Created
January 18, 2017 18:08
-
-
Save zgababa/a0513250caa3b3a66891ee3c21fff070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const request = require('request-promise'); | |
const path = require('path'); | |
const Promise = require('bluebird'); | |
const BASE_PATH = 'http://pokeapi.co/api/v2/'; | |
function getPokemon(id) { | |
return request({ | |
uri : BASE_PATH + path.join('pokemon-form', id.toString()), | |
json : true | |
}); | |
} | |
function getPokemons() { | |
return request({ | |
uri : BASE_PATH + path.join('pokemon-form'), | |
json : true | |
}).then((pokemons) => { | |
const pokemonUrls = pokemons.results.map((pokemon) => request(pokemon.url)); | |
return Promise.all(pokemonUrls); | |
}).then((pokemons) => pokemons.map((pokemon) => JSON.parse(pokemon))); | |
} | |
module.exports = { | |
getPokemon, | |
getPokemons | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment