pokeapi

package module
v0.3.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 8 Imported by: 1

README

Installation

Install:

go get github.com/jeremyhager/pokeapi

Use:

import "github.com/jeremyhager/pokeapi"

About

An SDK/wrapper for pokeapi v2 in Go, baesd on the SDK linked from pokeapi.co https://github.com/mtslzr/pokeapi-go/

Improvements

This SDK has some code improvements over pokeapi-go as well as updated types. For example, Language can contain a nested array of the Name struct. Within the original pokeapi-go package this is defined each time, while this SDK will define this once:

// github.com/mtslzr/pokeapi-go/blob/master/structs/utility.go
type EvolutionChain struct {
	BabyTriggerItem interface{} `json:"baby_trigger_item"`
	Chain           struct {
		EvolutionDetails []interface{} `json:"evolution_details"`
		EvolvesTo        []struct {
			EvolutionDetails []struct {
    // ...
// github.com/jeremyhager/pokeapi/utility.go
type EvolutionChain struct {
	ID              int               `json:"id"`
	BabyTriggerItem *NamedAPIResource `json:"baby_trigger_item,omitempty"`
	Chain           ChainLink         `json:"chain"`
}

type ChainLink struct {
	IsBaby           bool              `json:"is_baby,omitempty"`
	Species          NamedAPIResource  `json:"species"`
	EvolutionDetails []EvolutionDetail `json:"evolution_details,omitempty"`
	EvolvesTo        []ChainLink       `json:"evolves_to,omitempty"`
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheSettings = Settings{
	CustomExpire: 0,
	UseCache:     true,
}

Functions

This section is empty.

Types

type APIResource

type APIResource struct {
	Url string `json:"url,omitempty"`
}

type Ability

type Ability struct {
	ID                int                   `json:"id"`
	Name              string                `json:"name"`
	IsMainSeries      bool                  `json:"is_main_series"`
	Generation        NamedAPIResource      `json:"generation"`
	Names             []Name                `json:"names"`
	EffectEntries     []VerboseEffect       `json:"effect_entries"`
	EffectChanges     []AbilityEffectChange `json:"effect_changes"`
	FlavorTextEntries []AbilityFlavorText   `json:"flavor_text_entries"`
	Pokemon           []AbilityPokemon      `json:"pokemon"`
}

func GetAbility

func GetAbility(id string) (Ability, error)

type AbilityEffectChange

type AbilityEffectChange struct {
	EffectEntries []VerboseEffect  `json:"effect_entries"`
	VersionGroup  NamedAPIResource `json:"version_group"`
}

type AbilityFlavorText

type AbilityFlavorText struct {
	FlavorText   string           `json:"flavor_text"`
	Language     NamedAPIResource `json:"language"`
	VersionGroup NamedAPIResource `json:"version_group"`
}

type AbilityPokemon

type AbilityPokemon struct {
	IsHidden bool             `json:"is_hidden"`
	Slot     int              `json:"slot"`
	Pokemon  NamedAPIResource `json:"pokemon"`
}
type ChainLink struct {
	IsBaby           bool              `json:"is_baby,omitempty"`
	Species          NamedAPIResource  `json:"species"`
	EvolutionDetails []EvolutionDetail `json:"evolution_details,omitempty"`
	EvolvesTo        []ChainLink       `json:"evolves_to,omitempty"`
}

func (*ChainLink) Flatten

func (c *ChainLink) Flatten() ([]ChainLink, error)

Returns a flat array of the evolution chain for the pokemon

type Description

type Description struct {
	Description string           `json:"description,omitempty"`
	Language    NamedAPIResource `json:"language,omitempty"`
}

type Effect

type Effect struct {
	Effect   string           `json:"effect,omitempty"`
	Language NamedAPIResource `json:"language,omitempty"`
}

type Encounter

type Encounter struct {
	MinLevel        int                `json:"min_level,omitempty"`
	MaxLevel        int                `json:"max_level,omitempty"`
	ConditionValues []NamedAPIResource `json:"condition_values,omitempty"`
	Chance          int                `json:"chance,omitempty"`
	Method          NamedAPIResource   `json:"method,omitempty"`
}

type EvolutionChain

type EvolutionChain struct {
	ID              int               `json:"id"`
	BabyTriggerItem *NamedAPIResource `json:"baby_trigger_item,omitempty"`
	Chain           ChainLink         `json:"chain"`
}

func GetEvolutionChain

func GetEvolutionChain(id string) (EvolutionChain, error)

Get evolution chain by ID

chain, _ := GetEvolutionChain("80")

type EvolutionDetail

type EvolutionDetail struct {
	Item                  *NamedAPIResource `json:"item,omitempty"`
	Trigger               *NamedAPIResource `json:"trigger,omitempty"`
	Gender                int               `json:"gender,omitempty"`
	HeldItem              *NamedAPIResource `json:"held_item,omitempty"`
	KnownMove             *NamedAPIResource `json:"known_move,omitempty"`
	KnownMoveType         *NamedAPIResource `json:"known_move_type,omitempty"`
	Location              *NamedAPIResource `json:"location,omitempty"`
	MinLevel              int               `json:"min_level,omitempty"`
	MinHappiness          int               `json:"min_happiness,omitempty"`
	MinBeauty             int               `json:"min_beauty,omitempty"`
	MinAffection          int               `json:"min_affection,omitempty"`
	PartySpecies          *NamedAPIResource `json:"party_species,omitempty"`
	PartyType             *NamedAPIResource `json:"party_type,omitempty"`
	RelativePhysicalStats int               `json:"relative_physical_stats,omitempty"`
	TimeOfDay             string            `json:"time_of_day,omitempty"`
	TradeSpecies          *NamedAPIResource `json:"trade_species,omitempty"`
	TurnUpsideDown        bool              `json:"turn_upside_down,omitempty"`
}

type FlavorText

type FlavorText struct {
	FlavorText string           `json:"flavor_text,omitempty"`
	Language   NamedAPIResource `json:"language,omitempty"`
	Version    NamedAPIResource `json:"version,omitempty"`
}

type Generation

type Generation struct {
	ID             int                `json:"id"`
	Name           string             `json:"name"`
	Abilities      []NamedAPIResource `json:"abilities"`
	Names          []Name             `json:"names"`
	MainRegion     NamedAPIResource   `json:"main_region"`
	Moves          []NamedAPIResource `json:"moves"`
	PokemonSpecies []NamedAPIResource `json:"pokemon_species"`
	Types          []NamedAPIResource `json:"types"`
	VersionGroups  []NamedAPIResource `json:"version_groups"`
}

func GetGeneration

func GetGeneration(id string) (Generation, error)

type GenerationGameIndex

type GenerationGameIndex struct {
	GameIndex  int              `json:"game_index,omitempty"`
	Generation NamedAPIResource `json:"geneartion,omitempty"`
}

type Genus

type Genus struct {
	Genus    string           `json:"genus"`
	Language NamedAPIResource `json:"language"`
}

type Language

type Language struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Official bool   `json:"official"`
	ISO639   string `json:"iso639"`
	ISO3166  string `json:"iso3166"`
	Names    []Name `json:"names"`
}

func GetLanguage

func GetLanguage(id string) (Language, error)

type MachineVersionDetail

type MachineVersionDetail struct {
	Machine      APIResource      `json:"machine,omitempty"`
	VersionGroup NamedAPIResource `json:"version_group,omitempty"`
}

type Name

type Name struct {
	Name     string           `json:"name,omitempty"`
	Language NamedAPIResource `json:"Language,omitempty"`
}

type Named

type Named struct {
	Count    int                `json:"count"`
	Next     string             `json:"next"`
	Previous string             `json:"previous"`
	Results  []NamedAPIResource `json:"results"`
}

func GetNamedEndpoint

func GetNamedEndpoint(endpoint string) (Named, error)

type NamedAPIResource

type NamedAPIResource struct {
	Name string `json:"name,omitempty"`
	Url  string `json:"url,omitempty"`
}

type PalParkEncounterArea

type PalParkEncounterArea struct {
	BaseScore int              `json:"base_score"`
	Rate      int              `json:"rate"`
	Area      NamedAPIResource `json:"area"`
}

type Pokemon

type Pokemon struct {
	ID                     int                `json:"id"`
	Name                   string             `json:"name"`
	BaseExperiance         int                `json:"base_experience"`
	Height                 int                `json:"height"`
	IsDefault              bool               `json:"is_default"`
	Order                  int                `json:"order"`
	Weight                 int                `json:"weight"`
	Abilities              []PokemonAbility   `json:"abilities"`
	Forms                  []NamedAPIResource `json:"forms"`
	GameIndices            []VersionGameIndex `json:"game_indices"`
	HeldItems              []PokemonHeldItem  `json:"held_items"`
	LocationAreaEncounters string             `json:"location_area_encounters"`
	Moves                  []PokemonMove      `json:"moves"`
	PastTypes              []PokemonTypePast  `json:"past_types"`
	Sprites                PokemonSprites     `json:"sprites"`
	Species                NamedAPIResource   `json:"species"`
	Stats                  []PokemonStat      `json:"stats"`
	Types                  []PokemonType      `json:"types"`
}

https://pokeapi.co/docs/v2#pokemon

func GetPokemon

func GetPokemon(id string) (Pokemon, error)

type PokemonAbility

type PokemonAbility struct {
	IsHidden bool             `json:"is_hidden"`
	Slot     int              `json:"slot"`
	Ability  NamedAPIResource `json:"ability"`
}

type PokemonForm

type PokemonForm struct {
	ID           string             `json:"id"`
	Name         string             `json:"name"`
	Order        int                `json:"order"`
	FormOrder    int                `json:"form_order"`
	IsDefault    bool               `json:"is_default"`
	IsBattleOnly bool               `json:"is_battle_only"`
	IsMega       bool               `json:"is_mega"`
	FormName     string             `json:"form_name"`
	Pokemon      NamedAPIResource   `json:"pokemon"`
	Types        []PokemonFormType  `json:"types"`
	Sprites      PokemonFormSprites `json:"sprites"`
	VersionGroup NamedAPIResource   `json:"version_group"`
	Names        []Name             `json:"names"`
	FormNames    []Name             `json:"form_names"`
}

func GetPokemonForm

func GetPokemonForm(id string) (PokemonForm, error)

type PokemonFormSprites

type PokemonFormSprites struct {
	FrontDefault string `json:"front_default"`
	FrontShiny   string `json:"front_shiny"`
	BackDefault  string `json:"back_default"`
	BackShiny    string `json:"back_shiny"`
}

type PokemonFormType

type PokemonFormType struct {
	Slot int              `json:"slot"`
	Type NamedAPIResource `json:"type"`
}

type PokemonHeldItem

type PokemonHeldItem struct {
	Name           NamedAPIResource         `json:"item"`
	VersionDetails []PokemonHeldItemVersion `json:"version_details"`
}

type PokemonHeldItemVersion

type PokemonHeldItemVersion struct {
	Version NamedAPIResource `json:"version"`
	Rarity  int              `json:"rarity"`
}

type PokemonMove

type PokemonMove struct {
	Move                NamedAPIResource     `json:"move"`
	VersionGroupDetails []PokemonMoveVersion `json:"version_group_details"`
}

type PokemonMoveVersion

type PokemonMoveVersion struct {
	MoveLearnMethod NamedAPIResource `json:"move_learn_method"`
	VersionGroup    NamedAPIResource `json:"version_group"`
	LevelLearnedAt  int              `json:"level_learned_at"`
}

type PokemonOfficialArtwork

type PokemonOfficialArtwork struct {
	FrontDefault string `json:"front_default"`
	FrontShiny   string `json:"front_shiny"`
}

type PokemonSpecies

type PokemonSpecies struct {
	ID                   int                      `json:"id"`
	Name                 string                   `json:"name"`
	Order                int                      `json:"order"`
	GenderRate           int                      `json:"gender_rate"`
	BaseHappiness        int                      `josn:"base_happiness"`
	IsBaby               bool                     `json:"is_baby"`
	IsLegendary          bool                     `json:"is_legendary"`
	IsMythical           bool                     `json:"is_mythical"`
	HatchCounter         int                      `json:"hatch_counter"`
	HasGenderDifferences bool                     `json:"has_gender_differences"`
	FormsSwitchable      bool                     `json:"forms_switchable"`
	GorthwRate           NamedAPIResource         `json:"growth_rate"`
	PokedexNumbers       []PokemonSpeciesDexEntry `json:"pokedex_numbers"`
	EggGroups            []NamedAPIResource       `json:"egg_groups"`
	Color                NamedAPIResource         `json:"color"`
	Shape                NamedAPIResource         `json:"shape"`
	EvolvesFromSpecies   NamedAPIResource         `json:"evolves_from_species"`
	EvolutionChain       APIResource              `json:"evolution_chain"`
	Habitat              NamedAPIResource         `json:"habitat"`
	Generation           NamedAPIResource         `json:"generation"`
	Names                []Name                   `json:"names"`
	PalParkEncounters    []PalParkEncounterArea   `json:"pal_park_encounters"`
	FlavorTextEntries    []FlavorText             `json:"flavor_text_entries"`
	FormDescriptions     []Description            `json:"form_descriptions"`
	Genera               []Genus                  `json:"genera"`
	Varieties            []PokemonSpeciesVariety  `json:"varieties"`
}

func GetPokemonSpecies

func GetPokemonSpecies(id string) (PokemonSpecies, error)

func (*PokemonSpecies) FlattenEvolutions

func (s *PokemonSpecies) FlattenEvolutions(chain *ChainLink) ([]PokemonSpecies, error)

Returns a flat array of all pokemon evolution species related to the current pokemon

func (*PokemonSpecies) GetBasePokemonSpecies

func (s *PokemonSpecies) GetBasePokemonSpecies(chain *ChainLink) (PokemonSpecies, error)

Returns the base species evolution from an evolution chain

type PokemonSpeciesDexEntry

type PokemonSpeciesDexEntry struct {
	EntryNumber int              `json:"entry_number"`
	PokeDex     NamedAPIResource `json:"pokedex"`
}

type PokemonSpeciesVariety

type PokemonSpeciesVariety struct {
	IsDefault bool             `json:"is_default"`
	Pokemon   NamedAPIResource `json:"pokemon"`
}

type PokemonSprites

type PokemonSprites struct {
	FrontDefault     string              `json:"front_default"`
	FrontShiny       string              `json:"front_shiny"`
	FrontFemale      string              `json:"front_female"`
	FrontShinyFemale string              `json:"front_shiny_female"`
	BackDefault      string              `json:"back_default"`
	BackShiny        string              `json:"back_shiny"`
	BackFemale       string              `json:"back_female"`
	BackShinyFemale  string              `json:"back_shiny_female"`
	Other            PokemonSpritesOther `json:"other"`
}

type PokemonSpritesDreamWorld

type PokemonSpritesDreamWorld struct {
	FrontDefault string `json:"front_default"`
	FrontFemale  string `json:"front_female"`
}

type PokemonSpritesHome

type PokemonSpritesHome struct {
	FrontDefault     string `json:"front_default"`
	FrontFemale      string `json:"front_female"`
	FrontShiny       string `json:"front_shiny"`
	FrontShinyFemale string `json:"front_shiny_female"`
}

type PokemonSpritesOther

type PokemonSpritesOther struct {
	DreamWorld      PokemonSpritesDreamWorld `json:"dream_world"`
	Home            PokemonSpritesHome       `json:"home"`
	OfficialArtwork PokemonOfficialArtwork   `json:"official-artwork"`
}

type PokemonStat

type PokemonStat struct {
	Stat     NamedAPIResource `json:"stat"`
	Effort   int              `json:"effort"`
	BaseStat int              `json:"base_stat"`
}

type PokemonType

type PokemonType struct {
	Slot int              `json:"slot"`
	Type NamedAPIResource `json:"type"`
}

type PokemonTypePast

type PokemonTypePast struct {
	Generation NamedAPIResource `json:"generation"`
	Types      []PokemonType    `json:"types"`
}

type RESTClient

type RESTClient struct {
	// contains filtered or unexported fields
}

func (*RESTClient) ClearCache

func (c *RESTClient) ClearCache()

ClearCache clears all cached data.

func (*RESTClient) Get

func (c *RESTClient) Get(pokeapiUrl string, pokeObj any) error

type Settings

type Settings struct {
	CustomExpire time.Duration
	UseCache     bool
}

CacheSettings are user settings for cache expiration.

type VerboseEffect

type VerboseEffect struct {
	Effect      string           `json:"effect,omitempty"`
	ShortEffect string           `json:"short_effec,omitemptyt"`
	Language    NamedAPIResource `json:"language,omitempty"`
}

type VersionEncounterDetail

type VersionEncounterDetail struct {
	Version          NamedAPIResource `json:"version,omitempty"`
	MaxChance        int              `json:"max_chance,omitempty"`
	EncounterDetails []Encounter      `json:"encounter_details,omitempty"`
}

type VersionGameIndex

type VersionGameIndex struct {
	GameIndex int              `json:"game_index,omitempty"`
	Version   NamedAPIResource `json:"version,omitempty"`
}

type VersionGroupFlavorText

type VersionGroupFlavorText struct {
	Text         string           `json:"text,omitempty"`
	Language     NamedAPIResource `json:"language,omitempty"`
	VersionGroup NamedAPIResource `json:"version_group,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL