Documentation
¶
Overview ¶
Package pokeapi is the library behind the pokeapi command line: the HTTP client, request shaping, and the typed data models for PokéAPI.
PokéAPI is free and open, no auth required. The client sets a real User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx) with exponential backoff.
Index ¶
- Constants
- type Ability
- type Berry
- type Client
- func (c *Client) GetAbility(ctx context.Context, nameOrID string) (*Ability, error)
- func (c *Client) GetBerry(ctx context.Context, nameOrID string) (*Berry, error)
- func (c *Client) GetGeneration(ctx context.Context, nameOrID string) (*Generation, error)
- func (c *Client) GetItem(ctx context.Context, nameOrID string) (*Item, error)
- func (c *Client) GetMove(ctx context.Context, nameOrID string) (*Move, error)
- func (c *Client) GetPokemon(ctx context.Context, nameOrID string) (*Pokemon, error)
- func (c *Client) GetSpecies(ctx context.Context, nameOrID string) (*Species, error)
- func (c *Client) GetType(ctx context.Context, nameOrID string) (*Type, error)
- func (c *Client) List(ctx context.Context, limit, offset int) ([]PokemonListItem, error)
- type Config
- type Domain
- type Generation
- type Item
- type Move
- type Pokemon
- type PokemonListItem
- type Species
- type Type
Constants ¶
const Host = "pokeapi.co"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ability ¶ added in v0.1.1
type Ability struct {
ID int `json:"id"`
Name string `json:"name"`
PokemonCount int `json:"pokemon_count"` // len(pokemon)
Effect string `json:"effect"` // first English effect
ShortEffect string `json:"short_effect"` // first English short_effect
}
Ability is the ability detail from /ability.
type Berry ¶ added in v0.1.1
type Berry struct {
ID int `json:"id" kit:"id"`
Name string `json:"name"`
GrowthTime int `json:"growth_time"`
MaxHarvest int `json:"max_harvest"`
Firmness string `json:"firmness"`
GiftType string `json:"natural_gift_type"`
GiftPower int `json:"natural_gift_power"`
}
Berry is the berry detail from /berry.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to PokéAPI over HTTP.
func (*Client) GetAbility ¶ added in v0.1.1
GetAbility fetches the ability record by name or id.
func (*Client) GetGeneration ¶ added in v0.1.1
GetGeneration fetches the generation record by name or id.
func (*Client) GetPokemon ¶ added in v0.1.1
GetPokemon fetches the full detail record for the named or numbered Pokémon.
func (*Client) GetSpecies ¶ added in v0.1.1
GetSpecies fetches the species record for the named or numbered Pokémon.
type Config ¶ added in v0.1.1
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶ added in v0.1.1
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Domain ¶
type Domain struct{}
Domain is the pokeapi driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Generation ¶ added in v0.1.1
type Generation struct {
ID int `json:"id"`
Name string `json:"name"`
MainRegion string `json:"main_region"`
PokemonCount int `json:"pokemon_count"` // len(pokemon_species)
TypeCount int `json:"type_count"` // len(types)
}
Generation is the generation detail from /generation.
type Item ¶ added in v0.1.1
type Item struct {
ID int `json:"id"`
Name string `json:"name"`
Cost int `json:"cost"`
FlingPower int `json:"fling_power"`
Category string `json:"category"`
Effect string `json:"effect"` // first English effect
}
Item is the item detail from /item.
type Move ¶ added in v0.1.1
type Move struct {
ID int `json:"id"`
Name string `json:"name"`
Power int `json:"power"`
Accuracy int `json:"accuracy"`
PP int `json:"pp"`
Type string `json:"type"`
DamageClass string `json:"damage_class"`
Effect string `json:"effect"` // first English effect
}
Move is the move detail from /move.
type Pokemon ¶ added in v0.1.1
type Pokemon struct {
ID int `json:"id"`
Name string `json:"name"`
Height int `json:"height"` // decimeters
Weight int `json:"weight"` // hectograms
BaseExperience int `json:"base_experience"`
Types []string `json:"types"`
Abilities []string `json:"abilities"`
HP int `json:"hp"`
Attack int `json:"attack"`
Defense int `json:"defense"`
SpAttack int `json:"sp_attack"`
SpDefense int `json:"sp_defense"`
Speed int `json:"speed"`
SpriteURL string `json:"sprite_url"` // front_default sprite
URL string `json:"url"` // https://pokeapi.co/api/v2/pokemon/{id}/
}
Pokemon is the full detail record for one Pokémon.
type PokemonListItem ¶ added in v0.1.1
type PokemonListItem struct {
Rank int `json:"rank"`
Name string `json:"name"`
URL string `json:"url"`
}
PokemonListItem is one row from the /pokemon list endpoint.
type Species ¶ added in v0.1.1
type Species struct {
ID int `json:"id"`
Name string `json:"name"`
IsLegendary bool `json:"is_legendary"`
IsMythical bool `json:"is_mythical"`
CaptureRate int `json:"capture_rate"`
BaseHappiness int `json:"base_happiness"`
Color string `json:"color"`
Generation string `json:"generation"`
FlavorText string `json:"flavor_text"` // first English entry
}
Species is the Pokémon species record from /pokemon-species.
type Type ¶ added in v0.1.1
type Type struct {
ID int `json:"id"`
Name string `json:"name"`
PokemonCount int `json:"pokemon_count"` // len(pokemon)
SuperEffective []string `json:"super_effective"` // double_damage_to names
WeakTo []string `json:"weak_to"` // double_damage_from names
NotVeryEffective []string `json:"not_very_effective"` // half_damage_to names
NoEffect []string `json:"no_effect"` // no_damage_to names
}
Type is the Pokémon type info from /type.