@@ -5,20 +5,13 @@ import (
55 "errors"
66 "flag"
77 "fmt"
8- "github.com/charmbracelet/lipgloss"
98 "github.com/digitalghost-dev/poke-cli/structs"
9+ "github.com/digitalghost-dev/poke-cli/styling"
1010 "io"
1111 "net/http"
1212 "net/url"
1313)
1414
15- var (
16- errorBorder = lipgloss .NewStyle ().
17- BorderStyle (lipgloss .RoundedBorder ()).
18- BorderForeground (lipgloss .Color ("#F2055C" ))
19- errorColor = lipgloss .NewStyle ().Foreground (lipgloss .Color ("#F2055C" ))
20- )
21-
2215// ApiCallSetup Helper function to handle API calls and JSON unmarshalling
2316func ApiCallSetup (rawURL string , target interface {}, skipHTTPSCheck bool ) error {
2417 parsedURL , err := url .Parse (rawURL )
@@ -53,15 +46,16 @@ func ApiCallSetup(rawURL string, target interface{}, skipHTTPSCheck bool) error
5346 return nil
5447}
5548
49+ // AbilityApiCall function for calling the ability endpoint of the pokeAPI
5650func AbilityApiCall (endpoint string , abilityName string , baseURL string ) (structs.AbilityJSONStruct , string , error ) {
5751 fullURL := baseURL + endpoint + "/" + abilityName
5852
5953 var abilityStruct structs.AbilityJSONStruct
6054 err := ApiCallSetup (fullURL , & abilityStruct , false )
6155
6256 if err != nil {
63- errMessage := errorBorder .Render (
64- errorColor .Render ("Error!" ),
57+ errMessage := styling . ErrorBorder .Render (
58+ styling . ErrorColor .Render ("Error!" ),
6559 "\n Ability not found.\n \u2022 Perhaps a typo?\n \u2022 Missing a hyphen instead of a space?" ,
6660 )
6761 return structs.AbilityJSONStruct {}, "" , fmt .Errorf ("%s" , errMessage )
@@ -70,15 +64,16 @@ func AbilityApiCall(endpoint string, abilityName string, baseURL string) (struct
7064 return abilityStruct , abilityStruct .Name , nil
7165}
7266
67+ // PokemonApiCall function for calling the pokemon endpoint of the pokeAPI
7368func PokemonApiCall (endpoint string , pokemonName string , baseURL string ) (structs.PokemonJSONStruct , string , int , int , int , error ) {
7469 fullURL := baseURL + endpoint + "/" + pokemonName
7570
7671 var pokemonStruct structs.PokemonJSONStruct
7772 err := ApiCallSetup (fullURL , & pokemonStruct , false )
7873
7974 if err != nil {
80- errMessage := errorBorder .Render (
81- errorColor .Render ("Error!" ),
75+ errMessage := styling . ErrorBorder .Render (
76+ styling . ErrorColor .Render ("Error!" ),
8277 "\n Pokémon not found.\n \u2022 Perhaps a typo?\n \u2022 Missing a hyphen instead of a space?" ,
8378 )
8479 return structs.PokemonJSONStruct {}, "" , 0 , 0 , 0 , fmt .Errorf ("%s" , errMessage )
@@ -87,19 +82,17 @@ func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (struct
8782 return pokemonStruct , pokemonStruct .Name , pokemonStruct .ID , pokemonStruct .Weight , pokemonStruct .Height , nil
8883}
8984
90- func TypesApiCall (endpoint string , typesName string , baseURL string ) (structs.TypesJSONStruct , string , int , error ) {
85+ // TypesApiCall function for calling the type endpoint of the pokeAPI
86+ func TypesApiCall (endpoint string , typesName string , baseURL string ) (structs.TypesJSONStruct , string , int ) {
9187 fullURL := baseURL + endpoint + "/" + typesName
9288 var typesStruct structs.TypesJSONStruct
9389
9490 err := ApiCallSetup (fullURL , & typesStruct , false )
9591
9692 if err != nil {
97- errMessage := errorBorder .Render (
98- errorColor .Render ("Error!" ),
99- "\n Type not found.\n Perhaps a typo?" ,
100- )
101- return structs.TypesJSONStruct {}, "" , 0 , fmt .Errorf ("%s" , errMessage )
93+ fmt .Println (err )
94+ return structs.TypesJSONStruct {}, "" , 0
10295 }
10396
104- return typesStruct , typesStruct .Name , typesStruct .ID , nil
97+ return typesStruct , typesStruct .Name , typesStruct .ID
10598}
0 commit comments