Skip to content

Commit

Permalink
Created Resource (removed Pokemons/Generations), added structs for al…
Browse files Browse the repository at this point in the history
…l endpoints
  • Loading branch information
mtslzr committed Jun 22, 2019
1 parent 29021af commit cbe83e1
Show file tree
Hide file tree
Showing 18 changed files with 1,314 additions and 65 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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}/
Expand Down Expand Up @@ -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).
9 changes: 0 additions & 9 deletions games.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions structs/berries.go
Original file line number Diff line number Diff line change
@@ -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"`
}
57 changes: 57 additions & 0 deletions structs/contests.go
Original file line number Diff line number Diff line change
@@ -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"`
}
49 changes: 49 additions & 0 deletions structs/encounters.go
Original file line number Diff line number Diff line change
@@ -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"`
}
93 changes: 93 additions & 0 deletions structs/evolution.go
Original file line number Diff line number Diff line change
@@ -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"`
}
Loading

0 comments on commit cbe83e1

Please sign in to comment.