feat: added catch, inspect, and pokedex commands

This commit is contained in:
Stevan Freeborn
2026-07-29 06:52:44 -05:00
parent 017ac7a7bb
commit 7fb09a12fd
2 changed files with 171 additions and 11 deletions
+56 -2
View File
@@ -19,6 +19,7 @@ type Client struct {
cache *pokecache.Cache
Locations *locationsEndpoint
Pokemon *pokemonEndpoint
}
func NewClient(cache *pokecache.Cache) *Client {
@@ -29,6 +30,7 @@ func NewClient(cache *pokecache.Cache) *Client {
}
c.Locations = &locationsEndpoint{client: c, path: "/location-area"}
c.Pokemon = &pokemonEndpoint{client: c, path: "/pokemon"}
return c
}
@@ -160,12 +162,12 @@ type Location struct {
Url string `json:"url"`
}
type Pokemon struct {
type EncounteredPokemon struct {
Name string `json:"name"`
}
type PokemonEncounter struct {
Pokemon Pokemon `json:"pokemon"`
Pokemon EncounteredPokemon `json:"pokemon"`
}
type LocationArea struct {
@@ -220,3 +222,55 @@ func (le *locationsEndpoint) List(offset int) (Page[Location], error) {
return page, nil
}
type Stat struct {
Name string `json:"name"`
}
type PokemonStat struct {
BaseStat int `json:"base_stat"`
Effort int `json:"effort"`
Stat Stat `json:"stat"`
}
type Type struct {
Name string `json:"name"`
}
type PokemonType struct {
Type Type `json:"type"`
}
type Pokemon struct {
Id int `json:"id"`
Name string `json:"name"`
Height int `json:"height"`
Weight int `json:"weight"`
Stats []PokemonStat `json:"stats"`
Types []PokemonType `json:"types"`
BaseExperience int `json:"base_experience"`
}
type pokemonEndpoint struct {
path string
client *Client
}
func (pe *pokemonEndpoint) Get(name string) (Pokemon, error) {
var pokemon Pokemon
requestUrl := fmt.Sprintf("%s/%s", pe.path, name)
req, err := pe.client.NewRequest(http.MethodGet, requestUrl, map[string]string{}, nil)
if err != nil {
return pokemon, err
}
err = pe.client.doWithJsonResponse(req, &pokemon)
if err != nil {
return pokemon, err
}
return pokemon, nil
}