Skip to content

Commit

Permalink
Ported over to Pokemon TCG API
Browse files Browse the repository at this point in the history
  • Loading branch information
adback03 committed Sep 11, 2016
1 parent 47850ce commit 64c7a5c
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 37 deletions.
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
In progress.
# Pokémon TCG SDK

[![pokemontcg-developers on discord](https://img.shields.io/badge/discord-pokemontcg--developers-738bd7.svg)](https://discord.gg/dpsTCvg)

This is the Pokémon TCG SDK SDK Javascript implementation. It is a wrapper around the Pokémon TCG SDK API of [pokemontcg.io](http://pokemontcg.io/).

## Installation

npm install --save pokemontcgsdk

## Usage

const pokemon = require('pokemontcgsdk')

pokemon.card.find('base1-4')
.then(result => {
console.log(result.card.name) // "Charizard"
})

Query cards by any property:

card.where({ supertype: 'pokemon', subtype: 'mega' })
.then(cards => {
console.log(cards[0].name) // "M Sceptile-EX"
})

Retrieve cards across multiple pages of results:

card.all({ name: 'blastoise', pageSize: 1 })
.on('data', card => {
console.log(card.name)
})

// Will print:
// Blastoise
// Blastoise-EX
// M Blastoise-EX
// ....

### Properties

#### Card

id
name
nationalPokedexNumber
imageUrl
subtype
supertype
ability
ancientTrait
hp
number
artist
rarity
series
set
setCode
retreatCost
text
types
attacks
weaknesses
resistances

#### Set

code
name
series
totalCards
standardLegal
releaseDate

### Development

- es6 ([babel](https://babeljs.io))
- [standardjs](http://standardjs.com)
- [promises](https://www.promisejs.org)

Build tasks are in npm scripts:

npm run build
npm run watch
npm run test
2 changes: 1 addition & 1 deletion lib/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/querybuilder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/querybuilder.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "mtgsdk",
"version": "0.1.1",
"description": "Magic: The Gathering SDK is a javascript wrapper around the MTG API located at magicthegathering.io",
"name": "pokemontcgsdk",
"version": "1.0.0",
"description": "Pokémon TCG SDK is a javascript wrapper around the Pokémon TCG API located at pokemontcg.io",
"author": {
"name": "Raine Revere",
"email": "raineorshine@gmail.com",
"url": "https://github.com/metaraine"
"name": "Andrew Backes",
"email": "backes.andrew@gmail.com",
"url": "https://github.com/PokemonTCG/pokemon-tcg-sdk-javascript"
},
"main": "./lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
endpoint: 'https://api.magicthegathering.io/v1'
endpoint: 'https://api.pokemontcg.io/v1'
}
2 changes: 1 addition & 1 deletion src/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = type => ({
}),

/** Gets a resource with a given query. */
where: get(type, 0),
where: get(type, 1),

/** Gets a resource with a given query (like where), but
returns an emitter that emits 3 events:
Expand Down
47 changes: 23 additions & 24 deletions test-src/test-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@ const { pipe, prop } = require('ramda')
describe('card', () => {
describe('find', () => {
it('returns card', () => {
return card.find(88803).then(pipe(prop('card'), card => {
card.should.have.property('name', 'Choice of Damnations')
card.should.have.property('manaCost', '{5}{B}')
card.should.have.property('cmc', 6)
card.should.have.property('type', 'Sorcery — Arcane')
card.should.have.deep.property('colors[0]', 'Black')
card.should.have.deep.property('types[0]', 'Sorcery')
card.should.have.deep.property('subtypes[0]', 'Arcane')
card.should.have.property('rarity', 'Rare')
card.should.have.property('set', 'SOK')
card.should.have.property('text', 'Target opponent chooses a number. You may have that player lose that much life. If you don\'t, that player sacrifices all but that many permanents.')
card.should.have.property('flavor', '"Life is a series of choices between bad and worse."\n—Toshiro Umezawa')
card.should.have.property('artist', 'Tim Hildebrandt')
card.should.have.property('number', '62')
card.should.have.property('multiverseid', 88803)
card.should.have.property('imageUrl', 'http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=88803&type=card')
card.should.have.property('originalText', 'Target opponent chooses a number. You may have that player lose that much life. If you don\'t, that player sacrifices all but that many permanents.')
card.should.have.property('originalType', 'Sorcery — Arcane')
card.should.have.property('id', '1c4aab072d52d283e902f2302afa255b39e0794b')
return card.find('xy7-57').then(pipe(prop('card'), card => {
card.should.have.property('id', 'xy7-57')
card.should.have.property('name', 'Giratina-EX')
card.should.have.property('nationalPokedexNumber', 487)
card.should.have.property('imageUrl', 'https://s3.amazonaws.com/pokemontcg/xy7/57.png')
card.should.have.property('subtype', 'EX')
card.should.have.property('supertype', 'Pokémon')
card.should.have.deep.property('ability.name', 'Renegade Pulse')
card.should.have.deep.property('ability.text', "Prevent all effects of attacks, including damage, done to this Pokémon by your opponent's Mega Evolution Pokémon.")
card.should.have.property('hp', '170')
card.should.have.deep.property('retreatCost[0]', 'Colorless')
card.should.have.property('number', '57')
card.should.have.property('artist', 'PLANETA')
card.should.have.property('rarity', 'Rare Holo EX')
card.should.have.property('series', 'XY')
card.should.have.property('set', 'Ancient Origins')
card.should.have.property('setCode', 'xy7')
card.should.have.deep.property('types[0]', 'Dragon')
}))
})
})

describe('where', () => {
it('should filter', () => {
return card.where({ supertypes: 'legendary', subtypes: 'goblin' })
return card.where({ set: 'steam siege' })
.should.eventually.be.an('array')
.with.deep.property('[0]')
.that.has.property('supertypes[0]', 'Legendary')
.that.has.property('set', 'Steam Siege')
})

it('should return 1 page of results', () => {
Expand All @@ -53,7 +52,7 @@ describe('card', () => {
})

it('should be able to control the page size', () => {
return card.where({ page: 1, pageSize: 1 })
return card.where({ page: 5, pageSize: 1 })
.should.eventually.be.an('array')
.that.has.length(1)
})
Expand All @@ -62,11 +61,11 @@ describe('card', () => {
describe('all', () => {
it('should emit results from multiple pages', (cb) => {
const results = []
const cardEmitter = card.all({ name: 'Squee', pageSize: 5 })
const cardEmitter = card.all({ name: 'Pikachu', pageSize: 5 })
cardEmitter.on('data', card => results.push(card))
cardEmitter.on('error', cb)
cardEmitter.on('end', () => {
results.should.have.length(9)
results.should.have.length.of.at.least(20)
cb()
})
})
Expand Down

0 comments on commit 64c7a5c

Please # to comment.