Initial commit.

Classes and interfaces in place. The QueryBuilder generics are still a work in progress
This commit is contained in:
Bradyn Glines
2018-01-18 17:19:41 -07:00
commit 92c2dea62f
25 changed files with 371 additions and 0 deletions

34
src/client.ts Normal file
View 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;
}
}