Compare commits
95 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa62e1b6ee | |||
| 4b4d4cb901 | |||
| aca7f28a93 | |||
| 0bdd1f0def | |||
| e0afb2932a | |||
| 2d7b47efd4 | |||
| f077348af4 | |||
| 21d94dd997 | |||
| c5d48dba11 | |||
| 4d442f2d81 | |||
| ed55ddc434 | |||
| 9d40a50d80 | |||
| eedad4f043 | |||
| 47861f3760 | |||
| 3624938ade | |||
| 82ca4b6626 | |||
| 76fa13fa12 | |||
| 3b3b65e7d0 | |||
| fd3df49bc8 | |||
| 9443263499 | |||
| 0ef85368c8 | |||
| 5755c744a3 | |||
| de16add8d1 | |||
| 315f8cbef3 | |||
| 8a3b2a0b7a | |||
| 66965487a7 | |||
| 523201535d | |||
| 904c92bb9b | |||
| 0e4698f2a1 | |||
| 417cced318 | |||
| b0a744fd58 | |||
| 1033ad9dc2 | |||
| 1bcdd1d990 | |||
| 619ec93332 | |||
| 517ee0ff53 | |||
| 6f1c4958b1 | |||
| eb01211d09 | |||
| bfc4ad92b9 | |||
| 71266cf726 | |||
| 11c0c9041f | |||
| decba63848 | |||
| da9f106165 | |||
| 6c034d399f | |||
| de37e0ef40 | |||
| 4e87f38bc5 | |||
| 1492b96a23 | |||
| 5435e233e9 | |||
| 32e6de135e | |||
| 735d428dc2 | |||
| ed16e6e937 | |||
| 33116796dd | |||
| 1ab1add58a | |||
| 8c75754623 | |||
| d9fcb2ed55 | |||
| f86810201d | |||
| bfa0502a1e | |||
| fcbf7849ff | |||
| c00754f7df | |||
| daf61a0f9c | |||
| ba2ce6e79b | |||
| f47353849a | |||
| 9992fc99eb | |||
| 54c42b7654 | |||
| b6d387e7a5 | |||
| 2bf257de45 | |||
| 4238438adb | |||
| 0d00d4f984 | |||
| 979a6367b8 | |||
| b12e306c73 | |||
| 320d62dd41 | |||
| e7d36cc5a1 | |||
| fb33ea3617 | |||
| aa4179d523 | |||
| 7f71588138 | |||
| 537a236b42 | |||
| e588d35dd9 | |||
| 5f19f8227e | |||
| a7afa92184 | |||
| 2f186599dd | |||
| f30b2313fe | |||
| 4006272f4d | |||
| 43c1987a83 | |||
| e8201df35f | |||
| 363bcfd321 | |||
| 657605eaa0 | |||
| 669e6db54c | |||
| ade8606e8f | |||
| 424a32af9c | |||
| 9d5905a33f | |||
| 74055255e3 | |||
| 239b18bcd3 | |||
| cec9ea8c5e | |||
| 9b6acd5b9a | |||
| 25e1972242 | |||
| 668c6740e7 |
157
MIGRATING.md
Normal file
157
MIGRATING.md
Normal file
@ -0,0 +1,157 @@
|
||||
# Migrating from v1 to v2
|
||||
|
||||
The functions and typings in V2 the SDK have been re-named to improve developer experience.
|
||||
The guide will provide you with the steps to help you migrate your application.
|
||||
|
||||
## Type Changes
|
||||
Interfaces are no longer prefixed with the letter `I`. **Interfaces in the TypeScript compile are used solely for type-checking purposes.**
|
||||
Originally, `ICard` and `ISet` existed to be implemented with the `Card` and `Set` classes respectively. Because each function is now an independently exported function,
|
||||
the TypeScript interfaces can be used as intended, which is to simply describe the shape of the data from the API:
|
||||
|
||||
`IQuery` was also changed to `Parameter` to complement the [new parameter syntax](https://docs.pokemontcg.io/#api_v2cards_list) in V2 of the API.
|
||||
|
||||
* `ICard` -> `Card`
|
||||
* `ISet` -> `Set`
|
||||
* `IAbility` -> `Ability`
|
||||
* `IResistance` -> `Resistance`
|
||||
* `IWeakness` -> `Weakness`
|
||||
* `IAttack` -> `Attack`
|
||||
* `IQuery` -> `Parameter`
|
||||
|
||||
## Function Changes
|
||||
The API functions are no longer abstracted in classes. Instead, each function is an individual export which still returns
|
||||
data of type `Card` or `Set` to reduce redundancy in the SDK. The function names were renamed to reveal intent as clearly as possible. This results
|
||||
in code that is self documenting, and enforces a convention where the API functionality is described
|
||||
thoroughly for developers.
|
||||
|
||||
There is no change in the function return types, nor underlying functionality. Functions will continue to return a generic promised based on the resource (i.e. `Promise<Card>`, `Promise<Set>`).
|
||||
|
||||
It is recommended to refactor the function names with the find-and-replace tool in your IDE or text editor in order for your project
|
||||
to be compatible with V2 of the SDK.
|
||||
|
||||
## Card Functions
|
||||
### `PokemonTCG.Card.all()` -> `PokemonTCG.getAllCards()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Card.all();
|
||||
|
||||
// V2
|
||||
PokemonTCG.getAllCards();
|
||||
```
|
||||
|
||||
### `PokemonTCG.Card.find()` -> `PokemonTCG.findCardByID()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Card.find('xy7-54').then((card: PokemonTCG.Card) => {
|
||||
console.log(card.name) // Gardevoir
|
||||
});
|
||||
|
||||
// V2
|
||||
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
|
||||
console.log(card.name) // Gardevoir
|
||||
});
|
||||
```
|
||||
|
||||
### `PokemonTCG.Card.where()` -> `PokemonTCG.findCardsByQueries()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value: 'Gardevoir' }];
|
||||
|
||||
PokemonTCG.Card.where(paramsV1).then((cards: PokemonTCG.Card[]) => {
|
||||
console.log(card[0].name) // Gardevoir
|
||||
});
|
||||
|
||||
// V2
|
||||
const paramsV2: PokemonTCG.Parameter[] = { q: 'id:xy7-54' };
|
||||
|
||||
PokemonTCG.findCardsByQueries(paramsV2).then((cards: PokemonTCG.Card[]) => {
|
||||
console.log(card[0].name) // Gardevoir
|
||||
});
|
||||
```
|
||||
## Set Functions
|
||||
### `PokemonTCG.Set.all()` -> `PokemonTCG.getAllSets()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Set.all();
|
||||
|
||||
// V2
|
||||
PokemonTCG.getAllSets();
|
||||
```
|
||||
### `PokemonTCG.Set.find()` -> `PokemonTCG.findSetByID()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Set.find('base1').then((set: PokemonTCG.Set) => {
|
||||
console.log(set.name) // Base
|
||||
});
|
||||
|
||||
// V2
|
||||
PokemonTCG.findSetByID('base1').then((set: PokemonTCG.Set) => {
|
||||
console.log(set.name) // Base
|
||||
});
|
||||
```
|
||||
|
||||
### `PokemonTCG.Set.where()` -> `PokemonTCG.findSetsByQueries()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value:'Base' }];
|
||||
|
||||
PokemonTCG.Set.where(paramsV1).then((sets: PokemonTCG.Set[]) => {
|
||||
console.log(sets[0].name) // Base
|
||||
});
|
||||
|
||||
// V2
|
||||
const paramsV2: PokemonTCG.Parameter[] = { q: 'name:Base' };
|
||||
|
||||
PokemonTCG.findSetsByQueries(paramsV2).then((sets: PokemonTCG.Set[]) => {
|
||||
console.log(sets[0].name) // Base
|
||||
});
|
||||
```
|
||||
|
||||
## Meta Functions
|
||||
|
||||
### `PokemonTCG.Meta.allTypes()` -> `PokemonTCG.getTypes()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Meta.getAllTypes();
|
||||
|
||||
// V2
|
||||
PokemonTCG.getTypes();
|
||||
```
|
||||
|
||||
### `PokemonTCG.Meta.allSupertypes()` -> `PokemonTCG.getSupertypes()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Meta.allSupertypes();
|
||||
|
||||
// V2
|
||||
PokemonTCG.getSupertypes();
|
||||
```
|
||||
|
||||
### `PokemonTCG.Meta.allSubtypes()` -> `PokemonTCG.getSubtypes()`
|
||||
```typescript
|
||||
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
|
||||
|
||||
// V1
|
||||
PokemonTCG.Meta.allSubtypes();
|
||||
|
||||
// V2
|
||||
PokemonTCG.getSubtypes();
|
||||
```
|
||||
|
||||
|
||||
77
README.md
77
README.md
@ -2,6 +2,9 @@
|
||||
|
||||
This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io).
|
||||
|
||||
# V2 Announcement
|
||||
Version 1 of this SDK is officially depricated. Version 2 stable release this SDK is scheduled to be released on **Friday, April 3rd, 20201**. Version 1 will continue to receive support until then. **See the [migration guide](MIGRATING.md) for steps to update your app to use the latest supported version of the SDK**
|
||||
|
||||
## Installation
|
||||
|
||||
**npm**
|
||||
@ -12,35 +15,40 @@ This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io).
|
||||
|
||||
yarn add pokemon-tcg-sdk-typescript
|
||||
|
||||
It is recommended to use an API key for version 2 of the API. By default, requests are limited to 20,000/day. Requests are rate limited to 1000 requests a day, and a maximum of 30 per minute.
|
||||
|
||||
To use the SDK with an API key, create an account at https://dev.pokemontcg.io to grab an API key. Then set your API key to the environment variable POKEMONTCG_API_KEY in a .env file. Make sure to use this exact environment variable, otherwise the SDK will not be able to read the API key.
|
||||
|
||||
## Class Definitions
|
||||
|
||||
### Card
|
||||
|
||||
```typescript
|
||||
ability: IAbility;
|
||||
ancientTrait?: IAncientTrait;
|
||||
artist: string;
|
||||
attacks: IAttack[];
|
||||
convertedRetreatCost: number;
|
||||
evolvesFrom: string;
|
||||
hp: string;
|
||||
id: string;
|
||||
imageUrl: string;
|
||||
imageUrlHiRes: string;
|
||||
name: string;
|
||||
nationalPokedexNumber: number;
|
||||
number: string;
|
||||
rarity: string;
|
||||
resistances: IResistance[];
|
||||
retreatCost: string[];
|
||||
series: string;
|
||||
set: string;
|
||||
setCode: string;
|
||||
subtype: string;
|
||||
supertype: string;
|
||||
text: string[];
|
||||
types: string[];
|
||||
weaknesses: IWeakness[];
|
||||
id: string;
|
||||
name: string;
|
||||
supertype: string;
|
||||
subtypes: string[];
|
||||
hp?: string;
|
||||
types?: string[];
|
||||
evolesFrom?: string;
|
||||
evolvesTo?: string[];
|
||||
rules?: string[];
|
||||
ancientTrait?: IAncientTrait;
|
||||
abilities?: IAbility[];
|
||||
attacks?: IAttack[];
|
||||
weaknesses?: IWeakness[];
|
||||
resistances?: IResistance[];
|
||||
retreatCost?: string[];
|
||||
convertedRetreatCost?: number;
|
||||
set: ISet;
|
||||
number: string;
|
||||
artist?: string;
|
||||
rarity: string;
|
||||
flavorText?: string;
|
||||
nationalPokedexNumbers?: number[];
|
||||
legalities: ILegality;
|
||||
images: ICardImage;
|
||||
tcgplayer?: ITCGPlayer;
|
||||
```
|
||||
|
||||
### IAbility
|
||||
@ -71,17 +79,16 @@ value: string;
|
||||
### Set
|
||||
|
||||
```typescript
|
||||
code: string;
|
||||
expandedLegal: boolean;
|
||||
logoUrl: string;
|
||||
name: string;
|
||||
ptcgoCode: string;
|
||||
releaseDate: string;
|
||||
series: string;
|
||||
standardLegal: boolean;
|
||||
symbolUrl: string;
|
||||
totalCards: number;
|
||||
updatedAt: string;
|
||||
id: string;
|
||||
images: ISetImage;
|
||||
legalities: ILegality;
|
||||
name: string;
|
||||
printedTotal: number;
|
||||
ptcgoCode: string;
|
||||
releaseDate: string;
|
||||
series: string;
|
||||
total: number;
|
||||
updatedAt: string;
|
||||
```
|
||||
|
||||
### IQuery
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as chai from 'chai';
|
||||
import { Client } from '../client';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { Client } from '../src/client';
|
||||
import { IQuery } from '../src/interfaces/query';
|
||||
|
||||
const expect = chai.expect;
|
||||
describe('Client', () => {
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as chai from 'chai';
|
||||
import { Card } from '../classes/card';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { Card } from '../src/classes/card';
|
||||
import { QueryBuilder } from '../src/queryBuilder';
|
||||
import { IQuery } from '../src/interfaces/query';
|
||||
|
||||
const expect = chai.expect;
|
||||
describe('QueryBuilder', () => {
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
1531
package-lock.json
generated
1531
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pokemon-tcg-sdk-typescript",
|
||||
"version": "1.2.5",
|
||||
"version": "1.3.1",
|
||||
"description": "Typescript SDK for the PokemonTCG API (https://pokemontcg.io)",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@ -11,7 +11,7 @@
|
||||
"SDK"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec --require ts-node/register 'src/**/*.test.ts'",
|
||||
"test": "mocha --reporter spec --require ts-node/register 'coverage/**/*.test.ts'",
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": {
|
||||
@ -26,14 +26,15 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^0.19.0",
|
||||
"typescript": "^2.6.2"
|
||||
"axios": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.1",
|
||||
"@types/mocha": "^2.2.46",
|
||||
"@types/node": "^14.14.35",
|
||||
"chai": "^4.1.2",
|
||||
"mocha": "^8.2.1",
|
||||
"ts-node": "^4.1.0"
|
||||
"ts-node": "^4.1.0",
|
||||
"typescript": "4.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,63 +1,77 @@
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
import { IAncientTrait } from '../interfaces/ancientTrait';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { ICard } from '../interfaces/card';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { IResistance } from '../interfaces/resistance';
|
||||
import { IWeakness } from '../interfaces/weakness';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
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;
|
||||
artist: string;
|
||||
ancientTrait?: IAncientTrait;
|
||||
attacks: IAttack[];
|
||||
convertedRetreatCost: number;
|
||||
evolvesFrom: string;
|
||||
hp: string;
|
||||
id: string;
|
||||
imageUrl: string;
|
||||
imageUrlHiRes: string;
|
||||
name: string;
|
||||
nationalPokedexNumber: number;
|
||||
number: string;
|
||||
rarity: string;
|
||||
resistances: IResistance[];
|
||||
retreatCost: string[];
|
||||
series: string;
|
||||
set: string;
|
||||
setCode: string;
|
||||
subtype: string;
|
||||
supertype: string;
|
||||
text: string[];
|
||||
types: string[];
|
||||
weaknesses: IWeakness[];
|
||||
subtypes: string[];
|
||||
hp?: string;
|
||||
types?: string[];
|
||||
evolesFrom?: string;
|
||||
evolvesTo?: string[];
|
||||
rules?: string[];
|
||||
ancientTrait?: IAncientTrait;
|
||||
abilities?: IAbility[];
|
||||
attacks?: IAttack[];
|
||||
weaknesses?: IWeakness[];
|
||||
resistances?: IResistance[];
|
||||
retreatCost?: string[];
|
||||
convertedRetreatCost?: number;
|
||||
set: ISet;
|
||||
number: string;
|
||||
artist?: string;
|
||||
rarity: string;
|
||||
flavorText?: string;
|
||||
nationalPokedexNumbers?: number[];
|
||||
legalities: ILegality;
|
||||
images: ICardImage;
|
||||
tcgplayer?: ITCGPlayer;
|
||||
|
||||
resource(): string {
|
||||
return 'cards';
|
||||
return "cards";
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Card.find` is renamed to `findCardById` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async find(id: string): Promise<Card> {
|
||||
return QueryBuilder.find(this, id)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
return response;
|
||||
})
|
||||
.catch(error => Promise.reject(error));
|
||||
.catch((error) => Promise.reject(error));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Card.all` is renamed to `getAllCards` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async all(): Promise<Card[]> {
|
||||
return QueryBuilder.all(this)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
return response;
|
||||
})
|
||||
.catch(error => Promise.reject(error));
|
||||
.catch((error) => Promise.reject(error));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Card.where` is renamed to `findCardsByQueries` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async where(params: IQuery[]): Promise<Card[]> {
|
||||
return QueryBuilder.where(this, params)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
return response;
|
||||
})
|
||||
.catch(error => Promise.reject(error));
|
||||
.catch((error) => Promise.reject(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,35 @@
|
||||
import { Client } from '../client';
|
||||
|
||||
export class Meta {
|
||||
/**
|
||||
* @deprecated `allTypes` is renamed to `getAllTypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async allTypes(): Promise<string[]> {
|
||||
return Client.get('types');
|
||||
const resposne = await Client.get('types');
|
||||
return resposne;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `allSubtypes` is renamed to `getAllSubtypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async allSubtypes(): Promise<string[]> {
|
||||
return Client.get('subtypes');
|
||||
const response = await Client.get('subtypes');
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `allSupertypes` is renamed to `getAllSupertypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async allSupertypes(): Promise<string[]> {
|
||||
return Client.get('supertypes');
|
||||
const response = await Client.get('supertypes');
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `allRarities` is renamed to `getAllRarities` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async allRarities(): Promise<string[]> {
|
||||
const response = await Client.get('rarities');
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,28 @@
|
||||
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;
|
||||
|
||||
resource(): string {
|
||||
return 'sets';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Set.find` is renamed to `findSetById` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async find(id: string): Promise<Set> {
|
||||
return QueryBuilder.find(this, id)
|
||||
.then(response => {
|
||||
@ -27,6 +31,9 @@ export class Set implements ISet {
|
||||
.catch(error => Promise.reject(error));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Set.all` is renamed to `getAllSets` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async all(): Promise<Set[]> {
|
||||
return QueryBuilder.all(this)
|
||||
.then(response => {
|
||||
@ -35,6 +42,9 @@ export class Set implements ISet {
|
||||
.catch(error => Promise.reject(error));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated `Set.where` is renamed to `findSetsByQueries` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
|
||||
*/
|
||||
static async where(params: IQuery[]): Promise<Set[]> {
|
||||
return QueryBuilder.where(this, params)
|
||||
.then(response => {
|
||||
@ -42,4 +52,4 @@ export class Set implements ISet {
|
||||
})
|
||||
.catch(error => Promise.reject(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,12 +7,17 @@ export class Client {
|
||||
|
||||
static async get(resource: string, params?: IQuery[] | string): Promise<any> {
|
||||
let url: string = `${this.apiUrl}/${resource}`;
|
||||
const POKEMONTCG_API_KEY = process.env.POKEMONTCG_API_KEY;
|
||||
const config: axios.AxiosRequestConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
if (POKEMONTCG_API_KEY) {
|
||||
config.headers['X-Api-Key'] = POKEMONTCG_API_KEY;
|
||||
}
|
||||
|
||||
if(typeof params === 'string') url += `/${params}`;
|
||||
else url += `?${this.paramsToQuery(params)}`;
|
||||
|
||||
@ -34,4 +39,4 @@ export class Client {
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export interface IAttack {
|
||||
convertedEnergyCost: string;
|
||||
convertedEnergyCost: number;
|
||||
cost: string[];
|
||||
damage: string;
|
||||
name: string;
|
||||
|
||||
@ -1,32 +1,37 @@
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
import { IAncientTrait } from './ancientTrait';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { IResistance } from '../interfaces/resistance';
|
||||
import { IWeakness } from '../interfaces/weakness';
|
||||
import { IAbility } from "../interfaces/ability";
|
||||
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;
|
||||
artist: string;
|
||||
attacks: IAttack[];
|
||||
convertedRetreatCost: number;
|
||||
evolvesFrom: string;
|
||||
hp: string;
|
||||
id: string;
|
||||
imageUrl: string;
|
||||
imageUrlHiRes: string;
|
||||
name: string;
|
||||
nationalPokedexNumber: number;
|
||||
number: string;
|
||||
rarity: string;
|
||||
resistances: IResistance[];
|
||||
retreatCost: string[];
|
||||
series: string;
|
||||
set: string;
|
||||
setCode: string;
|
||||
subtype: string;
|
||||
supertype: string;
|
||||
text: string[];
|
||||
types: string[];
|
||||
weaknesses: IWeakness[];
|
||||
}
|
||||
subtypes: string[];
|
||||
hp?: string;
|
||||
types?: string[];
|
||||
evolesFrom?: string;
|
||||
evolvesTo?: string[];
|
||||
rules?: string[];
|
||||
ancientTrait?: IAncientTrait;
|
||||
abilities?: IAbility[];
|
||||
attacks?: IAttack[];
|
||||
weaknesses?: IWeakness[];
|
||||
resistances?: IResistance[];
|
||||
retreatCost?: string[];
|
||||
convertedRetreatCost?: number;
|
||||
set: ISet;
|
||||
number: string;
|
||||
artist?: string;
|
||||
rarity: string;
|
||||
flavorText?: string;
|
||||
nationalPokedexNumbers?: number[];
|
||||
legalities: ILegality;
|
||||
images: ICardImage;
|
||||
tcgplayer?: ITCGPlayer;
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
@ -6,9 +6,13 @@
|
||||
"outDir": "./dist",
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"lib": ["ES2015"]
|
||||
"lib": ["ES6"]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"coverage"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user