class PokeAPI::Requester
Constants
- APIError
- API_ENDPOINT
- EVOLUTION_CHAIN_ENDPOINT
- NotFoundError
- POKEMON_ENDPOINT
- POKEMON_SPECIES_ENDPOINT
- TYPES_ENDPOINT
- TimeoutError
Public Class Methods
evolution_chain(id)
click to toggle source
# File lib/pokeapi/requester.rb, line 26 def evolution_chain(id) data = get("#{EVOLUTION_CHAIN_ENDPOINT}#{id}") Parser::EvolutionChain.parse(data) end
get(path)
click to toggle source
# File lib/pokeapi/requester.rb, line 36 def get(path) http = HTTP.get("#{API_ENDPOINT}#{path}/") fail NotFoundError if http.code == 404 fail TimeoutError if http.code == 504 fail APIError if http.code == 500 JSON.parse(http.to_s, symbolize_names: true) end
pokemon(id)
click to toggle source
# File lib/pokeapi/requester.rb, line 16 def pokemon(id) data = get("#{POKEMON_ENDPOINT}#{id}") Parser::Pokemon.parse(data) end
species(id)
click to toggle source
# File lib/pokeapi/requester.rb, line 21 def species(id) data = get("#{POKEMON_SPECIES_ENDPOINT}#{id}") Parser::Species.parse(data) end
type(id)
click to toggle source
# File lib/pokeapi/requester.rb, line 31 def type(id) data = get("#{TYPES_ENDPOINT}#{id}") Parser::Type.parse(data) end