Class: PokeAPI::Requester
- Inherits:
-
Object
- Object
- PokeAPI::Requester
- Defined in:
- lib/pokeapi/requester.rb
Constant Summary collapse
- NotFoundError =
Class.new(StandardError)
- API_ENDPOINT =
"https://pokeapi.co/api/v2/"- POKEMON_ENDPOINT =
"pokemon/"
Class Method Summary collapse
Class Method Details
.get(path) ⇒ Object
15 16 17 18 19 |
# File 'lib/pokeapi/requester.rb', line 15 def get(path) http = HTTP.get("#{API_ENDPOINT}#{path}/") fail NotFoundError if http.code == 404 JSON.parse(http.to_s, symbolize_names: true) end |
.pokemon(id) ⇒ Object
11 12 13 |
# File 'lib/pokeapi/requester.rb', line 11 def pokemon(id) get("#{POKEMON_ENDPOINT}#{id}") end |