From e8201df35fc0b797c048c328273a8037cc5255f0 Mon Sep 17 00:00:00 2001 From: Tee Date: Thu, 25 Feb 2021 22:09:07 -0500 Subject: [PATCH] Transfer API information to client for ownership --- src/client.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/client.ts b/src/client.ts index 6639dae..5f71332 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,14 +1,13 @@ import * as axios from 'axios'; -import { IQuery } from './interfaces/query'; - -const API_URL: string = 'https://api.pokemontcg.io'; -const API_VERSION: string = '1'; +import { Query } from './interfaces/query'; export class Client { - static apiUrl: string = `${API_URL}/v${API_VERSION}`; + private static readonly API_BASE_URL: string = 'https://api.pokemontcg.io'; + private static readonly API_VERSION: string = '2'; + private static readonly API_URL: string = `${Client.API_BASE_URL}/v${Client.API_VERSION}`; - static async get(resource: string, params?: IQuery[] | string): Promise { - let url: string = `${this.apiUrl}/${resource}`; + static async get(resource: string, params?: Query[] | string): Promise { + let url: string = `${this.API_URL}/${resource}`; const config: axios.AxiosRequestConfig = { headers: { 'Content-Type': 'application/json' @@ -25,11 +24,11 @@ export class Client { .catch(error => Promise.reject(error)); } - private static paramsToQuery(params?: IQuery[]): string { + private static paramsToQuery(params?: Query[]): string { let query: string = ''; if (params) { - params.map((q: IQuery) => { + params.map((q: Query) => { query += `${q.name}=${encodeURIComponent(q.value.toString())}`.concat('&'); }); }