1.0.7 • Published 10 years ago

pkmn v1.0.7

Weekly downloads
12
License
MIT
Repository
github
Last release
10 years ago

pkmn NPM version Build Status Dependency Status Coverage percentage

pokeapi.co wrapper. Details about the api can be found here: http://pokeapi.co/docs/

Install

$ npm install --save pkmn

Usage

var Pkmn = require('pkmn');
var p = new Pkmn();

Get

All methods return a bluebird promise.

.get requires two arguments, a resource and an id. id can be a string, number, or array.

p.get('pokemon', 'meowth')
    .then(pokemon => /* do something */)
    .catch(err => /* handle error */);
    
p.get('pokemon', [1, 'mew'])
    .then(console.log) // logs [{name: 'Bulbasaur' ...}, {name: 'Mew'...}]

Errors and responses from the pokeapi that are not of status code 200 will be rejected.

p.get('pokemon', 'Vegeta')
    .catch(console.error) // logs [Error] 404

Too few arguments to .get also throws an error. All resources except pokedex require an id argument to passed to .get with them.

p.get('pokemon')
    .then(console.log)    // doesn't log
    .catch(console.error) // logs [Error] id argument required
    
p.get('pokedex')
    .then(console.log) // logs the pokedex

The full list of valid resources is:

pokedex, pokemon, egg, type, description, move, ability, sprite, game

Additionally, .get can take a resource_id as an argument. This is useful because most responses from pokeapi will have have a resource_id field. For example, a pokemon will come with a list of moves, each move contains a resource_id that you can pass directly to .get to retrieve the details of that move.

p.get('/api/v1/pokemon/bulbasaur')
// ...

Convenience Methods

All valid resource argumets to .get also have convenience methods:

p.pokemon([33, 'snorlax', 209])
p.ability(56)
p.egg(2)
p.pokedex()

// etc...

The full list of api resources can obtained from the api via .api

p.api()

License

MIT © Stephan Tabor

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago