diff --git a/tcgdex.ts b/tcgdex.ts index 5bc4379..ea2a87e 100644 --- a/tcgdex.ts +++ b/tcgdex.ts @@ -10,26 +10,18 @@ export default class TCGdex { return this.lang || TCGdex.defaultLang } - private getBaseUrl() { return `https://api.tcgdex.net/v2/${this.getLang()}` } - private gbu() { - return this.getBaseUrl() + public async fetchCard(id: string | number, set?: string): Promise { + const path = `/${set ? `sets/${set}` : 'cards'}/${id}/` + return this.rwgr(path).get() } - public async getCard(id: string|number, full: true, set?: string): Promise | undefined> - // @ts-expect-error Temporary while building it in the compiler - public async getCard(id: string|number, full?: boolean, set?: string): Promise { - const txt = set ? `sets/${set}` : "cards" - const req = this.rwgr(`${this.gbu()}/${txt}/${id}/`) - return req.get() - } - - public async getCards(set?: string): Promise | undefined> { + public async fetchCards(set?: string): Promise | undefined> { if (set) { - const setSingle = await this.getSet(set) + const setSingle = await this.fetchSet(set) if (!setSingle) { return undefined } @@ -43,7 +35,7 @@ export default class TCGdex { return resp } - public async getSet(set: string): Promise { + public async fetchSet(set: string): Promise { const req = this.rwgr(`/sets/${set}/`) const resp = await req.get() if (!resp) { @@ -52,19 +44,19 @@ export default class TCGdex { return resp } - public async getSerie(expansion: string): Promise { + public async fetchSerie(expansion: string): Promise { const req = this.rwgr(`/series/${expansion}/`) return req.get() } - public async getSeries(): Promise { + public async fetchSeries(): Promise { const req = this.rwgr(`/series/`) return req.get() } - public async getSets(expansion?: string): Promise { + public async fetchSets(expansion?: string): Promise { if (expansion) { - const expansionSingle = await this.getSerie(expansion) + const expansionSingle = await this.fetchSerie(expansion) if (!expansionSingle) { return undefined } @@ -79,6 +71,6 @@ export default class TCGdex { } private rwgr(url: string) { - return RequestWrapper.getRequest(`${this.gbu()}${url}`) + return RequestWrapper.getRequest(`${this.getBaseUrl()}${url}`) } }