Update package
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
import { IAbility } from '../interfaces/ability';
|
||||
|
||||
export class Ability implements IAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
type: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
import { IAttack } from '../interfaces/attack';
|
||||
|
||||
export class Attack implements IAttack {
|
||||
cost: string[];
|
||||
name: string;
|
||||
text: string;
|
||||
damage: string;
|
||||
convertedEnergyCost: string;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
17
src/classes/meta.ts
Normal file
17
src/classes/meta.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Client } from '../client';
|
||||
|
||||
export class Meta {
|
||||
constructor() {}
|
||||
|
||||
static allTypes(): Promise<string[]> {
|
||||
return Client.get('types');
|
||||
}
|
||||
|
||||
static allSubtypes(): Promise<string[]> {
|
||||
return Client.get('subtypes');
|
||||
}
|
||||
|
||||
static allSupertypes(): Promise<string[]> {
|
||||
return Client.get('supertypes');
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { ISet } from '../interfaces/set';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
import { IQuery } from '../interfaces/query';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
|
||||
export class Set implements ISet {
|
||||
code: string;
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import { IType } from '../interfaces/type';
|
||||
import { QueryBuilder } from '../queryBuilder';
|
||||
|
||||
export class Type implements IType {
|
||||
type: string;
|
||||
|
||||
constructor() {}
|
||||
|
||||
resource(): string {
|
||||
return 'types';
|
||||
}
|
||||
|
||||
static all(): Promise<Type[]> {
|
||||
return QueryBuilder.all(this)
|
||||
.then(response => {
|
||||
return response;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,6 @@
|
||||
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}`;
|
||||
|
||||
48
src/index.ts
48
src/index.ts
@ -1,27 +1,43 @@
|
||||
import { Card as BaseCard } from './classes/card';
|
||||
import { Ability as BaseAbility } from './classes/ability';
|
||||
import { Attack as BaseAttack } from './classes/attack';
|
||||
import { Meta as BaseMeta } from './classes/meta';
|
||||
import { Set as BaseSet } from './classes/set';
|
||||
import { Type as BaseType } from './classes/type';
|
||||
|
||||
export namespace PokemonTCG {
|
||||
export const Card = BaseCard;
|
||||
export type Card = BaseCard;
|
||||
|
||||
export const Meta = BaseMeta;
|
||||
export type Meta = BaseMeta;
|
||||
|
||||
export const Set = BaseSet;
|
||||
export type Set = BaseSet;
|
||||
|
||||
export interface IAbility {
|
||||
name: string;
|
||||
text: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface IAttack {
|
||||
convertedEnergyCost: string;
|
||||
cost: string[];
|
||||
damage: string;
|
||||
name: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface IQuery {
|
||||
name: string;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
export const Card = BaseCard;
|
||||
export type Card = BaseCard;
|
||||
export interface IResistance {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export const Ability = BaseAbility;
|
||||
export type Ability = BaseAbility;
|
||||
|
||||
export const Attack = BaseAttack;
|
||||
export type Attack = BaseAttack;
|
||||
|
||||
export const Set = BaseSet;
|
||||
export type Set = BaseSet;
|
||||
|
||||
export const Type = BaseType;
|
||||
export type Type = BaseType;
|
||||
export interface IWeakness {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export interface IType {
|
||||
type: string;
|
||||
}
|
||||
@ -1,24 +1,21 @@
|
||||
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 all<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T)): Promise<T[]> {
|
||||
static all<T extends Card | Set>(type: (new() => T)): Promise<T[]> {
|
||||
let t = new type();
|
||||
let params: IQuery[] = [{
|
||||
name: 'pageSize',
|
||||
value: 1000
|
||||
}];
|
||||
|
||||
return this.returnResponse(t.resource(), params);
|
||||
return this.returnResponse(t.resource(), params);
|
||||
}
|
||||
|
||||
static find<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T), id: string): Promise<T> {
|
||||
|
||||
static find<T extends Card | Set>(type: (new() => T), id: string): Promise<T> {
|
||||
let t = new type();
|
||||
let params: IQuery[] = [{
|
||||
name: 'id',
|
||||
@ -28,13 +25,13 @@ export class QueryBuilder {
|
||||
return this.returnResponse(t.resource(), params, true);
|
||||
}
|
||||
|
||||
static where<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T), params: IQuery[]): Promise<T[]> {
|
||||
static where<T extends Card | Set>(type: (new() => T), params: IQuery[]): Promise<T[]> {
|
||||
let t = new type();
|
||||
|
||||
|
||||
return this.returnResponse(t.resource(), params);
|
||||
}
|
||||
|
||||
private static returnResponse(resource: string, params: IQuery[], single?: boolean): Promise<any> {
|
||||
public static returnResponse(resource: string, params: IQuery[], single?: boolean): Promise<any> {
|
||||
return Client.get(resource, params)
|
||||
.then(response => {
|
||||
if (single) {
|
||||
|
||||
Reference in New Issue
Block a user