diff --git a/README.md b/README.md new file mode 100644 index 0000000..85a0bbc --- /dev/null +++ b/README.md @@ -0,0 +1,121 @@ +# Pokemon TCG SDK TypeScript + +This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io). + +## Installation + +``` +npm install --save pokemon-tcg-sdk-typescript +``` + +## Class Definitions + +### Card + +```typescript +id: number; +name: string; +imageUrl: string; +imageUrlHighRes: string; +subType: ISubType; +superType: ISuperType; +ability: IAbility; +hp: number; +number: number; +artist: string; +rarity: string; +series: string; +set: ISet; +setCode: string; +retreatCost: string; +text: string; +types: IType[]; +attacks: IAttack[]; +weaknesses: string[]; +resistances: string[]; +nationalPokedexNumber: number; +ancientTrait: string; +evolvesFrom: string; +``` + +### Set + +```typescript +code: string; +name: string; +series: string; +totalCards: number; +standardLegal: boolean; +expandedLegal: boolean; +releaseDate: string; +symbolUrl: string; +ptcgoCode: string; +``` + +### Type, SubType, SuperType + +```typescript +type: string; +``` + +### IQuery + +```typescript +{ name: string, value: string | number } +``` + +## Method Definitions + +```typescript +Card.find(id: string): Promise +Card.where(params: IQuery[]): Promise +Card.all(): Promise + +Set.find(id: string): Promise +Set.where(params: IQuery[]): Promise +Set.all(): Promise + +Type.all(): Promise +SuperType.all(): Promise +SubType.all(): Promise +``` + +## Usage + +All of the calls return generic promises like `Promise` or `Promise`. The type is determined from the class making the call. The examples here are using the `Card` class but the usage for the other classes are the same. + +```typescript +import { Card, Set, Type, SuperType, SubType, IQuery } from 'pokemon-tcg-sdk-typescript' + +Card.find('xy1') + .then(card => { + // do stuff with the card + }) + .catch(error => { + // do something with the error + }); + +let params: IQuery[] = [{ name: 'name', value: 'Charizard' }]; +Card.where(params) + .then(cards => { + // do stuff with the cards + }) + .catch(error => { + // do something with the error + }); + +Card.all() + .then(cards => { + // do stuff with the cards + }) + .catch(error => { + // do something with the error + }); +``` + +## Contributing + * Fork it (click the Fork button at the top of the page) + * Create your feature branch (git checkout -b my-new-feature) + * Commit your changes (git commit -am 'Add some feature') + * Push to the branch (git push origin my-new-feature) + * Create a new Pull Request \ No newline at end of file diff --git a/src/classes/subType.ts b/src/classes/subType.ts index 6774d6a..68406c9 100644 --- a/src/classes/subType.ts +++ b/src/classes/subType.ts @@ -2,7 +2,7 @@ import { ISubType } from '../interfaces/subType'; import { QueryBuilder } from '../queryBuilder'; export class SubType implements ISubType { - types: string[]; + type: string; constructor() {} diff --git a/src/classes/superType.ts b/src/classes/superType.ts index d59097d..ba8af4b 100644 --- a/src/classes/superType.ts +++ b/src/classes/superType.ts @@ -2,7 +2,7 @@ import { ISuperType } from '../interfaces/superType'; import { QueryBuilder } from '../queryBuilder'; export class SuperType implements ISuperType { - types: string[]; + type: string; constructor () {} diff --git a/src/classes/type.ts b/src/classes/type.ts index 4938713..7c2d1f0 100644 --- a/src/classes/type.ts +++ b/src/classes/type.ts @@ -1,8 +1,8 @@ import { IType } from '../interfaces/type'; +import { QueryBuilder } from '../queryBuilder'; export class Type implements IType { type: string; - value: string; constructor() {} @@ -10,7 +10,10 @@ export class Type implements IType { return 'types'; } - all(): IType[] { - throw new Error("Method not implemented."); + static all(): Promise { + return QueryBuilder.all(this) + .then(response => { + return response; + }); } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index de2b224..5fa85e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,4 +2,5 @@ export { Card } from './classes/card'; export { Set } from './classes/set'; export { Type } from './classes/type'; export { SuperType } from './classes/superType'; -export { SubType } from './classes/subType'; \ No newline at end of file +export { SubType } from './classes/subType'; +export { IQuery } from './interfaces/query'; \ No newline at end of file diff --git a/src/interfaces/subType.ts b/src/interfaces/subType.ts index 955696d..658a891 100644 --- a/src/interfaces/subType.ts +++ b/src/interfaces/subType.ts @@ -1,3 +1,3 @@ export interface ISubType { - types: string[]; + type: string; } \ No newline at end of file diff --git a/src/interfaces/superType.ts b/src/interfaces/superType.ts index 487f58f..92ba927 100644 --- a/src/interfaces/superType.ts +++ b/src/interfaces/superType.ts @@ -1,3 +1,3 @@ export interface ISuperType { - types: string[]; + type: string; } \ No newline at end of file diff --git a/src/interfaces/type.ts b/src/interfaces/type.ts index f7d012d..5d94739 100644 --- a/src/interfaces/type.ts +++ b/src/interfaces/type.ts @@ -1,7 +1,3 @@ export interface IType { type: string; - value: string; - - resource(): string; - all(): IType[]; } \ No newline at end of file