From 45cfb6eacbde2034f9ba5c4f14300e0e526e4405 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 00:33:37 -0400 Subject: [PATCH 01/23] Added AllPokemon and Pokemon endpoints; added Circle --- .circleci/config.yml | 0 .gitignore | 6 +++ Makefile | 12 ++++++ README.md | 29 +++++++++++++- client.go | 53 ++++++++++++++++++++++++++ client_test.go | 30 +++++++++++++++ go.mod | 5 +++ go.sum | 7 ++++ structs/pokemon.go | 90 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 .circleci/config.yml create mode 100644 Makefile create mode 100644 client.go create mode 100644 client_test.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 structs/pokemon.go diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index f1c181e..4366401 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,14 @@ *.so *.dylib +# Vendor +vendor + # Test binary, build with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out + +# VSCode +.vscode diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b83a893 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +all: deps test + +deps: tidy vend + +test: + go test -v ./... + +tidy: + go mod tidy -v + +vend: + go mod vendor -v \ No newline at end of file diff --git a/README.md b/README.md index ca81b17..a3df979 100644 --- a/README.md +++ b/README.md @@ -1 +1,28 @@ -# pokeapi-go \ No newline at end of file +# pokeapi-go + +Wrapper for Poke API, written in Go. + +## How To + +```go +import poke "github.com/mtslzr/pokeapi-go" +``` + +## Endpoints + +### Get All Pokemon + +```go +all := poke.AllPokemon() + +fmt.Println(all.Count) // 964 +fmt.Println(all.Results[0].Name) // "bulbasaur" +``` + +### Get Pokemon (by ID) + +```go +bulbasaur := poke.Pokemon(1) + +fmt.Println(bulbasaur.Name) // "bulbasaur" +``` \ No newline at end of file diff --git a/client.go b/client.go new file mode 100644 index 0000000..2918d1e --- /dev/null +++ b/client.go @@ -0,0 +1,53 @@ +package pokeapi + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "time" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// APIURL for PokeAPI. +const APIURL = "https://pokeapi.co/api/v2/" + +// AllPokemon returns all pokemon. +func AllPokemon() (*structs.AllPokemon, error) { + endpoint := "pokemon" + var result structs.AllPokemon + + err := doCall(endpoint, &result) + return &result, err +} + +// Pokemon returns a single pokemon. +func Pokemon(id int) (*structs.Pokemon, error) { + endpoint := fmt.Sprintf("pokemon/%d", id) + var result structs.Pokemon + + err := doCall(endpoint, &result) + return &result, err +} + +func doCall(endpoint string, obj interface{}) error { + req, err := http.NewRequest(http.MethodGet, APIURL+endpoint, nil) + if err != nil { + return err + } + client := &http.Client{Timeout: 10 * time.Second} + + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + + return json.Unmarshal(body, &obj) +} diff --git a/client_test.go b/client_test.go new file mode 100644 index 0000000..c15edd0 --- /dev/null +++ b/client_test.go @@ -0,0 +1,30 @@ +package pokeapi + +import ( + "testing" + + "github.com/mtslzr/pokeapi-go/structs" + "github.com/stretchr/testify/assert" +) + +func TestAllPokemon(t *testing.T) { + result, err := AllPokemon() + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.AllPokemon{}, result, + "Expect to receive an AllPokemon struct.") + assert.NotEqual(t, nil, result.Count, + "Expect to receive a count of pokemon.") + assert.Equal(t, "bulbasaur", result.Results[0].Name, + "Expect to receive Bulbasaur as first pokemon.") +} + +func TestPokemon(t *testing.T) { + result, err := Pokemon(1) + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Pokemon{}, result, + "Expect to receive a Pokemon struct.") + assert.NotEqual(t, nil, result.Name, + "Expect to receive Bulbasaur.") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fa4c6bb --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/mtslzr/pokeapi-go + +go 1.12 + +require github.com/stretchr/testify v1.3.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4347755 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/structs/pokemon.go b/structs/pokemon.go new file mode 100644 index 0000000..1a34d5b --- /dev/null +++ b/structs/pokemon.go @@ -0,0 +1,90 @@ +package structs + +// AllPokemon is a list of all pokemon. +type AllPokemon struct { + Count int `json:"count"` + Next string `json:"next"` + Prev string `json:"previous"` + Results []struct { + Name string `json:"name"` + URL string `json:"url"` + } +} + +// Pokemon is a single pokemon. +type Pokemon struct { + Abilities []struct { + Ability struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"ability"` + IsHidden bool `json:"is_hidden"` + Slot int `json:"slot"` + } `json:"abilities"` + BaseExperience int `json:"base_experience"` + Forms []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"forms"` + GameIndices []struct { + GameIndex int `json:"game_index"` + Version struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version"` + } `json:"game_indices"` + Height int `json:"height"` + HeldItems []interface{} `json:"held_items"` + ID int `json:"id"` + IsDefault bool `json:"is_default"` + LocationAreaEncounters string `json:"location_area_encounters"` + Moves []struct { + Move struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move"` + VersionGroupDetails []struct { + LevelLearnedAt int `json:"level_learned_at"` + MoveLearnMethod struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move_learn_method"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` + } `json:"version_group_details"` + } `json:"moves"` + Name string `json:"name"` + Order int `json:"order"` + Species struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"species"` + Sprites struct { + BackDefault string `json:"back_default"` + BackFemale interface{} `json:"back_female"` + BackShiny string `json:"back_shiny"` + BackShinyFemale interface{} `json:"back_shiny_female"` + FrontDefault string `json:"front_default"` + FrontFemale interface{} `json:"front_female"` + FrontShiny string `json:"front_shiny"` + FrontShinyFemale interface{} `json:"front_shiny_female"` + } `json:"sprites"` + Stats []struct { + BaseStat int `json:"base_stat"` + Effort int `json:"effort"` + Stat struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"stat"` + } `json:"stats"` + Types []struct { + Slot int `json:"slot"` + Type struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"type"` + } `json:"types"` + Weight int `json:"weight"` +} From c396f81b7fb5b2d46ff37911bc5df3f44ea69a7f Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 00:38:05 -0400 Subject: [PATCH 02/23] Actually added CircleCI --- .circleci/config.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e69de29..83f42c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -0,0 +1,9 @@ +version: 2 + +jobs: + test: + docker: + - image: golang:1.12 + steps: + - checkout + - run: make \ No newline at end of file From 0ac18bd50a48eadb94aeb0d54120846e4df7c9ab Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 00:38:55 -0400 Subject: [PATCH 03/23] Fixed Circle job name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 83f42c2..5aca54b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2 jobs: - test: + build: docker: - image: golang:1.12 steps: From ba57012a7b01a31707ca740ab5f09d7ba085072f Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 01:24:32 -0400 Subject: [PATCH 04/23] Restructed folders and files; updated packages --- Makefile | 2 +- README.md | 1 + client.go | 24 ++---------------------- pokemon.go | 25 +++++++++++++++++++++++++ client_test.go => tests/pokemon_test.go | 17 ++++++++++++++--- 5 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 pokemon.go rename client_test.go => tests/pokemon_test.go (63%) diff --git a/Makefile b/Makefile index b83a893..8c71e3c 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: deps test deps: tidy vend test: - go test -v ./... + go test -v ./tests/... tidy: go mod tidy -v diff --git a/README.md b/README.md index a3df979..9b0322b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # pokeapi-go +[![CircleCI](https://circleci.com/gh/mtslzr/pokeapi-go.svg?style=svg)](https://circleci.com/gh/mtslzr/pokeapi-go) Wrapper for Poke API, written in Go. diff --git a/client.go b/client.go index 2918d1e..575cb18 100644 --- a/client.go +++ b/client.go @@ -2,36 +2,16 @@ package pokeapi import ( "encoding/json" - "fmt" "io/ioutil" "net/http" "time" - - "github.com/mtslzr/pokeapi-go/structs" ) // APIURL for PokeAPI. const APIURL = "https://pokeapi.co/api/v2/" -// AllPokemon returns all pokemon. -func AllPokemon() (*structs.AllPokemon, error) { - endpoint := "pokemon" - var result structs.AllPokemon - - err := doCall(endpoint, &result) - return &result, err -} - -// Pokemon returns a single pokemon. -func Pokemon(id int) (*structs.Pokemon, error) { - endpoint := fmt.Sprintf("pokemon/%d", id) - var result structs.Pokemon - - err := doCall(endpoint, &result) - return &result, err -} - -func doCall(endpoint string, obj interface{}) error { +// Do calls Poke API and returns JSON data. +func do(endpoint string, obj interface{}) error { req, err := http.NewRequest(http.MethodGet, APIURL+endpoint, nil) if err != nil { return err diff --git a/pokemon.go b/pokemon.go new file mode 100644 index 0000000..cf6138e --- /dev/null +++ b/pokemon.go @@ -0,0 +1,25 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// AllPokemon returns all pokemon. +func AllPokemon() (*structs.AllPokemon, error) { + endpoint := "pokemon" + var result structs.AllPokemon + + err := do(endpoint, &result) + return &result, err +} + +// Pokemon returns a single pokemon. +func Pokemon(id int) (*structs.Pokemon, error) { + endpoint := fmt.Sprintf("pokemon/%d", id) + var result structs.Pokemon + + err := do(endpoint, &result) + return &result, err +} diff --git a/client_test.go b/tests/pokemon_test.go similarity index 63% rename from client_test.go rename to tests/pokemon_test.go index c15edd0..73cb6a4 100644 --- a/client_test.go +++ b/tests/pokemon_test.go @@ -1,14 +1,15 @@ -package pokeapi +package tests import ( "testing" + pokeapi "github.com/mtslzr/pokeapi-go" "github.com/mtslzr/pokeapi-go/structs" "github.com/stretchr/testify/assert" ) func TestAllPokemon(t *testing.T) { - result, err := AllPokemon() + result, err := pokeapi.AllPokemon() assert.Equal(t, nil, err, "Expect to not receive an error.") assert.IsType(t, &structs.AllPokemon{}, result, @@ -20,7 +21,7 @@ func TestAllPokemon(t *testing.T) { } func TestPokemon(t *testing.T) { - result, err := Pokemon(1) + result, err := pokeapi.Pokemon(1) assert.Equal(t, nil, err, "Expect to not receive an error.") assert.IsType(t, &structs.Pokemon{}, result, @@ -28,3 +29,13 @@ func TestPokemon(t *testing.T) { assert.NotEqual(t, nil, result.Name, "Expect to receive Bulbasaur.") } + +func TestPokemonFail(t *testing.T) { + result, err := pokeapi.Pokemon(9999) + assert.NotEqual(t, nil, err, + "Expect to receive an error.") + assert.IsType(t, &structs.Pokemon{}, result, + "Expect to receive a Pokemon struct.") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} From 3054189d5e9fdc3886e768ef624225fdded6663d Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 01:40:23 -0400 Subject: [PATCH 05/23] Added Generations, Generation endpoints; updated AllPokemon to Pokemons --- games.go | 25 +++++++++++++++++++++++ pokemon.go | 6 +++--- structs/games.go | 46 +++++++++++++++++++++++++++++++++++++++++++ structs/pokemon.go | 4 ++-- tests/games_test.go | 41 ++++++++++++++++++++++++++++++++++++++ tests/pokemon_test.go | 8 ++++---- 6 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 games.go create mode 100644 structs/games.go create mode 100644 tests/games_test.go diff --git a/games.go b/games.go new file mode 100644 index 0000000..29acf3a --- /dev/null +++ b/games.go @@ -0,0 +1,25 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Generations returns all generations. +func Generations() (*structs.Generations, error) { + endpoint := "generation" + var result structs.Generations + + err := do(endpoint, &result) + return &result, err +} + +// Generation returns a single generation. +func Generation(id int) (*structs.Generation, error) { + endpoint := fmt.Sprintf("generation/%d", id) + var result structs.Generation + + err := do(endpoint, &result) + return &result, err +} diff --git a/pokemon.go b/pokemon.go index cf6138e..8d3443c 100644 --- a/pokemon.go +++ b/pokemon.go @@ -6,10 +6,10 @@ import ( "github.com/mtslzr/pokeapi-go/structs" ) -// AllPokemon returns all pokemon. -func AllPokemon() (*structs.AllPokemon, error) { +// Pokemons returns all pokemon. +func Pokemons() (*structs.Pokemons, error) { endpoint := "pokemon" - var result structs.AllPokemon + var result structs.Pokemons err := do(endpoint, &result) return &result, err diff --git a/structs/games.go b/structs/games.go new file mode 100644 index 0000000..aa0c63d --- /dev/null +++ b/structs/games.go @@ -0,0 +1,46 @@ +package structs + +// Generations is a list of all generations. +type Generations struct { + Count int `json:"count"` + Next interface{} `json:"next"` + Previous interface{} `json:"previous"` + Results []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"results"` +} + +// Generation is a single generation. +type Generation struct { + Abilities []interface{} `json:"abilities"` + ID int `json:"id"` + MainRegion struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"main_region"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` + Types []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"types"` + VersionGroups []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_groups"` +} diff --git a/structs/pokemon.go b/structs/pokemon.go index 1a34d5b..d126527 100644 --- a/structs/pokemon.go +++ b/structs/pokemon.go @@ -1,7 +1,7 @@ package structs -// AllPokemon is a list of all pokemon. -type AllPokemon struct { +// Pokemons is a list of all pokemon. +type Pokemons struct { Count int `json:"count"` Next string `json:"next"` Prev string `json:"previous"` diff --git a/tests/games_test.go b/tests/games_test.go new file mode 100644 index 0000000..cafe608 --- /dev/null +++ b/tests/games_test.go @@ -0,0 +1,41 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/mtslzr/pokeapi-go/structs" + "github.com/stretchr/testify/assert" +) + +func TestGenerations(t *testing.T) { + result, err := pokeapi.Generations() + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Generations{}, result, + "Expect to receive a Generations struct.") + assert.NotEqual(t, nil, result.Count, + "Expect to receive a count of generations.") + assert.Equal(t, "generation-i", result.Results[0].Name, + "Expect to receive Generation I as first generation.") +} + +func TestGeneration(t *testing.T) { + result, err := pokeapi.Generation(1) + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Generation{}, result, + "Expect to receive a Generation struct.") + assert.NotEqual(t, nil, result.MainRegion.Name, + "Expect to receive Kanto.") +} + +func TestGenerationFail(t *testing.T) { + result, err := pokeapi.Generation(9999) + assert.NotEqual(t, nil, err, + "Expect to receive an error.") + assert.IsType(t, &structs.Generation{}, result, + "Expect to receive a Generation struct.") + assert.Equal(t, "", result.MainRegion.Name, + "Expect to receive an empty result.") +} diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index 73cb6a4..0920e00 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -8,12 +8,12 @@ import ( "github.com/stretchr/testify/assert" ) -func TestAllPokemon(t *testing.T) { - result, err := pokeapi.AllPokemon() +func TestPokemons(t *testing.T) { + result, err := pokeapi.Pokemons() assert.Equal(t, nil, err, "Expect to not receive an error.") - assert.IsType(t, &structs.AllPokemon{}, result, - "Expect to receive an AllPokemon struct.") + assert.IsType(t, &structs.Pokemons{}, result, + "Expect to receive a Pokemons struct.") assert.NotEqual(t, nil, result.Count, "Expect to receive a count of pokemon.") assert.Equal(t, "bulbasaur", result.Results[0].Name, From d6151031402b21cfeeaafc63f91556bb082b33f2 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 01:51:19 -0400 Subject: [PATCH 06/23] Tweaked unit tests; updated README with progress --- README.md | 107 ++++++++++++++++++++++++++++++++++++++++-- tests/games_test.go | 2 +- tests/pokemon_test.go | 2 +- 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b0322b..231505d 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,121 @@ Wrapper for Poke API, written in Go. ## How To ```go -import poke "github.com/mtslzr/pokeapi-go" +import pokeapi "github.com/mtslzr/pokeapi-go" ``` +## Progress + +Current progress of endpoints. *Italics* are partially implemented. + +### Berries +- [ ] GET /berry/{id or name}/ +- [ ] GET /berry-firmness/{id or name}/ +- [ ] GET /berry-flavor/{id or name}/ +### Contests +- [ ] GET /contest-type/{id or name}/ +- [ ] GET /contest-effect/{id}/ +- [ ] GET /super-contest-effect/{id}/ +### Encounters +- [ ] GET /encounter-method/{id or name}/ +- [ ] GET /encounter-condition/{id or name}/ +- [ ] GET /encounter-condition-value/{id or name}/ +### Evolution +- [ ] GET /evolution-chain/{id}/ +- [ ] GET /evolution-trigger/{id or name}/ +### Games +- [ ] *GET /generation/{id or name}/* +- [ ] GET /pokedex/{id or name}/ +- [ ] GET /version/{id or name}/ +- [ ] GET /version-group/{id or name}/ +### Items +- [ ] GET /item{id or name}/ +- [ ] GET /item-attribute/{id or name}/ +- [ ] GET /item-category/{id or name}/ +- [ ] GET /item-fling-effect/{id or name}/ +- [ ] GET /item-pocket/{id or name}/ +### Locations +- [ ] GET /location/{id or name}/ +- [ ] GET /location-area/{id or name}/ +- [ ] GET /pal-park-area/{id or name}/ +- [ ] GET /region/{id or name}/ +### Machines +- [ ] GET /machine/{id}/ +### Moves +- [ ] GET /move/{id or name}/ +- [ ] GET /move-ailment/{id or name}/ +- [ ] GET /move-battle-style/{id or name}/ +- [ ] GET /move-category/{id or name}/ +- [ ] GET /move-damage-class/{id or name}/ +- [ ] GET /move-learn-method/{id or name}/ +- [ ] GET /move-target/{id or name}/ +### Pokemon +- [ ] GET /ability/{id or name}/ +- [ ] GET /egg-group/{id or name}/ +- [ ] GET /gender/{id or name}/ +- [ ] GET /growth-rate/{id or name}/ +- [ ] GET /nature/{id or name}/ +- [ ] GET /pokeathlon-stat/{id or name}/ +- [ ] *GET /pokemon/{id or name}/* +- [ ] GET /pokemon-color/{id or name}/ +- [ ] GET /pokemon-form/{id or name}/ +- [ ] GET /pokemon-habitat/{id or name}/ +- [ ] GET /pokemon-species/{id or name}/ +- [ ] GET /stat/{id or name}/ +- [ ] GET /type/{id or name}/ +### Utility +- [ ] GET /language/{id or name}/ + ## Endpoints -### Get All Pokemon +### Games + +#### Get Generations + +Returns all generations. + +```go +gens := pokeapi.Generations() + +fmt.Println(gens.Count) // 7 +fmt.Println(gens.Results[0].Name) // "generation-i" +``` + +#### Get Generation + +Returns single generation (by ID or name). + +*NOTE: Name not yet implemented.* ```go -all := poke.AllPokemon() +gen := pokeapi.Generation(1) + +fmt.Println(gen.MainRegion.Name) // "kanto" +``` + +### Pokemon + +#### Get Pokemons + +Returns all Pokemon. + +*NOTE: Pagination not yet implemented.* + +```go +all := pokeapi.AllPokemon() fmt.Println(all.Count) // 964 fmt.Println(all.Results[0].Name) // "bulbasaur" ``` -### Get Pokemon (by ID) +#### Get Pokemon + +Returns single Pokemon (by ID or name). + +*NOTE: Name not yet implemented.* ```go -bulbasaur := poke.Pokemon(1) +bulbasaur := pokeapi.Pokemon(1) fmt.Println(bulbasaur.Name) // "bulbasaur" ``` \ No newline at end of file diff --git a/tests/games_test.go b/tests/games_test.go index cafe608..103aaf9 100644 --- a/tests/games_test.go +++ b/tests/games_test.go @@ -26,7 +26,7 @@ func TestGeneration(t *testing.T) { "Expect to not receive an error.") assert.IsType(t, &structs.Generation{}, result, "Expect to receive a Generation struct.") - assert.NotEqual(t, nil, result.MainRegion.Name, + assert.Equal(t, "kanto", result.MainRegion.Name, "Expect to receive Kanto.") } diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index 0920e00..f3a2f68 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -26,7 +26,7 @@ func TestPokemon(t *testing.T) { "Expect to not receive an error.") assert.IsType(t, &structs.Pokemon{}, result, "Expect to receive a Pokemon struct.") - assert.NotEqual(t, nil, result.Name, + assert.Equal(t, "bulbasaur", result.Name, "Expect to receive Bulbasaur.") } From 29021af1e859d434368039a88d9de65797953dc5 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 02:04:28 -0400 Subject: [PATCH 07/23] Updated Pokemon/Generation endpoints to use name or ID; updated tests and README --- README.md | 32 ++++++++++++++++---------------- games.go | 6 +++--- pokemon.go | 6 +++--- tests/games_test.go | 14 ++++++++++++-- tests/pokemon_test.go | 14 ++++++++++++-- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 231505d..6fb3216 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ## Progress -Current progress of endpoints. *Italics* are partially implemented. +Current progress of endpoints. **Bold** are partially implemented. ### Berries - [ ] GET /berry/{id or name}/ @@ -29,7 +29,7 @@ Current progress of endpoints. *Italics* are partially implemented. - [ ] GET /evolution-chain/{id}/ - [ ] GET /evolution-trigger/{id or name}/ ### Games -- [ ] *GET /generation/{id or name}/* +- [x] GET /generation/{id or name}/ - [ ] GET /pokedex/{id or name}/ - [ ] GET /version/{id or name}/ - [ ] GET /version-group/{id or name}/ @@ -61,7 +61,7 @@ Current progress of endpoints. *Italics* are partially implemented. - [ ] GET /growth-rate/{id or name}/ - [ ] GET /nature/{id or name}/ - [ ] GET /pokeathlon-stat/{id or name}/ -- [ ] *GET /pokemon/{id or name}/* +- [x] GET /pokemon/{id or name}/ - [ ] GET /pokemon-color/{id or name}/ - [ ] GET /pokemon-form/{id or name}/ - [ ] GET /pokemon-habitat/{id or name}/ @@ -88,13 +88,13 @@ fmt.Println(gens.Results[0].Name) // "generation-i" #### Get Generation -Returns single generation (by ID or name). - -*NOTE: Name not yet implemented.* +Returns single generation (by name or ID). ```go -gen := pokeapi.Generation(1) +gen := pokeapi.Generation("1") +fmt.Println(gen.MainRegion.Name) // "kanto" +gen := pokeapi.GenerationByName("generation-i") fmt.Println(gen.MainRegion.Name) // "kanto" ``` @@ -107,20 +107,20 @@ Returns all Pokemon. *NOTE: Pagination not yet implemented.* ```go -all := pokeapi.AllPokemon() +pokes := pokeapi.AllPokemon() -fmt.Println(all.Count) // 964 -fmt.Println(all.Results[0].Name) // "bulbasaur" +fmt.Println(pokes.Count) // 964 +fmt.Println(pokes.Results[0].Name) // "bulbasaur" ``` #### Get Pokemon -Returns single Pokemon (by ID or name). - -*NOTE: Name not yet implemented.* +Returns single Pokemon (by name or ID). ```go -bulbasaur := pokeapi.Pokemon(1) +poke := pokeapi.Pokemon("1") +fmt.Println(poke.Name) // "bulbasaur" -fmt.Println(bulbasaur.Name) // "bulbasaur" -``` \ No newline at end of file +poke := pokeapi.Pokemon("bulbasaur") +fmt.Println(poke.Name) // "bulbasaur" +``` diff --git a/games.go b/games.go index 29acf3a..6cddc18 100644 --- a/games.go +++ b/games.go @@ -15,9 +15,9 @@ func Generations() (*structs.Generations, error) { return &result, err } -// Generation returns a single generation. -func Generation(id int) (*structs.Generation, error) { - endpoint := fmt.Sprintf("generation/%d", id) +// Generation returns a single generation (by name or ID). +func Generation(id string) (*structs.Generation, error) { + endpoint := fmt.Sprintf("generation/%s", id) var result structs.Generation err := do(endpoint, &result) diff --git a/pokemon.go b/pokemon.go index 8d3443c..fc12071 100644 --- a/pokemon.go +++ b/pokemon.go @@ -15,9 +15,9 @@ func Pokemons() (*structs.Pokemons, error) { return &result, err } -// Pokemon returns a single pokemon. -func Pokemon(id int) (*structs.Pokemon, error) { - endpoint := fmt.Sprintf("pokemon/%d", id) +// Pokemon returns a single pokemon (by name or ID). +func Pokemon(id string) (*structs.Pokemon, error) { + endpoint := fmt.Sprintf("pokemon/%s", id) var result structs.Pokemon err := do(endpoint, &result) diff --git a/tests/games_test.go b/tests/games_test.go index 103aaf9..5f07d08 100644 --- a/tests/games_test.go +++ b/tests/games_test.go @@ -21,7 +21,17 @@ func TestGenerations(t *testing.T) { } func TestGeneration(t *testing.T) { - result, err := pokeapi.Generation(1) + result, err := pokeapi.Generation("1") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Generation{}, result, + "Expect to receive a Generation struct.") + assert.Equal(t, "kanto", result.MainRegion.Name, + "Expect to receive Kanto.") +} + +func TestGenerationByName(t *testing.T) { + result, err := pokeapi.Generation("generation-i") assert.Equal(t, nil, err, "Expect to not receive an error.") assert.IsType(t, &structs.Generation{}, result, @@ -31,7 +41,7 @@ func TestGeneration(t *testing.T) { } func TestGenerationFail(t *testing.T) { - result, err := pokeapi.Generation(9999) + result, err := pokeapi.Generation("asdf") assert.NotEqual(t, nil, err, "Expect to receive an error.") assert.IsType(t, &structs.Generation{}, result, diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index f3a2f68..ff39302 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -21,7 +21,17 @@ func TestPokemons(t *testing.T) { } func TestPokemon(t *testing.T) { - result, err := pokeapi.Pokemon(1) + result, err := pokeapi.Pokemon("1") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Pokemon{}, result, + "Expect to receive a Pokemon struct.") + assert.Equal(t, "bulbasaur", result.Name, + "Expect to receive Bulbasaur.") +} + +func TestPokemonByName(t *testing.T) { + result, err := pokeapi.Pokemon("bulbasaur") assert.Equal(t, nil, err, "Expect to not receive an error.") assert.IsType(t, &structs.Pokemon{}, result, @@ -31,7 +41,7 @@ func TestPokemon(t *testing.T) { } func TestPokemonFail(t *testing.T) { - result, err := pokeapi.Pokemon(9999) + result, err := pokeapi.Pokemon("digimon") assert.NotEqual(t, nil, err, "Expect to receive an error.") assert.IsType(t, &structs.Pokemon{}, result, From cbe83e187491fe073cb2f197ddb25692ef7547b6 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 03:19:04 -0400 Subject: [PATCH 08/23] Created Resource (removed Pokemons/Generations), added structs for all endpoints --- Makefile | 5 +- README.md | 13 +- games.go | 9 - pokemon.go | 11 +- structs/berries.go | 73 ++++++++ structs/contests.go | 57 ++++++ structs/encounters.go | 49 +++++ structs/evolution.go | 93 +++++++++ structs/games.go | 85 +++++++-- structs/items.go | 136 ++++++++++++++ structs/locations.go | 133 +++++++++++++ structs/machines.go | 18 ++ structs/moves.go | 220 ++++++++++++++++++++++ structs/pokemon.go | 424 +++++++++++++++++++++++++++++++++++++++++- structs/resource.go | 12 ++ structs/utility.go | 17 ++ tests/games_test.go | 12 -- tests/pokemon_test.go | 12 -- 18 files changed, 1314 insertions(+), 65 deletions(-) create mode 100644 structs/berries.go create mode 100644 structs/contests.go create mode 100644 structs/encounters.go create mode 100644 structs/evolution.go create mode 100644 structs/items.go create mode 100644 structs/locations.go create mode 100644 structs/machines.go create mode 100644 structs/moves.go create mode 100644 structs/resource.go create mode 100644 structs/utility.go diff --git a/Makefile b/Makefile index 8c71e3c..1c1b14b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ -all: deps test +all: deps testall deps: tidy vend test: + go test -v -tags quick ./tests/... + +testall: go test -v ./tests/... tidy: diff --git a/README.md b/README.md index 6fb3216..8cf22df 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ # pokeapi-go [![CircleCI](https://circleci.com/gh/mtslzr/pokeapi-go.svg?style=svg)](https://circleci.com/gh/mtslzr/pokeapi-go) -Wrapper for Poke API, written in Go. +Wrapper for [Poke API](https://pokeapi.co), written in Go. + +* [How To](#how-to) +* [Progress](#progress) +* [Endpoints](#endpoints) +* [Documentation](#documentation) ## How To @@ -34,7 +39,7 @@ Current progress of endpoints. **Bold** are partially implemented. - [ ] GET /version/{id or name}/ - [ ] GET /version-group/{id or name}/ ### Items -- [ ] GET /item{id or name}/ +- [ ] GET /item/{id or name}/ - [ ] GET /item-attribute/{id or name}/ - [ ] GET /item-category/{id or name}/ - [ ] GET /item-fling-effect/{id or name}/ @@ -124,3 +129,7 @@ fmt.Println(poke.Name) // "bulbasaur" poke := pokeapi.Pokemon("bulbasaur") fmt.Println(poke.Name) // "bulbasaur" ``` + +## Documentation + +Full API documentation can be found at [Poke API](https://pokeapi.co/docs/v2.html). \ No newline at end of file diff --git a/games.go b/games.go index 6cddc18..b9f0bef 100644 --- a/games.go +++ b/games.go @@ -6,15 +6,6 @@ import ( "github.com/mtslzr/pokeapi-go/structs" ) -// Generations returns all generations. -func Generations() (*structs.Generations, error) { - endpoint := "generation" - var result structs.Generations - - err := do(endpoint, &result) - return &result, err -} - // Generation returns a single generation (by name or ID). func Generation(id string) (*structs.Generation, error) { endpoint := fmt.Sprintf("generation/%s", id) diff --git a/pokemon.go b/pokemon.go index fc12071..7f8bb26 100644 --- a/pokemon.go +++ b/pokemon.go @@ -6,16 +6,7 @@ import ( "github.com/mtslzr/pokeapi-go/structs" ) -// Pokemons returns all pokemon. -func Pokemons() (*structs.Pokemons, error) { - endpoint := "pokemon" - var result structs.Pokemons - - err := do(endpoint, &result) - return &result, err -} - -// Pokemon returns a single pokemon (by name or ID). +// Pokemon returns a single Pokemon (by name or ID). func Pokemon(id string) (*structs.Pokemon, error) { endpoint := fmt.Sprintf("pokemon/%s", id) var result structs.Pokemon diff --git a/structs/berries.go b/structs/berries.go new file mode 100644 index 0000000..bcc3b80 --- /dev/null +++ b/structs/berries.go @@ -0,0 +1,73 @@ +package structs + +// Berry is a single berry. +type Berry struct { + Firmness struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"firmness"` + Flavors []struct { + Flavor struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"flavor"` + Potency int `json:"potency"` + } `json:"flavors"` + GrowthTime int `json:"growth_time"` + ID int `json:"id"` + Item struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"item"` + MaxHarvest int `json:"max_harvest"` + Name string `json:"name"` + NaturalGiftPower int `json:"natural_gift_power"` + NaturalGiftType struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"natural_gift_type"` + Size int `json:"size"` + Smoothness int `json:"smoothness"` + SoilDryness int `json:"soil_dryness"` +} + +// BerryFirmness is a single berry firmness. +type BerryFirmness struct { + Berries []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"berries"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// BerryFlavor is a single berry flavor. +type BerryFlavor struct { + Berries []struct { + Berry struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"berry"` + Potency int `json:"potency"` + } `json:"berries"` + ContestType struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"contest_type"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} diff --git a/structs/contests.go b/structs/contests.go new file mode 100644 index 0000000..3b602d9 --- /dev/null +++ b/structs/contests.go @@ -0,0 +1,57 @@ +package structs + +// ContestType is a single contest type. +type ContestType struct { + BerryFlavor struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"berry_flavor"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Color string `json:"color"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// ContestEffect is a single contest effect. +type ContestEffect struct { + Appeal int `json:"appeal"` + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"effect_entries"` + FlavorTextEntries []struct { + FlavorText string `json:"flavor_text"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"flavor_text_entries"` + ID int `json:"id"` + Jam int `json:"jam"` +} + +// SuperContestEffect is a single super contest effect. +type SuperContestEffect struct { + Appeal int `json:"appeal"` + FlavorTextEntries []struct { + FlavorText string `json:"flavor_text"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"flavor_text_entries"` + ID int `json:"id"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` +} diff --git a/structs/encounters.go b/structs/encounters.go new file mode 100644 index 0000000..e072235 --- /dev/null +++ b/structs/encounters.go @@ -0,0 +1,49 @@ +package structs + +// EncounterMethod is a single encounter method. +type EncounterMethod struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Order int `json:"order"` +} + +// EncounterCondition is a single encounter condition. +type EncounterCondition struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Values []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"values"` +} + +// EncounterConditionValue is a single encounter condition value. +type EncounterConditionValue struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Values []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"values"` +} diff --git a/structs/evolution.go b/structs/evolution.go new file mode 100644 index 0000000..c17cda3 --- /dev/null +++ b/structs/evolution.go @@ -0,0 +1,93 @@ +package structs + +// EvolutionChain is a single evolution chain. +type EvolutionChain struct { + BabyTriggerItem interface{} `json:"baby_trigger_item"` + Chain struct { + EvolutionDetails []interface{} `json:"evolution_details"` + EvolvesTo []struct { + EvolutionDetails []struct { + Gender interface{} `json:"gender"` + HeldItem interface{} `json:"held_item"` + Item interface{} `json:"item"` + KnownMove interface{} `json:"known_move"` + KnownMoveType interface{} `json:"known_move_type"` + Location interface{} `json:"location"` + MinAffection interface{} `json:"min_affection"` + MinBeauty interface{} `json:"min_beauty"` + MinHappiness interface{} `json:"min_happiness"` + MinLevel int `json:"min_level"` + NeedsOverworldRain bool `json:"needs_overworld_rain"` + PartySpecies interface{} `json:"party_species"` + PartyType interface{} `json:"party_type"` + RelativePhysicalStats interface{} `json:"relative_physical_stats"` + TimeOfDay string `json:"time_of_day"` + TradeSpecies interface{} `json:"trade_species"` + Trigger struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"trigger"` + TurnUpsideDown bool `json:"turn_upside_down"` + } `json:"evolution_details"` + EvolvesTo []struct { + EvolutionDetails []struct { + Gender interface{} `json:"gender"` + HeldItem interface{} `json:"held_item"` + Item interface{} `json:"item"` + KnownMove interface{} `json:"known_move"` + KnownMoveType interface{} `json:"known_move_type"` + Location interface{} `json:"location"` + MinAffection interface{} `json:"min_affection"` + MinBeauty interface{} `json:"min_beauty"` + MinHappiness interface{} `json:"min_happiness"` + MinLevel int `json:"min_level"` + NeedsOverworldRain bool `json:"needs_overworld_rain"` + PartySpecies interface{} `json:"party_species"` + PartyType interface{} `json:"party_type"` + RelativePhysicalStats interface{} `json:"relative_physical_stats"` + TimeOfDay string `json:"time_of_day"` + TradeSpecies interface{} `json:"trade_species"` + Trigger struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"trigger"` + TurnUpsideDown bool `json:"turn_upside_down"` + } `json:"evolution_details"` + EvolvesTo []interface{} `json:"evolves_to"` + IsBaby bool `json:"is_baby"` + Species struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"species"` + } `json:"evolves_to"` + IsBaby bool `json:"is_baby"` + Species struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"species"` + } `json:"evolves_to"` + IsBaby bool `json:"is_baby"` + Species struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"species"` + } `json:"chain"` + ID int `json:"id"` +} + +// EvolutionTrigger is a single evolution trigger. +type EvolutionTrigger struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` +} diff --git a/structs/games.go b/structs/games.go index aa0c63d..6ccffef 100644 --- a/structs/games.go +++ b/structs/games.go @@ -1,16 +1,5 @@ package structs -// Generations is a list of all generations. -type Generations struct { - Count int `json:"count"` - Next interface{} `json:"next"` - Previous interface{} `json:"previous"` - Results []struct { - Name string `json:"name"` - URL string `json:"url"` - } `json:"results"` -} - // Generation is a single generation. type Generation struct { Abilities []interface{} `json:"abilities"` @@ -44,3 +33,77 @@ type Generation struct { URL string `json:"url"` } `json:"version_groups"` } + +// Pokedex is a single Pokedex. +type Pokedex struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + IsMainSeries bool `json:"is_main_series"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonEntries []struct { + EntryNumber int `json:"entry_number"` + PokemonSpecies struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` + } `json:"pokemon_entries"` + Region interface{} `json:"region"` + VersionGroups []interface{} `json:"version_groups"` +} + +// Version is a single version. +type Version struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` +} + +// VersionGroup is a single version group. +type VersionGroup struct { + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + ID int `json:"id"` + MoveLearnMethods []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move_learn_methods"` + Name string `json:"name"` + Order int `json:"order"` + Pokedexes []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokedexes"` + Regions []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"regions"` + Versions []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"versions"` +} diff --git a/structs/items.go b/structs/items.go new file mode 100644 index 0000000..07fd70d --- /dev/null +++ b/structs/items.go @@ -0,0 +1,136 @@ +package structs + +// Item is a single item. +type Item struct { + Attributes []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"attributes"` + BabyTriggerFor interface{} `json:"baby_trigger_for"` + Category struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"category"` + Cost int `json:"cost"` + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + ShortEffect string `json:"short_effect"` + } `json:"effect_entries"` + FlavorTextEntries []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Text string `json:"text"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` + } `json:"flavor_text_entries"` + FlingEffect interface{} `json:"fling_effect"` + FlingPower interface{} `json:"fling_power"` + GameIndices []struct { + GameIndex int `json:"game_index"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + } `json:"game_indices"` + HeldByPokemon []interface{} `json:"held_by_pokemon"` + ID int `json:"id"` + Machines []interface{} `json:"machines"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Sprites struct { + Default string `json:"default"` + } `json:"sprites"` +} + +// ItemAttribute is a single item attribute. +type ItemAttribute struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + Items []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"items"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// ItemCategory is a single item category. +type ItemCategory struct { + ID int `json:"id"` + Items []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"items"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Pocket struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pocket"` +} + +// ItemFlingEffect is a single item fling effect. +type ItemFlingEffect struct { + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"effect_entries"` + ID int `json:"id"` + Items []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"items"` + Name string `json:"name"` +} + +// ItemPocket is a single item pocket. +type ItemPocket struct { + Categories []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"categories"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} diff --git a/structs/locations.go b/structs/locations.go new file mode 100644 index 0000000..8316c91 --- /dev/null +++ b/structs/locations.go @@ -0,0 +1,133 @@ +package structs + +// Location is a single location. +type Location struct { + Areas []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"areas"` + GameIndices []struct { + GameIndex int `json:"game_index"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + } `json:"game_indices"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Region struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"region"` +} + +// LocationArea is a single location area. +type LocationArea struct { + EncounterMethodRates []struct { + EncounterMethod struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"encounter_method"` + VersionDetails []struct { + Rate int `json:"rate"` + Version struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version"` + } `json:"version_details"` + } `json:"encounter_method_rates"` + GameIndex int `json:"game_index"` + ID int `json:"id"` + Location struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"location"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonEncounters []struct { + Pokemon struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon"` + VersionDetails []struct { + EncounterDetails []struct { + Chance int `json:"chance"` + ConditionValues []interface{} `json:"condition_values"` + MaxLevel int `json:"max_level"` + Method struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"method"` + MinLevel int `json:"min_level"` + } `json:"encounter_details"` + MaxChance int `json:"max_chance"` + Version struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version"` + } `json:"version_details"` + } `json:"pokemon_encounters"` +} + +// PalParkArea is a single Pal Park area. +type PalParkArea struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonEncounters []struct { + BaseScore int `json:"base_score"` + PokemonSpecies struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` + Rate int `json:"rate"` + } `json:"pokemon_encounters"` +} + +// Region is a single region. +type Region struct { + ID int `json:"id"` + Locations []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"locations"` + MainGeneration struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"main_generation"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Pokedexes []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokedexes"` + VersionGroups []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_groups"` +} diff --git a/structs/machines.go b/structs/machines.go new file mode 100644 index 0000000..a3c0fd9 --- /dev/null +++ b/structs/machines.go @@ -0,0 +1,18 @@ +package structs + +// Machine is a single machine. +type Machine struct { + ID int `json:"id"` + Item struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"item"` + Move struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` +} diff --git a/structs/moves.go b/structs/moves.go new file mode 100644 index 0000000..37074aa --- /dev/null +++ b/structs/moves.go @@ -0,0 +1,220 @@ +package structs + +// Move is a single move. +type Move struct { + Accuracy int `json:"accuracy"` + ContestCombos struct { + Normal struct { + UseAfter interface{} `json:"use_after"` + UseBefore []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"use_before"` + } `json:"normal"` + Super struct { + UseAfter interface{} `json:"use_after"` + UseBefore interface{} `json:"use_before"` + } `json:"super"` + } `json:"contest_combos"` + ContestEffect struct { + URL string `json:"url"` + } `json:"contest_effect"` + ContestType struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"contest_type"` + DamageClass struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"damage_class"` + EffectChance interface{} `json:"effect_chance"` + EffectChanges []interface{} `json:"effect_changes"` + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + ShortEffect string `json:"short_effect"` + } `json:"effect_entries"` + FlavorTextEntries []struct { + FlavorText string `json:"flavor_text"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` + } `json:"flavor_text_entries"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + ID int `json:"id"` + Machines []interface{} `json:"machines"` + Meta struct { + Ailment struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"ailment"` + AilmentChance int `json:"ailment_chance"` + Category struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"category"` + CritRate int `json:"crit_rate"` + Drain int `json:"drain"` + FlinchChance int `json:"flinch_chance"` + Healing int `json:"healing"` + MaxHits interface{} `json:"max_hits"` + MaxTurns interface{} `json:"max_turns"` + MinHits interface{} `json:"min_hits"` + MinTurns interface{} `json:"min_turns"` + StatChance int `json:"stat_chance"` + } `json:"meta"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PastValues []interface{} `json:"past_values"` + Power int `json:"power"` + Pp int `json:"pp"` + Priority int `json:"priority"` + StatChanges []interface{} `json:"stat_changes"` + SuperContestEffect struct { + URL string `json:"url"` + } `json:"super_contest_effect"` + Target struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"target"` + Type struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"type"` +} + +// MoveAilment is a single move ailment. +type MoveAilment struct { + ID int `json:"id"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// MoveBattleStyle is a single move battle style. +type MoveBattleStyle struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// MoveCategory is a single move category. +type MoveCategory struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` +} + +// MoveDamageClass is a single move damage class. +type MoveDamageClass struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// MoveLearnMethod is a single move learn method. +type MoveLearnMethod struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + VersionGroups []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_groups"` +} + +// MoveTarget is a single move target. +type MoveTarget struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + ID int `json:"id"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} diff --git a/structs/pokemon.go b/structs/pokemon.go index d126527..700785d 100644 --- a/structs/pokemon.go +++ b/structs/pokemon.go @@ -1,17 +1,181 @@ package structs -// Pokemons is a list of all pokemon. -type Pokemons struct { - Count int `json:"count"` - Next string `json:"next"` - Prev string `json:"previous"` - Results []struct { +// Ability is a single ability. +type Ability struct { + EffectChanges []struct { + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"effect_entries"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` + } `json:"effect_changes"` + EffectEntries []struct { + Effect string `json:"effect"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + ShortEffect string `json:"short_effect"` + } `json:"effect_entries"` + FlavorTextEntries []struct { + FlavorText string `json:"flavor_text"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` + } `json:"flavor_text_entries"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + ID int `json:"id"` + IsMainSeries bool `json:"is_main_series"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Pokemon []struct { + IsHidden bool `json:"is_hidden"` + Pokemon struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon"` + Slot int `json:"slot"` + } `json:"pokemon"` +} + +// EggGroup is a single egg group. +type EggGroup struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` +} + +// Gender is a single gender. +type Gender struct { + ID int `json:"id"` + Name string `json:"name"` + PokemonSpeciesDetails []struct { + PokemonSpecies struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` + Rate int `json:"rate"` + } `json:"pokemon_species_details"` + RequiredForEvolution []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"required_for_evolution"` +} + +// GrowthRate is a single growth rate. +type GrowthRate struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + Formula string `json:"formula"` + ID int `json:"id"` + Levels []struct { + Experience int `json:"experience"` + Level int `json:"level"` + } `json:"levels"` + Name string `json:"name"` + PokemonSpecies []struct { Name string `json:"name"` URL string `json:"url"` - } + } `json:"pokemon_species"` +} + +// Nature is a single nature. +type Nature struct { + DecreasedStat interface{} `json:"decreased_stat"` + HatesFlavor interface{} `json:"hates_flavor"` + ID int `json:"id"` + IncreasedStat interface{} `json:"increased_stat"` + LikesFlavor interface{} `json:"likes_flavor"` + MoveBattleStylePreferences []struct { + HighHpPreference int `json:"high_hp_preference"` + LowHpPreference int `json:"low_hp_preference"` + MoveBattleStyle struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move_battle_style"` + } `json:"move_battle_style_preferences"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokeathlonStatChanges []struct { + MaxChange int `json:"max_change"` + PokeathlonStat struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokeathlon_stat"` + } `json:"pokeathlon_stat_changes"` } -// Pokemon is a single pokemon. +// PokeathlonStat is a single Pokeathlon stat. +type PokeathlonStat struct { + AffectingNatures struct { + Decrease []struct { + MaxChange int `json:"max_change"` + Nature struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"nature"` + } `json:"decrease"` + Increase []struct { + MaxChange int `json:"max_change"` + Nature struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"nature"` + } `json:"increase"` + } `json:"affecting_natures"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// Pokemon is a single Pokemon. type Pokemon struct { Abilities []struct { Ability struct { @@ -88,3 +252,247 @@ type Pokemon struct { } `json:"types"` Weight int `json:"weight"` } + +// PokemonColor is a single Pokemon color. +type PokemonColor struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` +} + +// PokemonForm is a single Pokemon form. +type PokemonForm struct { + FormName string `json:"form_name"` + FormNames []interface{} `json:"form_names"` + FormOrder int `json:"form_order"` + ID int `json:"id"` + IsBattleOnly bool `json:"is_battle_only"` + IsDefault bool `json:"is_default"` + IsMega bool `json:"is_mega"` + Name string `json:"name"` + Names []interface{} `json:"names"` + Order int `json:"order"` + Pokemon struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon"` + Sprites struct { + BackDefault string `json:"back_default"` + BackShiny string `json:"back_shiny"` + FrontDefault string `json:"front_default"` + FrontShiny string `json:"front_shiny"` + } `json:"sprites"` + VersionGroup struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version_group"` +} + +// PokemonHabitat is a single Pokemon habitat. +type PokemonHabitat struct { + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` +} + +// PokemonSpecies is a single Pokemon species. +type PokemonSpecies struct { + BaseHappiness int `json:"base_happiness"` + CaptureRate int `json:"capture_rate"` + Color struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"color"` + EggGroups []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"egg_groups"` + EvolutionChain struct { + URL string `json:"url"` + } `json:"evolution_chain"` + EvolvesFromSpecies interface{} `json:"evolves_from_species"` + FlavorTextEntries []struct { + FlavorText string `json:"flavor_text"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Version struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"version"` + } `json:"flavor_text_entries"` + FormDescriptions []interface{} `json:"form_descriptions"` + FormsSwitchable bool `json:"forms_switchable"` + GenderRate int `json:"gender_rate"` + Genera []struct { + Genus string `json:"genus"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"genera"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + GrowthRate struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"growth_rate"` + Habitat struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"habitat"` + HasGenderDifferences bool `json:"has_gender_differences"` + HatchCounter int `json:"hatch_counter"` + ID int `json:"id"` + IsBaby bool `json:"is_baby"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Order int `json:"order"` + PalParkEncounters []struct { + Area struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"area"` + BaseScore int `json:"base_score"` + Rate int `json:"rate"` + } `json:"pal_park_encounters"` + PokedexNumbers []struct { + EntryNumber int `json:"entry_number"` + Pokedex struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokedex"` + } `json:"pokedex_numbers"` + Shape struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"shape"` + Varieties []struct { + IsDefault bool `json:"is_default"` + Pokemon struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon"` + } `json:"varieties"` +} + +// Stat is a single stat. +type Stat struct { + AffectingMoves struct { + Decrease []interface{} `json:"decrease"` + Increase []struct { + Change int `json:"change"` + Move struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move"` + } `json:"increase"` + } `json:"affecting_moves"` + AffectingNatures struct { + Decrease []interface{} `json:"decrease"` + Increase []interface{} `json:"increase"` + } `json:"affecting_natures"` + Characteristics []struct { + URL string `json:"url"` + } `json:"characteristics"` + GameIndex int `json:"game_index"` + ID int `json:"id"` + IsBattleOnly bool `json:"is_battle_only"` + MoveDamageClass interface{} `json:"move_damage_class"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` +} + +// Type is a single type. +type Type struct { + DamageRelations struct { + DoubleDamageFrom []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"double_damage_from"` + DoubleDamageTo []interface{} `json:"double_damage_to"` + HalfDamageFrom []interface{} `json:"half_damage_from"` + HalfDamageTo []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"half_damage_to"` + NoDamageFrom []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"no_damage_from"` + NoDamageTo []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"no_damage_to"` + } `json:"damage_relations"` + GameIndices []struct { + GameIndex int `json:"game_index"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + } `json:"game_indices"` + Generation struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"generation"` + ID int `json:"id"` + MoveDamageClass struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"move_damage_class"` + Moves []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"moves"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Pokemon []struct { + Pokemon struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon"` + Slot int `json:"slot"` + } `json:"pokemon"` +} diff --git a/structs/resource.go b/structs/resource.go new file mode 100644 index 0000000..1d278d2 --- /dev/null +++ b/structs/resource.go @@ -0,0 +1,12 @@ +package structs + +// Resource is a resource list for an endpoint. +type Resource struct { + Count int `json:"count"` + Next string `json:"next"` + Previous interface{} `json:"previous"` + Results []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"results"` +} diff --git a/structs/utility.go b/structs/utility.go new file mode 100644 index 0000000..3e43bd9 --- /dev/null +++ b/structs/utility.go @@ -0,0 +1,17 @@ +package structs + +// Language is a single language. +type Language struct { + ID int `json:"id"` + Iso3166 string `json:"iso3166"` + Iso639 string `json:"iso639"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + Official bool `json:"official"` +} diff --git a/tests/games_test.go b/tests/games_test.go index 5f07d08..872d2ed 100644 --- a/tests/games_test.go +++ b/tests/games_test.go @@ -8,18 +8,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGenerations(t *testing.T) { - result, err := pokeapi.Generations() - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Generations{}, result, - "Expect to receive a Generations struct.") - assert.NotEqual(t, nil, result.Count, - "Expect to receive a count of generations.") - assert.Equal(t, "generation-i", result.Results[0].Name, - "Expect to receive Generation I as first generation.") -} - func TestGeneration(t *testing.T) { result, err := pokeapi.Generation("1") assert.Equal(t, nil, err, diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index ff39302..e6dbd8f 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -8,18 +8,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPokemons(t *testing.T) { - result, err := pokeapi.Pokemons() - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Pokemons{}, result, - "Expect to receive a Pokemons struct.") - assert.NotEqual(t, nil, result.Count, - "Expect to receive a count of pokemon.") - assert.Equal(t, "bulbasaur", result.Results[0].Name, - "Expect to receive Bulbasaur as first pokemon.") -} - func TestPokemon(t *testing.T) { result, err := pokeapi.Pokemon("1") assert.Equal(t, nil, err, From 06099190ce9f434efbc04eecd91af8bf2907a302 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 03:30:07 -0400 Subject: [PATCH 09/23] Added all /pokemon/ endpoints; added Ability/EggGroup unit tests --- pokemon.go | 108 ++++++++++++++++++++++++++++++++++++++++++ tests/pokemon_test.go | 60 +++++++++++++++++++++++ 2 files changed, 168 insertions(+) diff --git a/pokemon.go b/pokemon.go index 7f8bb26..5582f6a 100644 --- a/pokemon.go +++ b/pokemon.go @@ -6,6 +6,60 @@ import ( "github.com/mtslzr/pokeapi-go/structs" ) +// Ability returns a single ability (by name or ID). +func Ability(id string) (*structs.Ability, error) { + endpoint := fmt.Sprintf("ability/%s", id) + var result structs.Ability + + err := do(endpoint, &result) + return &result, err +} + +// EggGroup returns a single egg group (by name or ID). +func EggGroup(id string) (*structs.EggGroup, error) { + endpoint := fmt.Sprintf("egg-group/%s", id) + var result structs.EggGroup + + err := do(endpoint, &result) + return &result, err +} + +// Gender returns a single gender (by name or ID). +func Gender(id string) (*structs.Gender, error) { + endpoint := fmt.Sprintf("gender/%s", id) + var result structs.Gender + + err := do(endpoint, &result) + return &result, err +} + +// GrowthRate returns a single growth rate (by name or ID). +func GrowthRate(id string) (*structs.GrowthRate, error) { + endpoint := fmt.Sprintf("growth-rate/%s", id) + var result structs.GrowthRate + + err := do(endpoint, &result) + return &result, err +} + +// Nature returns a single nature (by name or ID). +func Nature(id string) (*structs.Nature, error) { + endpoint := fmt.Sprintf("nature/%s", id) + var result structs.Nature + + err := do(endpoint, &result) + return &result, err +} + +// PokeathlonStat returns a single Pokeathlon stat (by name or ID). +func PokeathlonStat(id string) (*structs.PokeathlonStat, error) { + endpoint := fmt.Sprintf("pokeathlon-stat/%s", id) + var result structs.PokeathlonStat + + err := do(endpoint, &result) + return &result, err +} + // Pokemon returns a single Pokemon (by name or ID). func Pokemon(id string) (*structs.Pokemon, error) { endpoint := fmt.Sprintf("pokemon/%s", id) @@ -14,3 +68,57 @@ func Pokemon(id string) (*structs.Pokemon, error) { err := do(endpoint, &result) return &result, err } + +// PokemonColor returns a single Pokemon color (by name or ID). +func PokemonColor(id string) (*structs.PokemonColor, error) { + endpoint := fmt.Sprintf("pokemon-color/%s", id) + var result structs.PokemonColor + + err := do(endpoint, &result) + return &result, err +} + +// PokemonForm returns a single Pokemon form (by name or ID). +func PokemonForm(id string) (*structs.PokemonForm, error) { + endpoint := fmt.Sprintf("pokemon-form/%s", id) + var result structs.PokemonForm + + err := do(endpoint, &result) + return &result, err +} + +// PokemonHabitat returns a single Pokemon habitat (by name or ID). +func PokemonHabitat(id string) (*structs.PokemonHabitat, error) { + endpoint := fmt.Sprintf("pokemon-habitat/%s", id) + var result structs.PokemonHabitat + + err := do(endpoint, &result) + return &result, err +} + +// PokemonSpecies returns a single Pokemon species (by name or ID). +func PokemonSpecies(id string) (*structs.PokemonSpecies, error) { + endpoint := fmt.Sprintf("pokemon-species/%s", id) + var result structs.PokemonSpecies + + err := do(endpoint, &result) + return &result, err +} + +// Stat returns a single stat (by name or ID). +func Stat(id string) (*structs.Stat, error) { + endpoint := fmt.Sprintf("stat/%s", id) + var result structs.Stat + + err := do(endpoint, &result) + return &result, err +} + +// Type returns a single type (by name or ID). +func Type(id string) (*structs.Type, error) { + endpoint := fmt.Sprintf("type/%s", id) + var result structs.Type + + err := do(endpoint, &result) + return &result, err +} diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index e6dbd8f..fed89de 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -8,6 +8,66 @@ import ( "github.com/stretchr/testify/assert" ) +func TestAbility(t *testing.T) { + result, err := pokeapi.Ability("1") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Ability{}, result, + "Expect to receive an Ability struct.") + assert.Equal(t, "stench", result.Name, + "Expect to receive Stench.") +} + +func TestAbilityByName(t *testing.T) { + result, err := pokeapi.Ability("stench") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.Ability{}, result, + "Expect to receive an Ability struct.") + assert.Equal(t, "stench", result.Name, + "Expect to receive Stench.") +} + +func TestAbilityFail(t *testing.T) { + result, err := pokeapi.Ability("asdf") + assert.NotEqual(t, nil, err, + "Expect to receive an error.") + assert.IsType(t, &structs.Ability{}, result, + "Expect to receive an Ability struct.") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestEggGroup(t *testing.T) { + result, err := pokeapi.EggGroup("1") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.EggGroup{}, result, + "Expect to receive an EggGroup struct.") + assert.Equal(t, "monster", result.Name, + "Expect to receive Monster.") +} + +func TestEggGroupByName(t *testing.T) { + result, err := pokeapi.EggGroup("monster") + assert.Equal(t, nil, err, + "Expect to not receive an error.") + assert.IsType(t, &structs.EggGroup{}, result, + "Expect to receive an EggGroup struct.") + assert.Equal(t, "monster", result.Name, + "Expect to receive Monster.") +} + +func TestEggGroupFail(t *testing.T) { + result, err := pokeapi.EggGroup("asdf") + assert.NotEqual(t, nil, err, + "Expect to receive an error.") + assert.IsType(t, &structs.EggGroup{}, result, + "Expect to receive am EggGroup struct.") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + func TestPokemon(t *testing.T) { result, err := pokeapi.Pokemon("1") assert.Equal(t, nil, err, From ac6cbdc0e4d7daba78168547af0abdc9603af157 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 03:31:10 -0400 Subject: [PATCH 10/23] Updated progress in README --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8cf22df..ce1f2ad 100644 --- a/README.md +++ b/README.md @@ -60,19 +60,19 @@ Current progress of endpoints. **Bold** are partially implemented. - [ ] GET /move-learn-method/{id or name}/ - [ ] GET /move-target/{id or name}/ ### Pokemon -- [ ] GET /ability/{id or name}/ -- [ ] GET /egg-group/{id or name}/ -- [ ] GET /gender/{id or name}/ -- [ ] GET /growth-rate/{id or name}/ +- [x] GET /ability/{id or name}/ +- [x] GET /egg-group/{id or name}/ +- [ ] **GET /gender/{id or name}/** +- [ ] **GET /growth-rate/{id or name}/** - [ ] GET /nature/{id or name}/ -- [ ] GET /pokeathlon-stat/{id or name}/ +- [ ] **GET /pokeathlon-stat/{id or name}/** - [x] GET /pokemon/{id or name}/ -- [ ] GET /pokemon-color/{id or name}/ -- [ ] GET /pokemon-form/{id or name}/ -- [ ] GET /pokemon-habitat/{id or name}/ -- [ ] GET /pokemon-species/{id or name}/ -- [ ] GET /stat/{id or name}/ -- [ ] GET /type/{id or name}/ +- [ ] **GET /pokemon-color/{id or name}/** +- [ ] **GET /pokemon-form/{id or name}/** +- [ ] **GET /pokemon-habitat/{id or name}/** +- [ ] **GET /pokemon-species/{id or name}/** +- [ ] **GET /stat/{id or name}/** +- [ ] **GET /type/{id or name}/** ### Utility - [ ] GET /language/{id or name}/ From 2c8c61c45df06429434b117f98e43ed5fdca0c3f Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 11:57:28 -0400 Subject: [PATCH 11/23] Shrunk /pokemon/ functions and unit tests; added tests for remaining /pokemon/ endpoints; included Resource --- README.md | 20 ++-- pokemon.go | 121 +++++++-------------- resource.go | 13 +++ tests/pokemon_test.go | 235 +++++++++++++++++++++++++++++++++-------- tests/resource_test.go | 33 ++++++ 5 files changed, 286 insertions(+), 136 deletions(-) create mode 100644 resource.go create mode 100644 tests/resource_test.go diff --git a/README.md b/README.md index ce1f2ad..1729d5e 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,17 @@ Current progress of endpoints. **Bold** are partially implemented. ### Pokemon - [x] GET /ability/{id or name}/ - [x] GET /egg-group/{id or name}/ -- [ ] **GET /gender/{id or name}/** -- [ ] **GET /growth-rate/{id or name}/** -- [ ] GET /nature/{id or name}/ -- [ ] **GET /pokeathlon-stat/{id or name}/** +- [x] GET /gender/{id or name}/ +- [x] GET /growth-rate/{id or name}/ +- [x] GET /nature/{id or name}/ +- [x] GET /pokeathlon-stat/{id or name}/ - [x] GET /pokemon/{id or name}/ -- [ ] **GET /pokemon-color/{id or name}/** -- [ ] **GET /pokemon-form/{id or name}/** -- [ ] **GET /pokemon-habitat/{id or name}/** -- [ ] **GET /pokemon-species/{id or name}/** -- [ ] **GET /stat/{id or name}/** -- [ ] **GET /type/{id or name}/** +- [x] GET /pokemon-color/{id or name}/ +- [x] GET /pokemon-form/{id or name}/ +- [x] GET /pokemon-habitat/{id or name}/ +- [x] GET /pokemon-species/{id or name}/ +- [x] GET /stat/{id or name}/ +- [x] GET /type/{id or name}/ ### Utility - [ ] GET /language/{id or name}/ diff --git a/pokemon.go b/pokemon.go index 5582f6a..c4e5e20 100644 --- a/pokemon.go +++ b/pokemon.go @@ -7,118 +7,79 @@ import ( ) // Ability returns a single ability (by name or ID). -func Ability(id string) (*structs.Ability, error) { - endpoint := fmt.Sprintf("ability/%s", id) - var result structs.Ability - - err := do(endpoint, &result) - return &result, err +func Ability(id string) (result structs.Ability, err error) { + err = do(fmt.Sprintf("ability/%s", id), &result) + return result, err } // EggGroup returns a single egg group (by name or ID). -func EggGroup(id string) (*structs.EggGroup, error) { - endpoint := fmt.Sprintf("egg-group/%s", id) - var result structs.EggGroup - - err := do(endpoint, &result) - return &result, err +func EggGroup(id string) (result structs.EggGroup, err error) { + err = do(fmt.Sprintf("egg-group/%s", id), &result) + return result, err } // Gender returns a single gender (by name or ID). -func Gender(id string) (*structs.Gender, error) { - endpoint := fmt.Sprintf("gender/%s", id) - var result structs.Gender - - err := do(endpoint, &result) - return &result, err +func Gender(id string) (result structs.Gender, err error) { + err = do(fmt.Sprintf("gender/%s", id), &result) + return result, err } // GrowthRate returns a single growth rate (by name or ID). -func GrowthRate(id string) (*structs.GrowthRate, error) { - endpoint := fmt.Sprintf("growth-rate/%s", id) - var result structs.GrowthRate - - err := do(endpoint, &result) - return &result, err +func GrowthRate(id string) (result structs.GrowthRate, err error) { + err = do(fmt.Sprintf("growth-rate/%s", id), &result) + return result, err } // Nature returns a single nature (by name or ID). -func Nature(id string) (*structs.Nature, error) { - endpoint := fmt.Sprintf("nature/%s", id) - var result structs.Nature - - err := do(endpoint, &result) - return &result, err +func Nature(id string) (result structs.Nature, err error) { + err = do(fmt.Sprintf("nature/%s", id), &result) + return result, err } -// PokeathlonStat returns a single Pokeathlon stat (by name or ID). -func PokeathlonStat(id string) (*structs.PokeathlonStat, error) { - endpoint := fmt.Sprintf("pokeathlon-stat/%s", id) - var result structs.PokeathlonStat - - err := do(endpoint, &result) - return &result, err +// PokeathlonStat returns a single Pokeathlon state (by name or ID). +func PokeathlonStat(id string) (result structs.PokeathlonStat, err error) { + err = do(fmt.Sprintf("pokeathlon-stat/%s", id), &result) + return result, err } // Pokemon returns a single Pokemon (by name or ID). -func Pokemon(id string) (*structs.Pokemon, error) { - endpoint := fmt.Sprintf("pokemon/%s", id) - var result structs.Pokemon - - err := do(endpoint, &result) - return &result, err +func Pokemon(id string) (result structs.Pokemon, err error) { + err = do(fmt.Sprintf("pokemon/%s", id), &result) + return result, err } // PokemonColor returns a single Pokemon color (by name or ID). -func PokemonColor(id string) (*structs.PokemonColor, error) { - endpoint := fmt.Sprintf("pokemon-color/%s", id) - var result structs.PokemonColor - - err := do(endpoint, &result) - return &result, err +func PokemonColor(id string) (result structs.PokemonColor, err error) { + err = do(fmt.Sprintf("pokemon-color/%s", id), &result) + return result, err } // PokemonForm returns a single Pokemon form (by name or ID). -func PokemonForm(id string) (*structs.PokemonForm, error) { - endpoint := fmt.Sprintf("pokemon-form/%s", id) - var result structs.PokemonForm - - err := do(endpoint, &result) - return &result, err +func PokemonForm(id string) (result structs.PokemonForm, err error) { + err = do(fmt.Sprintf("pokemon-form/%s", id), &result) + return result, err } // PokemonHabitat returns a single Pokemon habitat (by name or ID). -func PokemonHabitat(id string) (*structs.PokemonHabitat, error) { - endpoint := fmt.Sprintf("pokemon-habitat/%s", id) - var result structs.PokemonHabitat - - err := do(endpoint, &result) - return &result, err +func PokemonHabitat(id string) (result structs.PokemonHabitat, err error) { + err = do(fmt.Sprintf("pokemon-habitat/%s", id), &result) + return result, err } -// PokemonSpecies returns a single Pokemon species (by name or ID). -func PokemonSpecies(id string) (*structs.PokemonSpecies, error) { - endpoint := fmt.Sprintf("pokemon-species/%s", id) - var result structs.PokemonSpecies - - err := do(endpoint, &result) - return &result, err +// PokemonSpecies returns a single Pokemon species(by name or ID). +func PokemonSpecies(id string) (result structs.PokemonSpecies, err error) { + err = do(fmt.Sprintf("pokemon-species/%s", id), &result) + return result, err } // Stat returns a single stat (by name or ID). -func Stat(id string) (*structs.Stat, error) { - endpoint := fmt.Sprintf("stat/%s", id) - var result structs.Stat - - err := do(endpoint, &result) - return &result, err +func Stat(id string) (result structs.Stat, err error) { + err = do(fmt.Sprintf("stat/%s", id), &result) + return result, err } // Type returns a single type (by name or ID). -func Type(id string) (*structs.Type, error) { - endpoint := fmt.Sprintf("type/%s", id) - var result structs.Type - - err := do(endpoint, &result) - return &result, err +func Type(id string) (result structs.Type, err error) { + err = do(fmt.Sprintf("type/%s", id), &result) + return result, err } diff --git a/resource.go b/resource.go new file mode 100644 index 0000000..df2bb6a --- /dev/null +++ b/resource.go @@ -0,0 +1,13 @@ +package pokeapi + +import ( + "github.com/mtslzr/pokeapi-go/structs" +) + +// Resource returns resource list for an endpoint. +func Resource(endpoint string) (*structs.Resource, error) { + var result structs.Resource + + err := do(endpoint, &result) + return &result, err +} diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index fed89de..e847a37 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -4,96 +4,239 @@ import ( "testing" pokeapi "github.com/mtslzr/pokeapi-go" - "github.com/mtslzr/pokeapi-go/structs" "github.com/stretchr/testify/assert" ) func TestAbility(t *testing.T) { - result, err := pokeapi.Ability("1") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Ability{}, result, - "Expect to receive an Ability struct.") + result, _ := pokeapi.Ability("1") assert.Equal(t, "stench", result.Name, "Expect to receive Stench.") } func TestAbilityByName(t *testing.T) { - result, err := pokeapi.Ability("stench") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Ability{}, result, - "Expect to receive an Ability struct.") + result, _ := pokeapi.Ability("stench") assert.Equal(t, "stench", result.Name, "Expect to receive Stench.") } func TestAbilityFail(t *testing.T) { - result, err := pokeapi.Ability("asdf") - assert.NotEqual(t, nil, err, - "Expect to receive an error.") - assert.IsType(t, &structs.Ability{}, result, - "Expect to receive an Ability struct.") + result, _ := pokeapi.Ability("asdf") assert.Equal(t, "", result.Name, "Expect to receive an empty result.") } func TestEggGroup(t *testing.T) { - result, err := pokeapi.EggGroup("1") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.EggGroup{}, result, - "Expect to receive an EggGroup struct.") + result, _ := pokeapi.EggGroup("1") assert.Equal(t, "monster", result.Name, "Expect to receive Monster.") } func TestEggGroupByName(t *testing.T) { - result, err := pokeapi.EggGroup("monster") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.EggGroup{}, result, - "Expect to receive an EggGroup struct.") + result, _ := pokeapi.EggGroup("monster") assert.Equal(t, "monster", result.Name, "Expect to receive Monster.") } func TestEggGroupFail(t *testing.T) { - result, err := pokeapi.EggGroup("asdf") - assert.NotEqual(t, nil, err, - "Expect to receive an error.") - assert.IsType(t, &structs.EggGroup{}, result, - "Expect to receive am EggGroup struct.") + result, _ := pokeapi.EggGroup("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestGender(t *testing.T) { + result, _ := pokeapi.Gender("1") + assert.Equal(t, "female", result.Name, + "Expect to receive Female.") +} + +func TestGenderByName(t *testing.T) { + result, _ := pokeapi.Gender("female") + assert.Equal(t, "female", result.Name, + "Expect to receive Female.") +} + +func TestGenderFail(t *testing.T) { + result, _ := pokeapi.Gender("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestGrowthRate(t *testing.T) { + result, _ := pokeapi.GrowthRate("1") + assert.Equal(t, "slow", result.Name, + "Expect to receive Slow.") +} + +func TestGrowthRateByName(t *testing.T) { + result, _ := pokeapi.GrowthRate("slow") + assert.Equal(t, "slow", result.Name, + "Expect to receive Slow.") +} + +func TestGrowthRateFail(t *testing.T) { + result, _ := pokeapi.GrowthRate("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestNature(t *testing.T) { + result, _ := pokeapi.Nature("1") + assert.Equal(t, "hardy", result.Name, + "Expect to receive Hardy.") +} + +func TestNatureByName(t *testing.T) { + result, _ := pokeapi.Nature("hardy") + assert.Equal(t, "hardy", result.Name, + "Expect to receive Hardy.") +} + +func TestNatureFail(t *testing.T) { + result, _ := pokeapi.Nature("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPokeathlonStat(t *testing.T) { + result, _ := pokeapi.PokeathlonStat("1") + assert.Equal(t, "speed", result.Name, + "Expect to receive Speed.") +} + +func TestPokeathlonStatByName(t *testing.T) { + result, _ := pokeapi.PokeathlonStat("speed") + assert.Equal(t, "speed", result.Name, + "Expect to receive Speed.") +} + +func TestPokeathlonStatFail(t *testing.T) { + result, _ := pokeapi.PokeathlonStat("asdf") assert.Equal(t, "", result.Name, "Expect to receive an empty result.") } func TestPokemon(t *testing.T) { - result, err := pokeapi.Pokemon("1") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Pokemon{}, result, - "Expect to receive a Pokemon struct.") + result, _ := pokeapi.Pokemon("1") assert.Equal(t, "bulbasaur", result.Name, "Expect to receive Bulbasaur.") } func TestPokemonByName(t *testing.T) { - result, err := pokeapi.Pokemon("bulbasaur") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Pokemon{}, result, - "Expect to receive a Pokemon struct.") + result, _ := pokeapi.Pokemon("bulbasaur") assert.Equal(t, "bulbasaur", result.Name, "Expect to receive Bulbasaur.") } func TestPokemonFail(t *testing.T) { - result, err := pokeapi.Pokemon("digimon") - assert.NotEqual(t, nil, err, - "Expect to receive an error.") - assert.IsType(t, &structs.Pokemon{}, result, - "Expect to receive a Pokemon struct.") + result, _ := pokeapi.Pokemon("digimon") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPokemonColor(t *testing.T) { + result, _ := pokeapi.PokemonColor("1") + assert.Equal(t, "black", result.Name, + "Expect to receive Black.") +} + +func TestPokemonColorByName(t *testing.T) { + result, _ := pokeapi.PokemonColor("black") + assert.Equal(t, "black", result.Name, + "Expect to receive Black.") +} + +func TestPokemonColorFail(t *testing.T) { + result, _ := pokeapi.PokemonColor("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPokemonForm(t *testing.T) { + result, _ := pokeapi.PokemonForm("1") + assert.Equal(t, "bulbasaur", result.Name, + "Expect to receive Bulbasaur.") +} + +func TestPokemonFormByName(t *testing.T) { + result, _ := pokeapi.PokemonForm("bulbasaur") + assert.Equal(t, "bulbasaur", result.Name, + "Expect to receive Bulbasaur.") +} + +func TestPokemonFormFail(t *testing.T) { + result, _ := pokeapi.PokemonForm("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPokemonHabitat(t *testing.T) { + result, _ := pokeapi.PokemonHabitat("1") + assert.Equal(t, "cave", result.Name, + "Expect to receive Cave.") +} + +func TestPokemonHabitatByName(t *testing.T) { + result, _ := pokeapi.PokemonHabitat("cave") + assert.Equal(t, "cave", result.Name, + "Expect to receive Cave.") +} + +func TestPokemonHabitatFail(t *testing.T) { + result, _ := pokeapi.PokemonHabitat("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPokemonSpecies(t *testing.T) { + result, _ := pokeapi.PokemonSpecies("1") + assert.Equal(t, "bulbasaur", result.Name, + "Expect to receive Bulbasaur.") +} + +func TestPokemonSpeciesByName(t *testing.T) { + result, _ := pokeapi.PokemonSpecies("bulbasaur") + assert.Equal(t, "bulbasaur", result.Name, + "Expect to receive Bulbasaur.") +} + +func TestPokemonSpeciesFail(t *testing.T) { + result, _ := pokeapi.PokemonSpecies("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestStat(t *testing.T) { + result, _ := pokeapi.Stat("1") + assert.Equal(t, "hp", result.Name, + "Expect to receive HP.") +} + +func TestStatByName(t *testing.T) { + result, _ := pokeapi.Stat("hp") + assert.Equal(t, "hp", result.Name, + "Expect to receive HP.") +} + +func TestStatFail(t *testing.T) { + result, _ := pokeapi.Stat("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestType(t *testing.T) { + result, _ := pokeapi.Type("1") + assert.Equal(t, "normal", result.Name, + "Expect to receive Normal.") +} + +func TestTypeByName(t *testing.T) { + result, _ := pokeapi.Type("normal") + assert.Equal(t, "normal", result.Name, + "Expect to receive Normal.") +} + +func TestTypeFail(t *testing.T) { + result, _ := pokeapi.Type("asdf") assert.Equal(t, "", result.Name, "Expect to receive an empty result.") } diff --git a/tests/resource_test.go b/tests/resource_test.go new file mode 100644 index 0000000..8426e70 --- /dev/null +++ b/tests/resource_test.go @@ -0,0 +1,33 @@ +// +build !quick + +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestResource(t *testing.T) { + tests := []string{ + "berry", "berry-firmness", "berry-flavor", "contest-type", + "contest-effect", "super-contest-effect", "encounter-method", + "encounter-condition", "encounter-condition-value", "evolution-chain", + "evolution-trigger", "generation", "pokedex", "version", "version-group", + "item", "item-attribute", "item-category", "item-fling-effect", + "item-pocket", "location", "location-area", "pal-park-area", "region", + "machine", "move", "move-ailment", "move-battle-style", "move-category", + "move-damage-class", "move-learn-method", "move-target", "ability", + "egg-group", "gender", "growth-rate", "nature", "pokeathlon-stat", + "pokemon", "pokemon-color", "pokemon-form", "pokemon-habitat", + "pokemon-species", "stat", "type", "language", + } + for _, test := range tests { + result, _ := pokeapi.Resource(test) + assert.NotEqual(t, 0, len(result.Results), + "Expect to receive more than zero results.") + assert.NotEqual(t, nil, result.Results[0].URL, + "Expect to receive results with URLs.") + } +} From 15edb185ece2bd66ffd383d1f164dfb8b3839895 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 12:12:20 -0400 Subject: [PATCH 12/23] Started to update README design --- README.md | 164 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 1729d5e..a829b6e 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,106 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. -* [How To](#how-to) -* [Progress](#progress) +* [Getting Started](#getting-started) * [Endpoints](#endpoints) +* [Not Implemented](#not-implemented) * [Documentation](#documentation) -## How To +## Getting Started + +```bash +go get github.com/mtslzr/pokeapi-go +``` ```go import pokeapi "github.com/mtslzr/pokeapi-go" ``` -## Progress +## Endpoints + +### Berries -Current progress of endpoints. **Bold** are partially implemented. +
+ Get Berries + + #### All Berries + + ```go + b := pokeapi.Resource("berry") + fmt.Println(b) + ``` + + ```json + { + "count": 64, + "next": "https://pokeapi.co/api/v2/berry?offset=20&limit=20", + "previous": null, + "results": [ + { + "name": "cheri", + "url": "https://pokeapi.co/api/v2/berry/1/" + }, + ... + } + ``` + +
+ +
+ Get Berry Firmness + + #### All Berry Firmnesses + + ```go + b := pokeapi.Resource("berry-firmness") + fmt.Println(b) + ``` + + ```json + { + "count": 5, + "next": null, + "previous": null, + "results": [ + { + "name": "very-soft", + "url": "https://pokeapi.co/api/v2/berry-firmness/1/" + }, + ... + } + ``` + +
+ +
+ Get Berry Flavors + + #### All Berry Flavors + + ```go + b := pokeapi.Resource("berry-flavor") + fmt.Println(b) + ``` + + ```json + { + "count": 5, + "next": null, + "previous": null, + "results": [ + { + "name": "spicy", + "url": "https://pokeapi.co/api/v2/berry-flavor/1/" + }, + ... + } + ``` + +
+ +## Not Implementd + +Current progress on remaining endpoints. **Bold** are partially implemented. ### Berries - [ ] GET /berry/{id or name}/ @@ -59,77 +145,9 @@ Current progress of endpoints. **Bold** are partially implemented. - [ ] GET /move-damage-class/{id or name}/ - [ ] GET /move-learn-method/{id or name}/ - [ ] GET /move-target/{id or name}/ -### Pokemon -- [x] GET /ability/{id or name}/ -- [x] GET /egg-group/{id or name}/ -- [x] GET /gender/{id or name}/ -- [x] GET /growth-rate/{id or name}/ -- [x] GET /nature/{id or name}/ -- [x] GET /pokeathlon-stat/{id or name}/ -- [x] GET /pokemon/{id or name}/ -- [x] GET /pokemon-color/{id or name}/ -- [x] GET /pokemon-form/{id or name}/ -- [x] GET /pokemon-habitat/{id or name}/ -- [x] GET /pokemon-species/{id or name}/ -- [x] GET /stat/{id or name}/ -- [x] GET /type/{id or name}/ ### Utility - [ ] GET /language/{id or name}/ -## Endpoints - -### Games - -#### Get Generations - -Returns all generations. - -```go -gens := pokeapi.Generations() - -fmt.Println(gens.Count) // 7 -fmt.Println(gens.Results[0].Name) // "generation-i" -``` - -#### Get Generation - -Returns single generation (by name or ID). - -```go -gen := pokeapi.Generation("1") -fmt.Println(gen.MainRegion.Name) // "kanto" - -gen := pokeapi.GenerationByName("generation-i") -fmt.Println(gen.MainRegion.Name) // "kanto" -``` - -### Pokemon - -#### Get Pokemons - -Returns all Pokemon. - -*NOTE: Pagination not yet implemented.* - -```go -pokes := pokeapi.AllPokemon() - -fmt.Println(pokes.Count) // 964 -fmt.Println(pokes.Results[0].Name) // "bulbasaur" -``` - -#### Get Pokemon - -Returns single Pokemon (by name or ID). - -```go -poke := pokeapi.Pokemon("1") -fmt.Println(poke.Name) // "bulbasaur" - -poke := pokeapi.Pokemon("bulbasaur") -fmt.Println(poke.Name) // "bulbasaur" -``` - ## Documentation Full API documentation can be found at [Poke API](https://pokeapi.co/docs/v2.html). \ No newline at end of file From 2c3d523318c86ecb6fc213b36af2af30121962ef Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 12:21:14 -0400 Subject: [PATCH 13/23] Minor README fixes --- README.md | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a829b6e..a098c13 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" "name": "cheri", "url": "https://pokeapi.co/api/v2/berry/1/" }, - ... - } + //... ``` @@ -68,8 +67,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" "name": "very-soft", "url": "https://pokeapi.co/api/v2/berry-firmness/1/" }, - ... - } + //... ``` @@ -94,13 +92,32 @@ import pokeapi "github.com/mtslzr/pokeapi-go" "name": "spicy", "url": "https://pokeapi.co/api/v2/berry-flavor/1/" }, - ... - } + //... ``` -## Not Implementd +### Contests + +### Encounters + +### Evolution + +### Games + +### Items + +### Locations + +### Machines + +### Moves + +### Pokemon + +### Utility + +## Not Implemented Current progress on remaining endpoints. **Bold** are partially implemented. @@ -120,7 +137,7 @@ Current progress on remaining endpoints. **Bold** are partially implemented. - [ ] GET /evolution-chain/{id}/ - [ ] GET /evolution-trigger/{id or name}/ ### Games -- [x] GET /generation/{id or name}/ +- [ ] **GET /generation/{id or name}/** - [ ] GET /pokedex/{id or name}/ - [ ] GET /version/{id or name}/ - [ ] GET /version-group/{id or name}/ From b45e1b4a458079a19101184320a1f2a0d2100969 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 13:18:55 -0400 Subject: [PATCH 14/23] Removed test limit; added /berry/ endpoints and unit tests --- Makefile | 5 +--- README.md | 58 ++++++++++++--------------------------- berries.go | 25 +++++++++++++++++ tests/berries_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++ tests/resource_test.go | 2 -- 5 files changed, 106 insertions(+), 46 deletions(-) create mode 100644 berries.go create mode 100644 tests/berries_test.go diff --git a/Makefile b/Makefile index 1c1b14b..8c71e3c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,8 @@ -all: deps testall +all: deps test deps: tidy vend test: - go test -v -tags quick ./tests/... - -testall: go test -v ./tests/... tidy: diff --git a/README.md b/README.md index a098c13..e526711 100644 --- a/README.md +++ b/README.md @@ -29,20 +29,14 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.Resource("berry") - fmt.Println(b) ``` - ```json - { - "count": 64, - "next": "https://pokeapi.co/api/v2/berry?offset=20&limit=20", - "previous": null, - "results": [ - { - "name": "cheri", - "url": "https://pokeapi.co/api/v2/berry/1/" - }, - //... + #### Single Berry + + *Can pass an ID (e.g. "1") or name (e.g. "cheri").* + + ```go + b := pokeapi.Berry("cheri") ``` @@ -54,20 +48,14 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.Resource("berry-firmness") - fmt.Println(b) ``` - ```json - { - "count": 5, - "next": null, - "previous": null, - "results": [ - { - "name": "very-soft", - "url": "https://pokeapi.co/api/v2/berry-firmness/1/" - }, - //... + #### Single Berry Firmness + + *Can pass an ID (e.g. "1") or name (e.g. "very-soft").* + + ```go + b := pokeapi.BerryFirmness("very-soft") ``` @@ -79,20 +67,14 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.Resource("berry-flavor") - fmt.Println(b) ``` - ```json - { - "count": 5, - "next": null, - "previous": null, - "results": [ - { - "name": "spicy", - "url": "https://pokeapi.co/api/v2/berry-flavor/1/" - }, - //... + #### Single Berry + + *Can pass an ID (e.g. "1") or name (e.g. "spicy").* + + ```go + b := pokeapi.BerryFlavor("spicy") ``` @@ -121,10 +103,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" Current progress on remaining endpoints. **Bold** are partially implemented. -### Berries -- [ ] GET /berry/{id or name}/ -- [ ] GET /berry-firmness/{id or name}/ -- [ ] GET /berry-flavor/{id or name}/ ### Contests - [ ] GET /contest-type/{id or name}/ - [ ] GET /contest-effect/{id}/ diff --git a/berries.go b/berries.go new file mode 100644 index 0000000..58ff707 --- /dev/null +++ b/berries.go @@ -0,0 +1,25 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Berry returns a single berry (by name or ID). +func Berry(id string) (result structs.Berry, err error) { + err = do(fmt.Sprintf("berry/%s", id), &result) + return result, err +} + +// BerryFirmness returns a single berry firmness (by name or ID). +func BerryFirmness(id string) (result structs.BerryFirmness, err error) { + err = do(fmt.Sprintf("berry-firmness/%s", id), &result) + return result, err +} + +// BerryFlavor returns a single berry flavor (by name or ID). +func BerryFlavor(id string) (result structs.BerryFlavor, err error) { + err = do(fmt.Sprintf("berry-flavor/%s", id), &result) + return result, err +} diff --git a/tests/berries_test.go b/tests/berries_test.go new file mode 100644 index 0000000..9b0d0a0 --- /dev/null +++ b/tests/berries_test.go @@ -0,0 +1,62 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestBerry(t *testing.T) { + result, _ := pokeapi.Berry("1") + assert.Equal(t, "cheri", result.Name, + "Expect to receive Cheri.") +} + +func TestBerryByName(t *testing.T) { + result, _ := pokeapi.Berry("cheri") + assert.Equal(t, "cheri", result.Name, + "Expect to receive Cheri.") +} + +func TestBerryFail(t *testing.T) { + result, _ := pokeapi.Berry("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestBerryFirmness(t *testing.T) { + result, _ := pokeapi.BerryFirmness("1") + assert.Equal(t, "very-soft", result.Name, + "Expect to receive Very Soft.") +} + +func TestBerryFirmnessByName(t *testing.T) { + result, _ := pokeapi.BerryFirmness("very-soft") + assert.Equal(t, "very-soft", result.Name, + "Expect to receive Very Soft.") +} + +func TestBerryFirmnessFail(t *testing.T) { + result, _ := pokeapi.BerryFirmness("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestBerryFlavor(t *testing.T) { + result, _ := pokeapi.BerryFlavor("1") + assert.Equal(t, "spicy", result.Name, + "Expect to receive Spicy.") +} + +func TestBerryFlavorByName(t *testing.T) { + result, _ := pokeapi.BerryFlavor("spicy") + assert.Equal(t, "spicy", result.Name, + "Expect to receive Spicy.") +} + +func TestBerryFlavorFail(t *testing.T) { + result, _ := pokeapi.BerryFlavor("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} diff --git a/tests/resource_test.go b/tests/resource_test.go index 8426e70..4f943a8 100644 --- a/tests/resource_test.go +++ b/tests/resource_test.go @@ -1,5 +1,3 @@ -// +build !quick - package tests import ( From 83f13601405cf0845a79e5d853363a374bd5dcfb Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 13:41:47 -0400 Subject: [PATCH 15/23] Added /contest/ endpoints and unit tests --- README.md | 85 ++++++++++++++++++++++++++++++++++-------- contests.go | 25 +++++++++++++ tests/contests_test.go | 50 +++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 contests.go create mode 100644 tests/contests_test.go diff --git a/README.md b/README.md index e526711..792a999 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Berries
- Get Berries + Berries - #### All Berries + #### Get Berries ```go b := pokeapi.Resource("berry") ``` - #### Single Berry + #### Get Berry - *Can pass an ID (e.g. "1") or name (e.g. "cheri").* + *Must pass an ID (e.g. "1") or name (e.g. "cheri").* ```go b := pokeapi.Berry("cheri") @@ -42,17 +42,17 @@ import pokeapi "github.com/mtslzr/pokeapi-go"
- Get Berry Firmness + Berry Firmness - #### All Berry Firmnesses + #### Get Berry Firmnesses ```go b := pokeapi.Resource("berry-firmness") ``` - #### Single Berry Firmness + #### Get Berry Firmness - *Can pass an ID (e.g. "1") or name (e.g. "very-soft").* + *Must pass an ID (e.g. "1") or name (e.g. "very-soft").* ```go b := pokeapi.BerryFirmness("very-soft") @@ -61,17 +61,17 @@ import pokeapi "github.com/mtslzr/pokeapi-go"
- Get Berry Flavors + Berry Flavors - #### All Berry Flavors + #### Get Berry Flavors ```go b := pokeapi.Resource("berry-flavor") ``` - #### Single Berry + #### Get Berry Flavor - *Can pass an ID (e.g. "1") or name (e.g. "spicy").* + *Must pass an ID (e.g. "1") or name (e.g. "spicy").* ```go b := pokeapi.BerryFlavor("spicy") @@ -81,6 +81,63 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Contests +
+ Contest Types + + #### Get Contest Types + + ```go + b := pokeapi.Resource("berry") + ``` + + #### Get Contest Type + + *Must pass an ID (e.g. "1") or name (e.g. "cool").* + + ```go + b := pokeapi.ContestType("cool") + ``` + +
+ +
+ Contest Effects + + #### Get Contest Effects + + ```go + b := pokeapi.Resource("contest-effect") + ``` + + #### Get Contest Effect + + *Must pass an ID (e.g. "1").* + + ```go + b := pokeapi.ContestType("1") + ``` + +
+ +
+ Super Contest Effects + + #### Get Super Contest Effects + + ```go + b := pokeapi.Resource("super-contest-effect") + ``` + + #### Get Super Contest Effect + + *Must pass an ID (e.g. "1").* + + ```go + b := pokeapi.ContestType("1") + ``` + +
+ ### Encounters ### Evolution @@ -103,10 +160,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" Current progress on remaining endpoints. **Bold** are partially implemented. -### Contests -- [ ] GET /contest-type/{id or name}/ -- [ ] GET /contest-effect/{id}/ -- [ ] GET /super-contest-effect/{id}/ ### Encounters - [ ] GET /encounter-method/{id or name}/ - [ ] GET /encounter-condition/{id or name}/ diff --git a/contests.go b/contests.go new file mode 100644 index 0000000..617eb1f --- /dev/null +++ b/contests.go @@ -0,0 +1,25 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// ContestType returns a single contest type (by name or ID). +func ContestType(id string) (result structs.ContestType, err error) { + err = do(fmt.Sprintf("contest-type/%s", id), &result) + return result, err +} + +// ContestEffect returns a single contest effect (by name or ID). +func ContestEffect(id string) (result structs.ContestEffect, err error) { + err = do(fmt.Sprintf("contest-effect/%s", id), &result) + return result, err +} + +// SuperContestEffect returns a single super contest effect (by name or ID). +func SuperContestEffect(id string) (result structs.SuperContestEffect, err error) { + err = do(fmt.Sprintf("super-contest-effect/%s", id), &result) + return result, err +} diff --git a/tests/contests_test.go b/tests/contests_test.go new file mode 100644 index 0000000..ee35deb --- /dev/null +++ b/tests/contests_test.go @@ -0,0 +1,50 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestContestType(t *testing.T) { + result, _ := pokeapi.ContestType("1") + assert.Equal(t, "cool", result.Name, + "Expect to receive Cool.") +} + +func TestContestTypeByName(t *testing.T) { + result, _ := pokeapi.ContestType("cool") + assert.Equal(t, "cool", result.Name, + "Expect to receive Cool.") +} + +func TestContestTypeFail(t *testing.T) { + result, _ := pokeapi.ContestType("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestContestEffect(t *testing.T) { + result, _ := pokeapi.ContestEffect("1") + assert.Equal(t, "A highly appealing move.", + result.FlavorTextEntries[0].FlavorText, "Expect to receive flavor text.") +} + +func TestContestEffectFail(t *testing.T) { + result, _ := pokeapi.ContestEffect("asdf") + assert.Equal(t, 0, len(result.FlavorTextEntries), + "Expect to receive an empty result.") +} + +func TestSuperContestEffect(t *testing.T) { + result, _ := pokeapi.SuperContestEffect("1") + assert.Equal(t, "Enables the user to perform first in the next turn.", + result.FlavorTextEntries[0].FlavorText, "Expect to receive flavor text.") +} + +func TestSuperContestEffectFail(t *testing.T) { + result, _ := pokeapi.SuperContestEffect("asdf") + assert.Equal(t, 0, len(result.FlavorTextEntries), + "Expect to receive an empty result.") +} From d9e77b34a416fb7c9fce34511967b196c2ef1663 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 13:45:32 -0400 Subject: [PATCH 16/23] Added /machine/ endpoint and unit tests; fixed some comments --- README.md | 33 +++++++++++++++++++++++++-------- contests.go | 4 ++-- machines.go | 13 +++++++++++++ tests/machines_test.go | 20 ++++++++++++++++++++ 4 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 machines.go create mode 100644 tests/machines_test.go diff --git a/README.md b/README.md index 792a999..1c13868 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Contest Types ```go - b := pokeapi.Resource("berry") + c := pokeapi.Resource("berry") ``` #### Get Contest Type @@ -95,7 +95,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1") or name (e.g. "cool").* ```go - b := pokeapi.ContestType("cool") + c := pokeapi.ContestType("cool") ```
@@ -106,7 +106,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Contest Effects ```go - b := pokeapi.Resource("contest-effect") + c := pokeapi.Resource("contest-effect") ``` #### Get Contest Effect @@ -114,7 +114,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - b := pokeapi.ContestType("1") + c := pokeapi.ContestType("1") ``` @@ -125,7 +125,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Super Contest Effects ```go - b := pokeapi.Resource("super-contest-effect") + c := pokeapi.Resource("super-contest-effect") ``` #### Get Super Contest Effect @@ -133,7 +133,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - b := pokeapi.ContestType("1") + c := pokeapi.ContestType("1") ``` @@ -150,6 +150,25 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Machines +
+ Machines + + #### Get Machines + + ```go + m := pokeapi.Resource("machine") + ``` + + #### Get Machine + + *Must pass an ID (e.g. "1").* + + ```go + m := pokeapi.ContestType("1") + ``` + +
+ ### Moves ### Pokemon @@ -183,8 +202,6 @@ Current progress on remaining endpoints. **Bold** are partially implemented. - [ ] GET /location-area/{id or name}/ - [ ] GET /pal-park-area/{id or name}/ - [ ] GET /region/{id or name}/ -### Machines -- [ ] GET /machine/{id}/ ### Moves - [ ] GET /move/{id or name}/ - [ ] GET /move-ailment/{id or name}/ diff --git a/contests.go b/contests.go index 617eb1f..7ad0083 100644 --- a/contests.go +++ b/contests.go @@ -12,13 +12,13 @@ func ContestType(id string) (result structs.ContestType, err error) { return result, err } -// ContestEffect returns a single contest effect (by name or ID). +// ContestEffect returns a single contest effect (by ID). func ContestEffect(id string) (result structs.ContestEffect, err error) { err = do(fmt.Sprintf("contest-effect/%s", id), &result) return result, err } -// SuperContestEffect returns a single super contest effect (by name or ID). +// SuperContestEffect returns a single super contest effect (by ID). func SuperContestEffect(id string) (result structs.SuperContestEffect, err error) { err = do(fmt.Sprintf("super-contest-effect/%s", id), &result) return result, err diff --git a/machines.go b/machines.go new file mode 100644 index 0000000..b07e021 --- /dev/null +++ b/machines.go @@ -0,0 +1,13 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Machine returns a single machine (by ID). +func Machine(id string) (result structs.Machine, err error) { + err = do(fmt.Sprintf("machine/%s", id), &result) + return result, err +} diff --git a/tests/machines_test.go b/tests/machines_test.go new file mode 100644 index 0000000..d857e28 --- /dev/null +++ b/tests/machines_test.go @@ -0,0 +1,20 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestMachine(t *testing.T) { + result, _ := pokeapi.Machine("1") + assert.Equal(t, "tm01", result.Item.Name, + "Expect to receive TM01.") +} + +func TestMachineFail(t *testing.T) { + result, _ := pokeapi.Machine("asdf") + assert.Equal(t, "", result.Item.Name, + "Expect to receive an empty result.") +} From 02e668f37623662a8c73050201a5cb4c2b0e3be4 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 13:53:11 -0400 Subject: [PATCH 17/23] Added /utility/ endpoint and unit test --- README.md | 22 ++++++++++++++++++++-- tests/utility_test.go | 26 ++++++++++++++++++++++++++ utility.go | 13 +++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/utility_test.go create mode 100644 utility.go diff --git a/README.md b/README.md index 1c13868..33702e1 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,26 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Utility +
+ Languages + + #### Get Languages + + ```go + m := pokeapi.Resource("language") + ``` + + #### Get Language + + *Must pass an ID (e.g. "1") or name (e.g. "en").* + + ```go + m := pokeapi.ContestType("en") + ``` + +
+ + ## Not Implemented Current progress on remaining endpoints. **Bold** are partially implemented. @@ -210,8 +230,6 @@ Current progress on remaining endpoints. **Bold** are partially implemented. - [ ] GET /move-damage-class/{id or name}/ - [ ] GET /move-learn-method/{id or name}/ - [ ] GET /move-target/{id or name}/ -### Utility -- [ ] GET /language/{id or name}/ ## Documentation diff --git a/tests/utility_test.go b/tests/utility_test.go new file mode 100644 index 0000000..a59271e --- /dev/null +++ b/tests/utility_test.go @@ -0,0 +1,26 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestLanguage(t *testing.T) { + result, _ := pokeapi.Language("1") + assert.Equal(t, "ja-Hrkt", result.Name, + "Expect to receive Japanese.") +} + +func TestLanguageByName(t *testing.T) { + result, _ := pokeapi.Language("ja-Hrkt") + assert.Equal(t, "ja-Hrkt", result.Name, + "Expect to receive Japanese.") +} + +func TestLanguageFail(t *testing.T) { + result, _ := pokeapi.Language("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} diff --git a/utility.go b/utility.go new file mode 100644 index 0000000..6ca19a0 --- /dev/null +++ b/utility.go @@ -0,0 +1,13 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Language returns a single language (by name or ID). +func Language(id string) (result structs.Language, err error) { + err = do(fmt.Sprintf("language/%s", id), &result) + return result, err +} From 4ff2e7f6aeb925a595592504970a974472f61faa Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 13:59:05 -0400 Subject: [PATCH 18/23] Added /evolution/ endpoints and unit tests --- README.md | 47 +++++++++++++++++++++++++++++++---------- evolution.go | 19 +++++++++++++++++ tests/evolution_test.go | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 evolution.go create mode 100644 tests/evolution_test.go diff --git a/README.md b/README.md index 33702e1..ea52f57 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.Berry("cheri") ``` -
@@ -57,7 +56,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.BerryFirmness("very-soft") ``` -
@@ -76,7 +74,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go b := pokeapi.BerryFlavor("spicy") ``` -
### Contests @@ -97,7 +94,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go c := pokeapi.ContestType("cool") ``` -
@@ -116,7 +112,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go c := pokeapi.ContestType("1") ``` -
@@ -135,13 +130,48 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go c := pokeapi.ContestType("1") ``` -
### Encounters ### Evolution +
+ Evolution Chains + + #### Get Evolution Chains + + ```go + b := pokeapi.Resource("evolution-chain") + ``` + + #### Get Evolution Chain + + *Must pass an ID (e.g. "1").* + + ```go + b := pokeapi.EvolutionChain("1") + ``` +
+ +
+ Evolution Triggers + + #### Get Evolution Triggers + + ```go + b := pokeapi.Resource("evolution-trigger") + ``` + + #### Get Evolution Trigger + + *Must pass an ID (e.g. "1") or name (e.g. "level-up").* + + ```go + b := pokeapi.EvolutionTrigger("level-up") + ``` +
+ ### Games ### Items @@ -166,7 +196,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go m := pokeapi.ContestType("1") ``` - ### Moves @@ -191,7 +220,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ```go m := pokeapi.ContestType("en") ``` - @@ -203,9 +231,6 @@ Current progress on remaining endpoints. **Bold** are partially implemented. - [ ] GET /encounter-method/{id or name}/ - [ ] GET /encounter-condition/{id or name}/ - [ ] GET /encounter-condition-value/{id or name}/ -### Evolution -- [ ] GET /evolution-chain/{id}/ -- [ ] GET /evolution-trigger/{id or name}/ ### Games - [ ] **GET /generation/{id or name}/** - [ ] GET /pokedex/{id or name}/ diff --git a/evolution.go b/evolution.go new file mode 100644 index 0000000..2962c3e --- /dev/null +++ b/evolution.go @@ -0,0 +1,19 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// EvolutionChain returns a single evolution chain (by ID). +func EvolutionChain(id string) (result structs.EvolutionChain, err error) { + err = do(fmt.Sprintf("evolution-chain/%s", id), &result) + return result, err +} + +// EvolutionTrigger returns a single evolution trigger (by ID or name). +func EvolutionTrigger(id string) (result structs.EvolutionTrigger, err error) { + err = do(fmt.Sprintf("evolution-trigger/%s", id), &result) + return result, err +} diff --git a/tests/evolution_test.go b/tests/evolution_test.go new file mode 100644 index 0000000..027a6cc --- /dev/null +++ b/tests/evolution_test.go @@ -0,0 +1,38 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestEvolutionChain(t *testing.T) { + result, _ := pokeapi.EvolutionChain("1") + assert.Equal(t, "bulbasaur", result.Chain.Species.Name, + "Expect to receive Bulbasaur.") +} + +func TestEvolutionChainFail(t *testing.T) { + result, _ := pokeapi.EvolutionChain("asdf") + assert.Equal(t, "", result.Chain.Species.Name, + "Expect to receive an empty result.") +} + +func TestEvolutionTrigger(t *testing.T) { + result, _ := pokeapi.EvolutionTrigger("1") + assert.Equal(t, "level-up", result.Name, + "Expect to receive Level Up.") +} + +func TestEvolutionTriggerByName(t *testing.T) { + result, _ := pokeapi.EvolutionTrigger("level-up") + assert.Equal(t, "level-up", result.Name, + "Expect to receive Level Up.") +} + +func TestEvolutionTriggerFail(t *testing.T) { + result, _ := pokeapi.EvolutionTrigger("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} From 11da45da13a4e545518db84d801e0e89e6f9b825 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 14:01:19 -0400 Subject: [PATCH 19/23] Updated Table of Contents in README --- README.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea52f57..58dac00 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,27 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. -* [Getting Started](#getting-started) -* [Endpoints](#endpoints) -* [Not Implemented](#not-implemented) -* [Documentation](#documentation) +- [pokeapi-go](#pokeapi-go) + - [Getting Started](#Getting-Started) + - [Endpoints](#Endpoints) + - [Berries](#Berries) + - [Contests](#Contests) + - [Encounters](#Encounters) + - [Evolution](#Evolution) + - [Games](#Games) + - [Items](#Items) + - [Locations](#Locations) + - [Machines](#Machines) + - [Moves](#Moves) + - [Pokemon](#Pokemon) + - [Utility](#Utility) + - [Not Implemented](#Not-Implemented) + - [Encounters](#Encounters-1) + - [Games](#Games-1) + - [Items](#Items-1) + - [Locations](#Locations-1) + - [Moves](#Moves-1) + - [Documentation](#Documentation) ## Getting Started From 6c4e6f21ad07124132d1a48e41795e9581ed86d0 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 14:21:36 -0400 Subject: [PATCH 20/23] Added /games/ and /encounters/ endpoints and unit tests --- README.md | 155 ++++++++++++++++++++++++++++++++++----- encounters.go | 28 +++++++ games.go | 25 +++++-- tests/encounters_test.go | 62 ++++++++++++++++ tests/games_test.go | 73 ++++++++++++++---- 5 files changed, 302 insertions(+), 41 deletions(-) create mode 100644 encounters.go create mode 100644 tests/encounters_test.go diff --git a/README.md b/README.md index 58dac00..3e34945 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. - [Pokemon](#Pokemon) - [Utility](#Utility) - [Not Implemented](#Not-Implemented) - - [Encounters](#Encounters-1) - - [Games](#Games-1) - [Items](#Items-1) - [Locations](#Locations-1) - [Moves](#Moves-1) @@ -127,7 +125,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - c := pokeapi.ContestType("1") + c := pokeapi.ContestEffect("1") ``` @@ -145,12 +143,66 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - c := pokeapi.ContestType("1") + c := pokeapi.SuperContestEffect("1") ``` ### Encounters +
+ Encounter Methods + + #### Get Encounter Methods + + ```go + e := pokeapi.Resource("encounter-method") + ``` + + #### Get Encounter Method + + *Must pass an ID (e.g. "1") or name (e.g. "walk").* + + ```go + e := pokeapi.EncounterMethod("walk") + ``` +
+ +
+ Encounter Conditions + + #### Get Encounter Conditions + + ```go + e := pokeapi.Resource("encounter-condition") + ``` + + #### Get Encounter Condition + + *Must pass an ID (e.g. "1") or name (e.g. "swarm").* + + ```go + e := pokeapi.EncounterCondition("swarm") + ``` +
+ +
+ Encounter Condition Values + + #### Get Encounter Condition Values + + ```go + e := pokeapi.Resource("encounter-condition-value") + ``` + + #### Get Encounter Condition Value + + *Must pass an ID (e.g. "1") or name (e.g. "swarm-yes").* + + ```go + e := pokeapi.EncounterConditionValue("swarm-yes") + ``` +
+ ### Evolution
@@ -159,7 +211,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Evolution Chains ```go - b := pokeapi.Resource("evolution-chain") + e := pokeapi.Resource("evolution-chain") ``` #### Get Evolution Chain @@ -167,7 +219,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - b := pokeapi.EvolutionChain("1") + e := pokeapi.EvolutionChain("1") ```
@@ -177,7 +229,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Evolution Triggers ```go - b := pokeapi.Resource("evolution-trigger") + e := pokeapi.Resource("evolution-trigger") ``` #### Get Evolution Trigger @@ -185,12 +237,84 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1") or name (e.g. "level-up").* ```go - b := pokeapi.EvolutionTrigger("level-up") + e := pokeapi.EvolutionTrigger("level-up") ``` ### Games +
+ Generations + + #### Get Generations + + ```go + g := pokeapi.Resource("generation") + ``` + + #### Get Generation + + *Must pass an ID (e.g. "1") or name (e.g. "generation-i").* + + ```go + g := pokeapi.Generation("generation-i") + ``` +
+ +
+ Pokedex + + #### Get All Pokedex + + ```go + g := pokeapi.Resource("pokedex") + ``` + + #### Get Single Pokedex + + *Must pass an ID (e.g. "1") or name (e.g. "national").* + + ```go + g := pokeapi.Pokedex("national") + ``` +
+ +
+ Versions + + #### Get Versions + + ```go + g := pokeapi.Resource("version") + ``` + + #### Get Version + + *Must pass an ID (e.g. "1") or name (e.g. "red").* + + ```go + g := pokeapi.Version("red") + ``` +
+ +
+ Version Groups + + #### Get Version Groups + + ```go + g := pokeapi.Resource("version-group") + ``` + + #### Get Version Group + + *Must pass an ID (e.g. "1") or name (e.g. "red-blue").* + + ```go + g := pokeapi.VersionGroup("red-blue") + ``` +
+ ### Items ### Locations @@ -211,7 +335,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1").* ```go - m := pokeapi.ContestType("1") + m := pokeapi.Machine("1") ``` @@ -227,7 +351,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" #### Get Languages ```go - m := pokeapi.Resource("language") + l := pokeapi.Resource("language") ``` #### Get Language @@ -235,7 +359,7 @@ import pokeapi "github.com/mtslzr/pokeapi-go" *Must pass an ID (e.g. "1") or name (e.g. "en").* ```go - m := pokeapi.ContestType("en") + l := pokeapi.Lanuage("en") ``` @@ -244,15 +368,6 @@ import pokeapi "github.com/mtslzr/pokeapi-go" Current progress on remaining endpoints. **Bold** are partially implemented. -### Encounters -- [ ] GET /encounter-method/{id or name}/ -- [ ] GET /encounter-condition/{id or name}/ -- [ ] GET /encounter-condition-value/{id or name}/ -### Games -- [ ] **GET /generation/{id or name}/** -- [ ] GET /pokedex/{id or name}/ -- [ ] GET /version/{id or name}/ -- [ ] GET /version-group/{id or name}/ ### Items - [ ] GET /item/{id or name}/ - [ ] GET /item-attribute/{id or name}/ diff --git a/encounters.go b/encounters.go new file mode 100644 index 0000000..0fb3c74 --- /dev/null +++ b/encounters.go @@ -0,0 +1,28 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// EncounterMethod returns a single encounter method (by name or ID). +func EncounterMethod(id string) (result structs.EncounterMethod, err error) { + err = do(fmt.Sprintf("encounter-method/%s", id), &result) + return result, err +} + +// EncounterCondition returns a single encounter condition (by name or ID). +func EncounterCondition(id string) (result structs.EncounterCondition, + err error) { + err = do(fmt.Sprintf("encounter-condition/%s", id), &result) + return result, err +} + +// EncounterConditionValue returns a single encounter condition value +// (by name or ID). +func EncounterConditionValue(id string) (result structs.EncounterConditionValue, + err error) { + err = do(fmt.Sprintf("encounter-condition-value/%s", id), &result) + return result, err +} diff --git a/games.go b/games.go index b9f0bef..63018f6 100644 --- a/games.go +++ b/games.go @@ -7,10 +7,25 @@ import ( ) // Generation returns a single generation (by name or ID). -func Generation(id string) (*structs.Generation, error) { - endpoint := fmt.Sprintf("generation/%s", id) - var result structs.Generation +func Generation(id string) (result structs.Generation, err error) { + err = do(fmt.Sprintf("generation/%s", id), &result) + return result, err +} + +// Pokedex returns a single Pokedex (by name or ID). +func Pokedex(id string) (result structs.Pokedex, err error) { + err = do(fmt.Sprintf("pokedex/%s", id), &result) + return result, err +} + +// Version returns a single version (by name or ID). +func Version(id string) (result structs.Version, err error) { + err = do(fmt.Sprintf("version/%s", id), &result) + return result, err +} - err := do(endpoint, &result) - return &result, err +// VersionGroup returns a single version group (by name or ID). +func VersionGroup(id string) (result structs.VersionGroup, err error) { + err = do(fmt.Sprintf("version-group/%s", id), &result) + return result, err } diff --git a/tests/encounters_test.go b/tests/encounters_test.go new file mode 100644 index 0000000..5c303d8 --- /dev/null +++ b/tests/encounters_test.go @@ -0,0 +1,62 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestEncounterMethod(t *testing.T) { + result, _ := pokeapi.EncounterMethod("1") + assert.Equal(t, "walk", result.Name, + "Expect to receive Walk.") +} + +func TestEncounterMethodByName(t *testing.T) { + result, _ := pokeapi.EncounterMethod("walk") + assert.Equal(t, "walk", result.Name, + "Expect to receive Walk.") +} + +func TestEncounterMethodFail(t *testing.T) { + result, _ := pokeapi.EncounterMethod("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestEncounterCondition(t *testing.T) { + result, _ := pokeapi.EncounterCondition("1") + assert.Equal(t, "swarm", result.Name, + "Expect to receive Swarm.") +} + +func TestEncounterConditionByName(t *testing.T) { + result, _ := pokeapi.EncounterCondition("swarm") + assert.Equal(t, "swarm", result.Name, + "Expect to receive Swarm.") +} + +func TestEncounterConditionFail(t *testing.T) { + result, _ := pokeapi.EncounterCondition("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestEncounterConditionValue(t *testing.T) { + result, _ := pokeapi.EncounterConditionValue("1") + assert.Equal(t, "swarm-yes", result.Name, + "Expect to receive Swarm (yes).") +} + +func TestEncounterConditionValueByName(t *testing.T) { + result, _ := pokeapi.EncounterConditionValue("swarm-yes") + assert.Equal(t, "swarm-yes", result.Name, + "Expect to receive Swarm (yes).") +} + +func TestEncounterConditionValueFail(t *testing.T) { + result, _ := pokeapi.EncounterConditionValue("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} diff --git a/tests/games_test.go b/tests/games_test.go index 872d2ed..e0a5f85 100644 --- a/tests/games_test.go +++ b/tests/games_test.go @@ -4,36 +4,77 @@ import ( "testing" pokeapi "github.com/mtslzr/pokeapi-go" - "github.com/mtslzr/pokeapi-go/structs" "github.com/stretchr/testify/assert" ) func TestGeneration(t *testing.T) { - result, err := pokeapi.Generation("1") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Generation{}, result, - "Expect to receive a Generation struct.") + result, _ := pokeapi.Generation("1") assert.Equal(t, "kanto", result.MainRegion.Name, "Expect to receive Kanto.") } func TestGenerationByName(t *testing.T) { - result, err := pokeapi.Generation("generation-i") - assert.Equal(t, nil, err, - "Expect to not receive an error.") - assert.IsType(t, &structs.Generation{}, result, - "Expect to receive a Generation struct.") + result, _ := pokeapi.Generation("generation-i") assert.Equal(t, "kanto", result.MainRegion.Name, "Expect to receive Kanto.") } func TestGenerationFail(t *testing.T) { - result, err := pokeapi.Generation("asdf") - assert.NotEqual(t, nil, err, - "Expect to receive an error.") - assert.IsType(t, &structs.Generation{}, result, - "Expect to receive a Generation struct.") + result, _ := pokeapi.Generation("asdf") assert.Equal(t, "", result.MainRegion.Name, "Expect to receive an empty result.") } + +func TestPokedex(t *testing.T) { + result, _ := pokeapi.Pokedex("1") + assert.Equal(t, "national", result.Name, + "Expect to receive National Dex.") +} + +func TestPokedexByName(t *testing.T) { + result, _ := pokeapi.Pokedex("national") + assert.Equal(t, "national", result.Name, + "Expect to receive National Dex.") +} + +func TestPokedexFail(t *testing.T) { + result, _ := pokeapi.Pokedex("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestVersion(t *testing.T) { + result, _ := pokeapi.Version("1") + assert.Equal(t, "red", result.Name, + "Expect to receive Red Version.") +} + +func TestVersionByName(t *testing.T) { + result, _ := pokeapi.Version("red") + assert.Equal(t, "red", result.Name, + "Expect to receive Red Version.") +} + +func TestVersionFail(t *testing.T) { + result, _ := pokeapi.Version("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestVersionGroup(t *testing.T) { + result, _ := pokeapi.VersionGroup("1") + assert.Equal(t, "red-blue", result.Name, + "Expect to receive Red-Blue.") +} + +func TestVersionGroupByName(t *testing.T) { + result, _ := pokeapi.VersionGroup("red-blue") + assert.Equal(t, "red-blue", result.Name, + "Expect to receive Red-Blue.") +} + +func TestVersionGroupFail(t *testing.T) { + result, _ := pokeapi.VersionGroup("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} From 5033a60c8314c8a7a6d48228cabfcd78003c030a Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 14:34:00 -0400 Subject: [PATCH 21/23] Added /location/ endpoints and unit tests --- README.md | 78 ++++++++++++++++++++++++++++++++++++---- locations.go | 31 ++++++++++++++++ tests/locations_test.go | 80 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 locations.go create mode 100644 tests/locations_test.go diff --git a/README.md b/README.md index 3e34945..b917a04 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. - [Utility](#Utility) - [Not Implemented](#Not-Implemented) - [Items](#Items-1) - - [Locations](#Locations-1) - [Moves](#Moves-1) - [Documentation](#Documentation) @@ -319,6 +318,78 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Locations +
+ Locations + + #### Get Locations + + ```go + l := pokeapi.Resource("location") + ``` + + #### Get Location + + *Must pass an ID (e.g. "1") or name (e.g. "canalave-city").* + + ```go + l := pokeapi.Location("canalave-city") + ``` +
+ +
+ Location Areas + + #### Get Location Areas + + ```go + l := pokeapi.Resource("location-area") + ``` + + #### Get Location Area + + *Must pass an ID (e.g. "1") or name (e.g. "canalave-city-area").* + + ```go + l := pokeapi.LocationArea("canalave-city-area") + ``` +
+ +
+ Pal Park Areas + + #### Get Pal Park Areas + + ```go + l := pokeapi.Resource("pal-park-area") + ``` + + #### Get Pal Park Area + + *Must pass an ID (e.g. "1") or name (e.g. "forest").* + + ```go + l := pokeapi.PalParkArea("forest") + ``` +
+ +
+ Regions + + #### Get Regions + + ```go + l := pokeapi.Resource("region") + ``` + + #### Get Region + + *Must pass an ID (e.g. "1") or name (e.g. "kanto").* + + ```go + l := pokeapi.Region("kanto") + ``` +
+ ### Machines
@@ -374,11 +445,6 @@ Current progress on remaining endpoints. **Bold** are partially implemented. - [ ] GET /item-category/{id or name}/ - [ ] GET /item-fling-effect/{id or name}/ - [ ] GET /item-pocket/{id or name}/ -### Locations -- [ ] GET /location/{id or name}/ -- [ ] GET /location-area/{id or name}/ -- [ ] GET /pal-park-area/{id or name}/ -- [ ] GET /region/{id or name}/ ### Moves - [ ] GET /move/{id or name}/ - [ ] GET /move-ailment/{id or name}/ diff --git a/locations.go b/locations.go new file mode 100644 index 0000000..884e23f --- /dev/null +++ b/locations.go @@ -0,0 +1,31 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Location returns a single location (by name or ID). +func Location(id string) (result structs.Location, err error) { + err = do(fmt.Sprintf("location/%s", id), &result) + return result, err +} + +// LocationArea returns a single location area (by name or ID). +func LocationArea(id string) (result structs.LocationArea, err error) { + err = do(fmt.Sprintf("location-area/%s", id), &result) + return result, err +} + +// PalParkArea returns a single Pal Park area (by name or ID). +func PalParkArea(id string) (result structs.PalParkArea, err error) { + err = do(fmt.Sprintf("pal-park-area/%s", id), &result) + return result, err +} + +// Region returns a single region (by name or ID). +func Region(id string) (result structs.Region, err error) { + err = do(fmt.Sprintf("region/%s", id), &result) + return result, err +} diff --git a/tests/locations_test.go b/tests/locations_test.go new file mode 100644 index 0000000..79be725 --- /dev/null +++ b/tests/locations_test.go @@ -0,0 +1,80 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestLocation(t *testing.T) { + result, _ := pokeapi.Location("1") + assert.Equal(t, "canalave-city", result.Name, + "Expect to receive Canalave City.") +} + +func TestLocationByName(t *testing.T) { + result, _ := pokeapi.Location("canalave-city") + assert.Equal(t, "canalave-city", result.Name, + "Expect to receive Canalave City.") +} + +func TestLocationFail(t *testing.T) { + result, _ := pokeapi.Location("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestLocationArea(t *testing.T) { + result, _ := pokeapi.LocationArea("1") + assert.Equal(t, "canalave-city-area", result.Name, + "Expect to receive Canalave City area.") +} + +func TestLocationAreaByName(t *testing.T) { + result, _ := pokeapi.LocationArea("canalave-city-area") + assert.Equal(t, "canalave-city-area", result.Name, + "Expect to receive Canalave City area.") +} + +func TestLocationAreaFail(t *testing.T) { + result, _ := pokeapi.LocationArea("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestPalParkArea(t *testing.T) { + result, _ := pokeapi.PalParkArea("1") + assert.Equal(t, "forest", result.Name, + "Expect to receive Forest.") +} + +func TestPalParkAreaByName(t *testing.T) { + result, _ := pokeapi.PalParkArea("forest") + assert.Equal(t, "forest", result.Name, + "Expect to receive Forest.") +} + +func TestPalParkAreaFail(t *testing.T) { + result, _ := pokeapi.PalParkArea("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestRegion(t *testing.T) { + result, _ := pokeapi.Region("1") + assert.Equal(t, "kanto", result.Name, + "Expect to receive Kanto.") +} + +func TestRegionByName(t *testing.T) { + result, _ := pokeapi.Region("kanto") + assert.Equal(t, "kanto", result.Name, + "Expect to receive Kanto.") +} + +func TestRegionFail(t *testing.T) { + result, _ := pokeapi.Region("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} From 51af2c7d80eda3d432e9c202d7db4a1a757ebcc6 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 15:11:46 -0400 Subject: [PATCH 22/23] Added /items/ and /moves/ endpoints and unit tests; added remaining /pokemon/ endpoints and unit tests --- README.md | 521 +++++++++++++++++++++++++++++++++++++++--- items.go | 37 +++ moves.go | 49 ++++ pokemon.go | 14 +- structs/pokemon.go | 42 ++++ tests/items_test.go | 98 ++++++++ tests/moves_test.go | 134 +++++++++++ tests/pokemon_test.go | 30 +++ 8 files changed, 895 insertions(+), 30 deletions(-) create mode 100644 items.go create mode 100644 moves.go create mode 100644 tests/items_test.go create mode 100644 tests/moves_test.go diff --git a/README.md b/README.md index b917a04..4ca3b68 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. - [pokeapi-go](#pokeapi-go) + - [Documentation](#Documentation) - [Getting Started](#Getting-Started) - [Endpoints](#Endpoints) - [Berries](#Berries) @@ -17,10 +18,10 @@ Wrapper for [Poke API](https://pokeapi.co), written in Go. - [Moves](#Moves) - [Pokemon](#Pokemon) - [Utility](#Utility) - - [Not Implemented](#Not-Implemented) - - [Items](#Items-1) - - [Moves](#Moves-1) - - [Documentation](#Documentation) + +## Documentation + +Full API documentation can be found at [Poke API](https://pokeapi.co/docs/v2.html). ## Getting Started @@ -316,6 +317,96 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Items +
+ Items + + #### Get Items + + ```go + i := pokeapi.Resource("item") + ``` + + #### Get Item + + *Must pass an ID (e.g. "1") or name (e.g. "master-ball").* + + ```go + i := pokeapi.Item("master-ball") + ``` +
+ +
+ Item Attributes + + #### Get Item Attributes + + ```go + i := pokeapi.Resource("item-attribute") + ``` + + #### Get Item Attribute + + *Must pass an ID (e.g. "1") or name (e.g. "countable").* + + ```go + i := pokeapi.ItemAttribute("countable") + ``` +
+ +
+ Item Categories + + #### Get Item Ctegories + + ```go + i := pokeapi.Resource("item-category") + ``` + + #### Get Item Category + + *Must pass an ID (e.g. "1") or name (e.g. "stat-boosts").* + + ```go + i := pokeapi.ItemCategory("stat-boosts") + ``` +
+ +
+ Item Fling Effects + + #### Get Item Fling Effects + + ```go + i := pokeapi.Resource("item-fling-effect") + ``` + + #### Get Item Fling Effect + + *Must pass an ID (e.g. "1") or name (e.g. "badly-poison").* + + ```go + i := pokeapi.ItemFlingEffect("badly-poison") + ``` +
+ +
+ Item Pockets + + #### Get Item Pockets + + ```go + i := pokeapi.Resource("item-pocket") + ``` + + #### Get Item Pocket + + *Must pass an ID (e.g. "1") or name (e.g. "misc").* + + ```go + i := pokeapi.ItemPocket("misc") + ``` +
+ ### Locations
@@ -412,48 +503,420 @@ import pokeapi "github.com/mtslzr/pokeapi-go" ### Moves +
+ Moves + + #### Get Moves + + ```go + m := pokeapi.Resource("move") + ``` + + #### Get Move + + *Must pass an ID (e.g. "1") or name (e.g. "pound").* + + ```go + m := pokeapi.Move("pound") + ``` +
+ +
+ Move Ailments + + #### Get Move Ailments + + ```go + m := pokeapi.Resource("move-ailment") + ``` + + #### Get Move Ailment + + *Must pass an ID (e.g. "1") or name (e.g. "paralysis").* + + ```go + m := pokeapi.MoveAilment("paralysis") + ``` +
+ +
+ Move Battle Styles + + #### Get Move Battle Styles + + ```go + m := pokeapi.Resource("move-battle-style") + ``` + + #### Get Move Battle Style + + *Must pass an ID (e.g. "1") or name (e.g. "attack").* + + ```go + m := pokeapi.MoveBattleStyle("attack") + ``` +
+ +
+ Move Categories + + #### Get Move Categories + + ```go + m := pokeapi.Resource("move-catgory") + ``` + + #### Get Move Category + + *Must pass an ID (e.g. "1") or name (e.g. "ailment").* + + ```go + m := pokeapi.MoveCategory("ailment") + ``` +
+ +
+ Move Damage Classes + + #### Get Move Damage Classes + + ```go + m := pokeapi.Resource("move-damage-class") + ``` + + #### Get Move Damage Class + + *Must pass an ID (e.g. "1") or name (e.g. "status").* + + ```go + m := pokeapi.MoveDamageClass("status") + ``` +
+ +
+ Move Learn Methods + + #### Get Move Learn Methods + + ```go + m := pokeapi.Resource("move-learn-method") + ``` + + #### Get Move Learn Method + + *Must pass an ID (e.g. "1") or name (e.g. "level-up").* + + ```go + m := pokeapi.MoveLearnMethod("level-up") + ``` +
+ +
+ Move Targets + + #### Get Move Targets + + ```go + m := pokeapi.Resource("move-target") + ``` + + #### Get Move Target + + *Must pass an ID (e.g. "1") or name (e.g. "specific-move").* + + ```go + m := pokeapi.MoveTarget("specific-move") + ``` +
+ ### Pokemon -### Utility +
+ Abilities + + #### Get Abilities + + ```go + p := pokeapi.Resource("ability") + ``` + + #### Get Ability + + *Must pass an ID (e.g. "1") or name (e.g. "stench").* + + ```go + p := pokeapi.Ability("stench") + ``` +
- Languages + Characteristics - #### Get Languages + #### Get Characteristics ```go - l := pokeapi.Resource("language") + p := pokeapi.Resource("characteristic") ``` - #### Get Language + #### Get Characteristic - *Must pass an ID (e.g. "1") or name (e.g. "en").* + *Must pass an ID (e.g. "1").* + + ```go + p := pokeapi.Characteristic("1") + ``` +
+ +
+ Egg Groups + + #### Get Egg Groups ```go - l := pokeapi.Lanuage("en") + p := pokeapi.Resource("egg-group") + ``` + + #### Get Egg Group + + *Must pass an ID (e.g. "1") or name (e.g. "monster").* + + ```go + p := pokeapi.EggGroup("monster") ```
+
+ Genders + + #### Get Genders -## Not Implemented + ```go + p := pokeapi.Resource("gender") + ``` -Current progress on remaining endpoints. **Bold** are partially implemented. + #### Get Gender -### Items -- [ ] GET /item/{id or name}/ -- [ ] GET /item-attribute/{id or name}/ -- [ ] GET /item-category/{id or name}/ -- [ ] GET /item-fling-effect/{id or name}/ -- [ ] GET /item-pocket/{id or name}/ -### Moves -- [ ] GET /move/{id or name}/ -- [ ] GET /move-ailment/{id or name}/ -- [ ] GET /move-battle-style/{id or name}/ -- [ ] GET /move-category/{id or name}/ -- [ ] GET /move-damage-class/{id or name}/ -- [ ] GET /move-learn-method/{id or name}/ -- [ ] GET /move-target/{id or name}/ + *Must pass an ID (e.g. "1") or name (e.g. "female").* -## Documentation + ```go + p := pokeapi.Gender("female") + ``` +
-Full API documentation can be found at [Poke API](https://pokeapi.co/docs/v2.html). \ No newline at end of file +
+ Growth Rates + + #### Get Growth Rates + + ```go + p := pokeapi.Resource("growth-rate") + ``` + + #### Get Growth Rate + + *Must pass an ID (e.g. "1") or name (e.g. "slow").* + + ```go + p := pokeapi.GrowthRate("slow") + ``` +
+ +
+ Natures + + #### Get Natures + + ```go + p := pokeapi.Resource("nature") + ``` + + #### Get Nature + + *Must pass an ID (e.g. "1") or name (e.g. "hardy").* + + ```go + p := pokeapi.Nature("hardy") + ``` +
+ +
+ Pokeathlon Stats + + #### Get Pokeathlon Stats + + ```go + p := pokeapi.Resource("pokeathlon-stat") + ``` + + #### Get Pokeathlon Stat + + *Must pass an ID (e.g. "1") or name (e.g. "speed").* + + ```go + p := pokeapi.PokeathlonStat("speed") + ``` +
+ +
+ Pokemon + + #### Get All Pokemon + + ```go + l := pokeapi.Resource("pokemon") + ``` + + #### Get Single Pokemon + + *Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").* + + ```go + l := pokeapi.Pokemon("bulabsaur") + ``` +
+ +
+ Pokemon Colors + + #### Get Pokemon Colors + + ```go + p := pokeapi.Resource("pokemon-color") + ``` + + #### Get Pokemon Color + + *Must pass an ID (e.g. "1") or name (e.g. "black").* + + ```go + p := pokeapi.PokemonColor("black") + ``` +
+ +
+ Pokemon Forms + + #### Get Pokemon Forms + + ```go + p := pokeapi.Resource("pokemon-form") + ``` + + #### Get Pokemon Form + + *Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").* + + ```go + p := pokeapi.PokemonForm("bulabsaur") + ``` +
+ +
+ Pokemon Habitats + + #### Get Pokemon Habitats + + ```go + p := pokeapi.Resource("pokemon-habitat") + ``` + + #### Get Pokemon Habitat + + *Must pass an ID (e.g. "1") or name (e.g. "cave").* + + ```go + p := pokeapi.PokemonHabitat("cave") + ``` +
+ +
+ Pokemon Shapes + + #### Get Pokemon Shapes + + ```go + p := pokeapi.Resource("pokemon-shape") + ``` + + #### Get Pokemon Shape + + *Must pass an ID (e.g. "1") or name (e.g. "ball").* + + ```go + p := pokeapi.PokemonShape("ball") + ``` +
+ +
+ Pokemon Species + + #### Get All Pokemon Species + + ```go + p := pokeapi.Resource("pokemon-species") + ``` + + #### Get Single Pokemon Species + + *Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").* + + ```go + p := pokeapi.PokemonSpecies("bulabsaur") + ``` +
+ +
+ Stats + + #### Get Stats + + ```go + p := pokeapi.Resource("stat") + ``` + + #### Get Stat + + *Must pass an ID (e.g. "1") or name (e.g. "hp").* + + ```go + p := pokeapi.Stat("hp") + ``` +
+ +
+ Types + + #### Get Types + + ```go + p := pokeapi.Resource("type") + ``` + + #### Get Type + + *Must pass an ID (e.g. "1") or name (e.g. "normal").* + + ```go + p := pokeapi.Type("normal") + ``` +
+ +### Utility + +
+ Languages + + #### Get Languages + + ```go + u := pokeapi.Resource("language") + ``` + + #### Get Language + + *Must pass an ID (e.g. "1") or name (e.g. "en").* + + ```go + u := pokeapi.Language("en") + ``` +
diff --git a/items.go b/items.go new file mode 100644 index 0000000..ede1c76 --- /dev/null +++ b/items.go @@ -0,0 +1,37 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Item returns a single item (by name or ID). +func Item(id string) (result structs.Item, err error) { + err = do(fmt.Sprintf("item/%s", id), &result) + return result, err +} + +// ItemAttribute returns a single item attribute (by name or ID). +func ItemAttribute(id string) (result structs.ItemAttribute, err error) { + err = do(fmt.Sprintf("item-attribute/%s", id), &result) + return result, err +} + +// ItemCategory returns a single item category (by name or ID). +func ItemCategory(id string) (result structs.ItemCategory, err error) { + err = do(fmt.Sprintf("item-category/%s", id), &result) + return result, err +} + +// ItemFlingEffect returns a single item fling effect (by name or ID). +func ItemFlingEffect(id string) (result structs.ItemFlingEffect, err error) { + err = do(fmt.Sprintf("item-fling-effect/%s", id), &result) + return result, err +} + +// ItemPocket returns a single item pocket (by name or ID). +func ItemPocket(id string) (result structs.ItemPocket, err error) { + err = do(fmt.Sprintf("item-pocket/%s", id), &result) + return result, err +} diff --git a/moves.go b/moves.go new file mode 100644 index 0000000..8a47b6d --- /dev/null +++ b/moves.go @@ -0,0 +1,49 @@ +package pokeapi + +import ( + "fmt" + + "github.com/mtslzr/pokeapi-go/structs" +) + +// Move returns a single move (by name or ID). +func Move(id string) (result structs.Move, err error) { + err = do(fmt.Sprintf("move/%s", id), &result) + return result, err +} + +// MoveAilment returns a single move ailment (by name or ID). +func MoveAilment(id string) (result structs.MoveAilment, err error) { + err = do(fmt.Sprintf("move-ailment/%s", id), &result) + return result, err +} + +// MoveBattleStyle returns a single move battle style (by name or ID). +func MoveBattleStyle(id string) (result structs.MoveBattleStyle, err error) { + err = do(fmt.Sprintf("move-battle-style/%s", id), &result) + return result, err +} + +// MoveCategory returns a single move category (by name or ID). +func MoveCategory(id string) (result structs.MoveCategory, err error) { + err = do(fmt.Sprintf("move-category/%s", id), &result) + return result, err +} + +// MoveDamageClass returns a single move damage class (by name or ID). +func MoveDamageClass(id string) (result structs.MoveDamageClass, err error) { + err = do(fmt.Sprintf("move-damage-class/%s", id), &result) + return result, err +} + +// MoveLearnMethod returns a single move learn method (by name or ID). +func MoveLearnMethod(id string) (result structs.MoveLearnMethod, err error) { + err = do(fmt.Sprintf("move-learn-method/%s", id), &result) + return result, err +} + +// MoveTarget returns a single move target (by name or ID). +func MoveTarget(id string) (result structs.MoveTarget, err error) { + err = do(fmt.Sprintf("move-target/%s", id), &result) + return result, err +} diff --git a/pokemon.go b/pokemon.go index c4e5e20..75423f4 100644 --- a/pokemon.go +++ b/pokemon.go @@ -12,6 +12,12 @@ func Ability(id string) (result structs.Ability, err error) { return result, err } +// Characteristic returns a single characteristic (by ID). +func Characteristic(id string) (result structs.Characteristic, err error) { + err = do(fmt.Sprintf("characteristic/%s", id), &result) + return result, err +} + // EggGroup returns a single egg group (by name or ID). func EggGroup(id string) (result structs.EggGroup, err error) { err = do(fmt.Sprintf("egg-group/%s", id), &result) @@ -66,7 +72,13 @@ func PokemonHabitat(id string) (result structs.PokemonHabitat, err error) { return result, err } -// PokemonSpecies returns a single Pokemon species(by name or ID). +// PokemonShape returns a single Pokemon shape (by name or ID). +func PokemonShape(id string) (result structs.PokemonShape, err error) { + err = do(fmt.Sprintf("pokemon-shape/%s", id), &result) + return result, err +} + +// PokemonSpecies returns a single Pokemon species (by name or ID). func PokemonSpecies(id string) (result structs.PokemonSpecies, err error) { err = do(fmt.Sprintf("pokemon-species/%s", id), &result) return result, err diff --git a/structs/pokemon.go b/structs/pokemon.go index 700785d..7d220a2 100644 --- a/structs/pokemon.go +++ b/structs/pokemon.go @@ -58,6 +58,24 @@ type Ability struct { } `json:"pokemon"` } +// Characteristic is a single characteristic. +type Characteristic struct { + Descriptions []struct { + Description string `json:"description"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"descriptions"` + GeneModulo int `json:"gene_modulo"` + HighestStat struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"highest_stat"` + ID int `json:"id"` + PossibleValues []int `json:"possible_values"` +} + // EggGroup is a single egg group. type EggGroup struct { ID int `json:"id"` @@ -315,6 +333,30 @@ type PokemonHabitat struct { } `json:"pokemon_species"` } +// PokemonShape is a single Pokemon shape. +type PokemonShape struct { + AwesomeNames []struct { + AwesomeName string `json:"awesome_name"` + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + } `json:"awesome_names"` + ID int `json:"id"` + Name string `json:"name"` + Names []struct { + Language struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"language"` + Name string `json:"name"` + } `json:"names"` + PokemonSpecies []struct { + Name string `json:"name"` + URL string `json:"url"` + } `json:"pokemon_species"` +} + // PokemonSpecies is a single Pokemon species. type PokemonSpecies struct { BaseHappiness int `json:"base_happiness"` diff --git a/tests/items_test.go b/tests/items_test.go new file mode 100644 index 0000000..7618927 --- /dev/null +++ b/tests/items_test.go @@ -0,0 +1,98 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestItem(t *testing.T) { + result, _ := pokeapi.Item("1") + assert.Equal(t, "master-ball", result.Name, + "Expect to receive Master Ball.") +} + +func TestItemByName(t *testing.T) { + result, _ := pokeapi.Item("master-ball") + assert.Equal(t, "master-ball", result.Name, + "Expect to receive Master Ball.") +} + +func TestItemFail(t *testing.T) { + result, _ := pokeapi.Item("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestItemAttribute(t *testing.T) { + result, _ := pokeapi.ItemAttribute("1") + assert.Equal(t, "countable", result.Name, + "Expect to receive Countable.") +} + +func TestItemAttributeByName(t *testing.T) { + result, _ := pokeapi.ItemAttribute("countable") + assert.Equal(t, "countable", result.Name, + "Expect to receive Countable.") +} + +func TestItemAttributeFail(t *testing.T) { + result, _ := pokeapi.ItemAttribute("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestItemCategory(t *testing.T) { + result, _ := pokeapi.ItemCategory("1") + assert.Equal(t, "stat-boosts", result.Name, + "Expect to receive Stat Boosts.") +} + +func TestItemCategoryByName(t *testing.T) { + result, _ := pokeapi.ItemCategory("stat-boosts") + assert.Equal(t, "stat-boosts", result.Name, + "Expect to receive Stat Boosts.") +} + +func TestItemCategoryFail(t *testing.T) { + result, _ := pokeapi.Item("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestItemFlingEffect(t *testing.T) { + result, _ := pokeapi.ItemFlingEffect("1") + assert.Equal(t, "badly-poison", result.Name, + "Expect to receive Badly Poison.") +} + +func TestItemFlingEffectByName(t *testing.T) { + result, _ := pokeapi.ItemFlingEffect("badly-poison") + assert.Equal(t, "badly-poison", result.Name, + "Expect to receive Badly Poison.") +} + +func TestItemFlingEffectFail(t *testing.T) { + result, _ := pokeapi.ItemFlingEffect("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestItemPocket(t *testing.T) { + result, _ := pokeapi.ItemPocket("1") + assert.Equal(t, "misc", result.Name, + "Expect to receive Miscellaneous.") +} + +func TestItemPocketByName(t *testing.T) { + result, _ := pokeapi.ItemPocket("misc") + assert.Equal(t, "misc", result.Name, + "Expect to receive Miscellaneous.") +} + +func TestItemPocketFail(t *testing.T) { + result, _ := pokeapi.ItemPocket("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} diff --git a/tests/moves_test.go b/tests/moves_test.go new file mode 100644 index 0000000..515fafb --- /dev/null +++ b/tests/moves_test.go @@ -0,0 +1,134 @@ +package tests + +import ( + "testing" + + pokeapi "github.com/mtslzr/pokeapi-go" + "github.com/stretchr/testify/assert" +) + +func TestMove(t *testing.T) { + result, _ := pokeapi.Move("1") + assert.Equal(t, "pound", result.Name, + "Expect to receive Pound.") +} + +func TestMoveByName(t *testing.T) { + result, _ := pokeapi.Move("pound") + assert.Equal(t, "pound", result.Name, + "Expect to receive Pound.") +} + +func TestMoveFail(t *testing.T) { + result, _ := pokeapi.Move("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveAilment(t *testing.T) { + result, _ := pokeapi.MoveAilment("1") + assert.Equal(t, "paralysis", result.Name, + "Expect to receive Paralysis.") +} + +func TestMoveAilmentByName(t *testing.T) { + result, _ := pokeapi.MoveAilment("paralysis") + assert.Equal(t, "paralysis", result.Name, + "Expect to receive Paralysis.") +} + +func TestMoveAilmentFail(t *testing.T) { + result, _ := pokeapi.MoveAilment("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveBattleStyle(t *testing.T) { + result, _ := pokeapi.MoveBattleStyle("1") + assert.Equal(t, "attack", result.Name, + "Expect to receive Attack.") +} + +func TestMoveBattleStyleByName(t *testing.T) { + result, _ := pokeapi.MoveBattleStyle("attack") + assert.Equal(t, "attack", result.Name, + "Expect to receive Attack.") +} + +func TestMoveBattleStyleFail(t *testing.T) { + result, _ := pokeapi.MoveBattleStyle("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveCategory(t *testing.T) { + result, _ := pokeapi.MoveCategory("1") + assert.Equal(t, "ailment", result.Name, + "Expect to receive Ailment.") +} + +func TestMoveCategoryByName(t *testing.T) { + result, _ := pokeapi.MoveCategory("ailment") + assert.Equal(t, "ailment", result.Name, + "Expect to receive Ailment.") +} + +func TestMoveCategoryFail(t *testing.T) { + result, _ := pokeapi.MoveCategory("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveDamageClass(t *testing.T) { + result, _ := pokeapi.MoveDamageClass("1") + assert.Equal(t, "status", result.Name, + "Expect to receive Status.") +} + +func TestMoveDamageClassByName(t *testing.T) { + result, _ := pokeapi.MoveDamageClass("status") + assert.Equal(t, "status", result.Name, + "Expect to receive Status.") +} + +func TestMoveDamageClassFail(t *testing.T) { + result, _ := pokeapi.MoveDamageClass("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveLearnMethod(t *testing.T) { + result, _ := pokeapi.MoveLearnMethod("1") + assert.Equal(t, "level-up", result.Name, + "Expect to receive Level Up.") +} + +func TestMoveLearnMethodByName(t *testing.T) { + result, _ := pokeapi.MoveLearnMethod("level-up") + assert.Equal(t, "level-up", result.Name, + "Expect to receive Level Up.") +} + +func TestMoveLearnMethodFail(t *testing.T) { + result, _ := pokeapi.MoveLearnMethod("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + +func TestMoveTarget(t *testing.T) { + result, _ := pokeapi.MoveTarget("1") + assert.Equal(t, "specific-move", result.Name, + "Expect to receive Specific Move.") +} + +func TestMoveTargetByName(t *testing.T) { + result, _ := pokeapi.MoveTarget("specific-move") + assert.Equal(t, "specific-move", result.Name, + "Expect to receive Specific Move.") +} + +func TestMoveTargetFail(t *testing.T) { + result, _ := pokeapi.MoveTarget("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} diff --git a/tests/pokemon_test.go b/tests/pokemon_test.go index e847a37..cff0ae7 100644 --- a/tests/pokemon_test.go +++ b/tests/pokemon_test.go @@ -25,6 +25,18 @@ func TestAbilityFail(t *testing.T) { "Expect to receive an empty result.") } +func TestCharacteristic(t *testing.T) { + result, _ := pokeapi.Characteristic("1") + assert.Equal(t, "Loves to eat", result.Descriptions[1].Description, + "Expect to receive a description.") +} + +func TestCharacteristicFail(t *testing.T) { + result, _ := pokeapi.Characteristic("asdf") + assert.Equal(t, 0, len(result.Descriptions), + "Expect to receive an empty result.") +} + func TestEggGroup(t *testing.T) { result, _ := pokeapi.EggGroup("1") assert.Equal(t, "monster", result.Name, @@ -187,6 +199,24 @@ func TestPokemonHabitatFail(t *testing.T) { "Expect to receive an empty result.") } +func TestPokemonShape(t *testing.T) { + result, _ := pokeapi.PokemonShape("1") + assert.Equal(t, "ball", result.Name, + "Expect to receive Ball.") +} + +func TestPokemonShapeByName(t *testing.T) { + result, _ := pokeapi.PokemonShape("ball") + assert.Equal(t, "ball", result.Name, + "Expect to receive Ball.") +} + +func TestPokemonShapeFail(t *testing.T) { + result, _ := pokeapi.PokemonShape("asdf") + assert.Equal(t, "", result.Name, + "Expect to receive an empty result.") +} + func TestPokemonSpecies(t *testing.T) { result, _ := pokeapi.PokemonSpecies("1") assert.Equal(t, "bulbasaur", result.Name, From 6e5993cf97a8346a5d3892d6480829c4d7182544 Mon Sep 17 00:00:00 2001 From: Matthew Salazar Date: Sat, 22 Jun 2019 15:19:19 -0400 Subject: [PATCH 23/23] Added CHANGELOG; updated for 1.0.0 --- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..86d84ad --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,28 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +### Added +- Pagination for resource lists + +## [1.0.0] - 2019-06-22 +### Added +- Endpoint Categories + - Berries (berries, firmness, flavors) + - Contests (types, effects, etc.) + - Encounters (methods, conditions, etc.) + - Evolution (chains, triggers) + - Games (generations, versions, etc.) + - Locations (areas, regions, etc.) + - Machines + - Moves (moves, attributes, etc.) + - Pokemon (abilities, egg groups, etc.) + - Utility (languages) +- Resource endpoint for resource lists +- Unit tests for all endpoints + +[Unreleased]: https://github.com/mtslzr/pokeapi-go/compare/v1.0.0...HEAD +[1.0.0]: https://github.com/mtslzr/pokeapi-go/releases/tag/v1.0.0 \ No newline at end of file