Merge pull request #1 from PokemonTCG/master
Add Initial v2 Data Structure Changes
This commit is contained in:
@ -13,7 +13,7 @@ describe('Client', () => {
|
||||
Client.get('cards', params)
|
||||
.then(response => {
|
||||
expect(response).to.be.a('array');
|
||||
expect(response[0].name).to.equal('Gardevoir');
|
||||
expect(response[0].name).to.equal('Ampharos');
|
||||
});
|
||||
});
|
||||
|
||||
@ -21,7 +21,7 @@ describe('Client', () => {
|
||||
Client.get('cards')
|
||||
.then(response => {
|
||||
expect(response).to.be.a('array');
|
||||
expect(response.length).to.equal(100);
|
||||
expect(response.length).to.equal(250);
|
||||
});
|
||||
});
|
||||
|
||||
@ -56,7 +56,7 @@ describe('Client', () => {
|
||||
.then(response => {
|
||||
expect(response).to.be.a('array');
|
||||
expect(response[0]).to.be.a('object');
|
||||
expect(response[0].code).to.equal('base1');
|
||||
expect(response[0].id).to.equal('base1');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -16,13 +16,8 @@ describe('QueryBuilder', () => {
|
||||
it('should use where to filter data', () => {
|
||||
const params: IQuery[] = [
|
||||
{
|
||||
name: 'name',
|
||||
value: 'Charizard'
|
||||
|
||||
},
|
||||
{
|
||||
name: 'setCode',
|
||||
value: 'base1'
|
||||
name: 'q',
|
||||
value: 'name:Charizard set.id:base1'
|
||||
}
|
||||
];
|
||||
|
||||
@ -30,14 +25,14 @@ describe('QueryBuilder', () => {
|
||||
.then(cards => {
|
||||
expect(cards.length).to.equal(1);
|
||||
expect(cards[0].id).to.equal('base1-4');
|
||||
expect(cards[0].set).to.equal('Base');
|
||||
expect(cards[0].set.name).to.equal('Base');
|
||||
});
|
||||
});
|
||||
|
||||
it('should use all to get all cards', () => {
|
||||
QueryBuilder.all<Card>(Card)
|
||||
.then(cards => {
|
||||
expect(cards.length).to.equal(1000);
|
||||
expect(cards.length).to.equal(250);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -2,13 +2,17 @@ import { IAbility } from '../interfaces/ability';
|
||||
import { IAncientTrait } from '../interfaces/ancientTrait';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { ICard } from '../interfaces/card';
|
||||
import { ICardImage } from '../interfaces/image';
|
||||
import { ILegality } from '../interfaces/legality';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { IResistance } from '../interfaces/resistance';
|
||||
import { ISet } from '../interfaces/set';
|
||||
import { ITCGPlayer } from '../interfaces/tcgplayer';
|
||||
import { IWeakness } from '../interfaces/weakness';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
|
||||
export class Card implements ICard {
|
||||
ability: IAbility;
|
||||
abilities: IAbility[];
|
||||
artist: string;
|
||||
ancientTrait?: IAncientTrait;
|
||||
attacks: IAttack[];
|
||||
@ -16,20 +20,19 @@ export class Card implements ICard {
|
||||
evolvesFrom: string;
|
||||
hp: string;
|
||||
id: string;
|
||||
imageUrl: string;
|
||||
imageUrlHiRes: string;
|
||||
images: ICardImage;
|
||||
legalities: ILegality;
|
||||
name: string;
|
||||
nationalPokedexNumber: number;
|
||||
nationalPokedexNumbers: number[];
|
||||
number: string;
|
||||
rarity: string;
|
||||
resistances: IResistance[];
|
||||
retreatCost: string[];
|
||||
series: string;
|
||||
set: string;
|
||||
setCode: string;
|
||||
subtype: string;
|
||||
rules: string[];
|
||||
set: ISet;
|
||||
subtypes: string[];
|
||||
supertype: string;
|
||||
text: string[];
|
||||
tcgplayer: ITCGPlayer | undefined;
|
||||
types: string[];
|
||||
weaknesses: IWeakness[];
|
||||
|
||||
|
||||
@ -12,4 +12,8 @@ export class Meta {
|
||||
static async allSupertypes(): Promise<string[]> {
|
||||
return Client.get('supertypes');
|
||||
}
|
||||
|
||||
static allRarities(): Promise<string[]> {
|
||||
return Client.get('rarities');
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,20 @@
|
||||
import { ISet } from '../interfaces/set';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
import { ILegality } from '../interfaces/legality';
|
||||
import { ISetImage } from '../interfaces/image';
|
||||
|
||||
export class Set implements ISet {
|
||||
code: string;
|
||||
expandedLegal: boolean;
|
||||
logoUrl: string;
|
||||
name: string;
|
||||
id: string;
|
||||
images: ISetImage;
|
||||
legalities: ILegality;
|
||||
name: string;
|
||||
printedTotal: number;
|
||||
ptcgoCode: string;
|
||||
releaseDate: string;
|
||||
series: string;
|
||||
standardLegal: boolean;
|
||||
symbolUrl: string;
|
||||
totalCards: number;
|
||||
series: string;
|
||||
total: number;
|
||||
updatedAt: string;
|
||||
updatedSince: string;
|
||||
|
||||
resource(): string {
|
||||
return 'sets';
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export interface IAttack {
|
||||
convertedEnergyCost: string;
|
||||
convertedEnergyCost: number;
|
||||
cost: string[];
|
||||
damage: string;
|
||||
name: string;
|
||||
|
||||
@ -3,30 +3,34 @@ import { IAncientTrait } from './ancientTrait';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { IResistance } from '../interfaces/resistance';
|
||||
import { IWeakness } from '../interfaces/weakness';
|
||||
import { ICardImage } from './image';
|
||||
import { ILegality } from './legality';
|
||||
import { ISet } from './set';
|
||||
import { ITCGPlayer } from './tcgplayer';
|
||||
|
||||
export interface ICard {
|
||||
ability: IAbility;
|
||||
ancientTrait?: IAncientTrait;
|
||||
abilities: IAbility[];
|
||||
artist: string;
|
||||
ancientTrait?: IAncientTrait;
|
||||
attacks: IAttack[];
|
||||
convertedRetreatCost: number;
|
||||
evolvesFrom: string;
|
||||
flavorText: string;
|
||||
hp: string;
|
||||
id: string;
|
||||
imageUrl: string;
|
||||
imageUrlHiRes: string;
|
||||
images: ICardImage;
|
||||
legalities: ILegality;
|
||||
name: string;
|
||||
nationalPokedexNumber: number;
|
||||
nationalPokedexNumbers: number[];
|
||||
number: string;
|
||||
rarity: string;
|
||||
resistances: IResistance[];
|
||||
retreatCost: string[];
|
||||
series: string;
|
||||
set: string;
|
||||
setCode: string;
|
||||
subtype: string;
|
||||
rules: string[];
|
||||
set: ISet;
|
||||
subtypes: string[];
|
||||
supertype: string;
|
||||
text: string[];
|
||||
tcgplayer: ITCGPlayer | undefined;
|
||||
types: string[];
|
||||
weaknesses: IWeakness[];
|
||||
}
|
||||
9
src/interfaces/image.ts
Normal file
9
src/interfaces/image.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export interface ISetImage {
|
||||
symbol: string;
|
||||
logo: string;
|
||||
}
|
||||
|
||||
export interface ICardImage {
|
||||
small: string;
|
||||
large: string;
|
||||
}
|
||||
10
src/interfaces/legality.ts
Normal file
10
src/interfaces/legality.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export enum Legality {
|
||||
LEGAL = 'Legal',
|
||||
BANNED = 'Banned',
|
||||
}
|
||||
|
||||
export interface ILegality {
|
||||
expanded: Legality | undefined
|
||||
standard: Legality | undefined
|
||||
unlimited: Legality | undefined
|
||||
}
|
||||
@ -1,14 +1,15 @@
|
||||
import { ISetImage } from "./image";
|
||||
import { ILegality } from "./legality";
|
||||
|
||||
export interface ISet {
|
||||
code: string;
|
||||
expandedLegal: boolean;
|
||||
logoUrl: string;
|
||||
name: string;
|
||||
id: string;
|
||||
images: ISetImage;
|
||||
legalities: ILegality;
|
||||
name: string;
|
||||
printedTotal: number;
|
||||
ptcgoCode: string;
|
||||
releaseDate: string;
|
||||
series: string;
|
||||
standardLegal: boolean;
|
||||
symbolUrl: string;
|
||||
totalCards: number;
|
||||
series: string;
|
||||
total: number;
|
||||
updatedAt: string;
|
||||
updatedSince: string;
|
||||
}
|
||||
17
src/interfaces/tcgplayer.ts
Normal file
17
src/interfaces/tcgplayer.ts
Normal file
@ -0,0 +1,17 @@
|
||||
export interface ITCGPlayer {
|
||||
url: string;
|
||||
updatedAt: string;
|
||||
prices: {
|
||||
normal: IPrice | undefined;
|
||||
holofoil: IPrice | undefined;
|
||||
reverseHolofoil: IPrice | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPrice {
|
||||
low: number | null
|
||||
mid: number | null
|
||||
high: number | null
|
||||
market: number | null
|
||||
directLow: number | null
|
||||
}
|
||||
@ -8,7 +8,7 @@ export class QueryBuilder {
|
||||
const t = new type();
|
||||
const params: IQuery[] = [{
|
||||
name: 'pageSize',
|
||||
value: 1000
|
||||
value: 250,
|
||||
}];
|
||||
|
||||
return Client.get(t.resource(), params);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Constants
|
||||
export const API_URL: string = 'https://api.pokemontcg.io';
|
||||
export const API_VERSION: string = '1';
|
||||
export const API_VERSION: string = '2';
|
||||
|
||||
// Classes
|
||||
export * from './classes/card';
|
||||
|
||||
Reference in New Issue
Block a user