Skip to content

Instantly share code, notes, and snippets.

@zgababa
Created January 18, 2017 18:08
Show Gist options
  • Save zgababa/a0513250caa3b3a66891ee3c21fff070 to your computer and use it in GitHub Desktop.
Save zgababa/a0513250caa3b3a66891ee3c21fff070 to your computer and use it in GitHub Desktop.
'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