Initial commit.
Classes and interfaces in place. The QueryBuilder generics are still a work in progress
This commit is contained in:
9
src/classes/ability.ts
Normal file
9
src/classes/ability.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
|
||||
export class Ability implements IAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
type: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
8
src/classes/ancientAbility.ts
Normal file
8
src/classes/ancientAbility.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { IAncientAbility } from '../interfaces/ancientAbility';
|
||||
|
||||
export class AncientAbility implements IAncientAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
11
src/classes/attack.ts
Normal file
11
src/classes/attack.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
|
||||
export class Attack implements IAttack {
|
||||
cost: string;
|
||||
name: string;
|
||||
text: string;
|
||||
damage: string;
|
||||
convertedEnergyCost: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
52
src/classes/card.ts
Normal file
52
src/classes/card.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { ICard } from '../interfaces/card';
|
||||
import { ISubType } from '../interfaces/subType';
|
||||
import { ISuperType } from '../interfaces/superType';
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
import { ISet } from '../interfaces/set';
|
||||
import { IType } from '../interfaces/type';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
|
||||
export class Card implements ICard {
|
||||
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;
|
||||
|
||||
constructor() {}
|
||||
|
||||
static resource(): string {
|
||||
return 'cards';
|
||||
}
|
||||
|
||||
find(id: string): Card {
|
||||
return QueryBuilder.find<Card>(id);
|
||||
}
|
||||
|
||||
all(): ICard[] {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
where(args: object): ICard {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
32
src/classes/set.ts
Normal file
32
src/classes/set.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { ISet } from '../interfaces/set';
|
||||
|
||||
export class Set implements ISet {
|
||||
code: string;
|
||||
name: string;
|
||||
series: string;
|
||||
totalCards: number;
|
||||
standardLegal: boolean;
|
||||
expandedLegal: boolean;
|
||||
releaseDate: string;
|
||||
symbolUrl: string;
|
||||
ptcgoCode: string;
|
||||
|
||||
constructor() {}
|
||||
|
||||
resource(): string {
|
||||
return "sets";
|
||||
}
|
||||
|
||||
find(id: number): ISet {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
all(): ISet[] {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
where(args: object): ISet {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
14
src/classes/subType.ts
Normal file
14
src/classes/subType.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { ISubType } from '../interfaces/subType';
|
||||
|
||||
export class SubType implements ISubType {
|
||||
constructor() {}
|
||||
|
||||
resource(): string {
|
||||
return 'subtypes';
|
||||
}
|
||||
|
||||
all(): ISubType[] {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
13
src/classes/superType.ts
Normal file
13
src/classes/superType.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { ISuperType } from '../interfaces/superType';
|
||||
|
||||
export class SuperType implements ISuperType {
|
||||
constructor () {}
|
||||
|
||||
resource(): string {
|
||||
return 'supertypes';
|
||||
}
|
||||
|
||||
all(): ISuperType[] {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
16
src/classes/type.ts
Normal file
16
src/classes/type.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { IType } from '../interfaces/type';
|
||||
|
||||
export class Type implements IType {
|
||||
type: string;
|
||||
value: string;
|
||||
|
||||
constructor() {}
|
||||
|
||||
resource(): string {
|
||||
return 'types';
|
||||
}
|
||||
|
||||
all(): IType[] {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
34
src/client.ts
Normal file
34
src/client.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import * as axios from 'axios';
|
||||
import { PokemonTCG } from './sdk';
|
||||
import { IQuery } from './interfaces/query';
|
||||
import { ICard } from './interfaces/card';
|
||||
import { IType } from './interfaces/type';
|
||||
import { ISuperType } from './interfaces/superType';
|
||||
import { ISubType } from './interfaces/subType';
|
||||
import { ISet } from './interfaces/set';
|
||||
|
||||
export class Client {
|
||||
static apiUrl: string = `${PokemonTCG.API_URL}/v${PokemonTCG.version}`;
|
||||
|
||||
static get(resource: string, params?: IQuery[]): axios.AxiosPromise<any> {
|
||||
let config: axios.AxiosRequestConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
return axios.default.get<any>(`${Client.apiUrl}/${resource}?${Client.paramsToQuery(params)}`, config);
|
||||
}
|
||||
|
||||
private static paramsToQuery(params?: IQuery[]): string {
|
||||
let query: string = '';
|
||||
|
||||
if (params !== null) {
|
||||
params.map((q: IQuery) => {
|
||||
query += `${q.name}=${encodeURI(q.value)}`.concat('&');
|
||||
});
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
5
src/interfaces/ability.ts
Normal file
5
src/interfaces/ability.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface IAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
type: string;
|
||||
}
|
||||
4
src/interfaces/ancientAbility.ts
Normal file
4
src/interfaces/ancientAbility.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface IAncientAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
}
|
||||
7
src/interfaces/attack.ts
Normal file
7
src/interfaces/attack.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface IAttack {
|
||||
cost: string;
|
||||
name: string;
|
||||
text: string;
|
||||
damage: string;
|
||||
convertedEnergyCost: string;
|
||||
}
|
||||
37
src/interfaces/card.ts
Normal file
37
src/interfaces/card.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
import { ISet } from '../interfaces/set';
|
||||
import { ISubType } from '../interfaces/subType';
|
||||
import { ISuperType } from '../interfaces/superType';
|
||||
import { IType } from '../interfaces/type';
|
||||
|
||||
export interface ICard {
|
||||
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;
|
||||
|
||||
resource(): string;
|
||||
find(id: number): ICard;
|
||||
all(): ICard[];
|
||||
where(args: object): ICard;
|
||||
}
|
||||
4
src/interfaces/query.ts
Normal file
4
src/interfaces/query.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface IQuery {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
16
src/interfaces/set.ts
Normal file
16
src/interfaces/set.ts
Normal file
@ -0,0 +1,16 @@
|
||||
export interface ISet {
|
||||
code: string;
|
||||
name: string;
|
||||
series: string;
|
||||
totalCards: number;
|
||||
standardLegal: boolean;
|
||||
expandedLegal: boolean;
|
||||
releaseDate: string;
|
||||
symbolUrl: string;
|
||||
ptcgoCode: string;
|
||||
|
||||
resource(): string;
|
||||
find(id: number): ISet;
|
||||
all(): ISet[];
|
||||
where(args: object): ISet;
|
||||
}
|
||||
4
src/interfaces/subType.ts
Normal file
4
src/interfaces/subType.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface ISubType {
|
||||
resource(): string;
|
||||
all(): ISubType[];
|
||||
}
|
||||
4
src/interfaces/superType.ts
Normal file
4
src/interfaces/superType.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface ISuperType {
|
||||
resource(): string;
|
||||
all(): ISuperType[];
|
||||
}
|
||||
7
src/interfaces/type.ts
Normal file
7
src/interfaces/type.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface IType {
|
||||
type: string;
|
||||
value: string;
|
||||
|
||||
resource(): string;
|
||||
all(): IType[];
|
||||
}
|
||||
1
src/playground/index.ts
Normal file
1
src/playground/index.ts
Normal file
@ -0,0 +1 @@
|
||||
import {}
|
||||
14
src/queryBuilder.ts
Normal file
14
src/queryBuilder.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Client } from './client';
|
||||
import { Card } from "./classes/card";
|
||||
import { Set } from "./classes/set";
|
||||
import { Type } from "./classes/type";
|
||||
import { SubType } from "./classes/subType";
|
||||
import { SuperType } from "./classes/superType";
|
||||
import { IQuery } from './interfaces/query';
|
||||
import { AxiosResponse } from 'axios';
|
||||
|
||||
export class QueryBuilder {
|
||||
static find<T>(type: (new() => T), id: string): T {
|
||||
Client.get(type.resource())
|
||||
}
|
||||
}
|
||||
4
src/sdk.ts
Normal file
4
src/sdk.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export namespace PokemonTCG {
|
||||
export const API_URL: string = 'https://api.pokemontcg.io';
|
||||
export const version: string = '1';
|
||||
}
|
||||
Reference in New Issue
Block a user