Compare commits

...

10 Commits

Author SHA1 Message Date
97acf4287f v1.7.0 2021-01-31 13:49:49 +01:00
7f0e95d574 Added the new Rarity v1.7.0
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-31 13:49:36 +01:00
b7d8fac835 v1.6.1
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-31 13:46:57 +01:00
d965aabad7 v1.6.1 2021-01-31 13:28:23 +01:00
e22d63d2ee Merge branch 'master' of github.com:tcgdex/javascript-sdk 2021-01-08 15:21:51 +01:00
5d2b836af6 Publish update
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:21:34 +01:00
dd7e252027 Remove console.warn
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:21:20 +01:00
c4fff9b370 Let the enduser handle not found errors
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:20:19 +01:00
610d2590e8 Update package.json 2021-01-08 11:54:41 +01:00
b180369514 1.5.1 - Because 1.5 already existed
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 11:44:51 +01:00
5 changed files with 43 additions and 32 deletions

View File

@ -23,7 +23,7 @@ export class Request<T = any> {
this.url = url
}
public async get(): Promise<T> {
public async get(): Promise<T | undefined> {
const now = new Date()
if (
this.fetched &&
@ -34,22 +34,17 @@ export class Request<T = any> {
}
// Fetch Response
try {
const resp = await fetch(this.url, {
headers: {
"Content-Type": "text/plain"
}
})
if (resp.status !== 200) {
throw new Error(`Error request ended with the code (${resp.status})`)
const resp = await fetch(this.url, {
headers: {
"Content-Type": "text/plain"
}
const response = await resp.json()
this.response = response
this.fetched = now
return response
} catch (e) {
console.error(e)
throw new Error('An error occured')
})
if (resp.status !== 200) {
return undefined
}
const response = await resp.json()
this.response = response
this.fetched = now
return response
}
}

View File

@ -25,7 +25,7 @@ export interface CardSingle {
low: string
high?: string
}
tags: Array<TagSimple>
tags?: Array<TagSimple>
illustrator?: IllustratorSimple
rarity: RaritySimple
category: CategorySimple
@ -89,7 +89,7 @@ type Card = {
evolveFrom?: LangList<string>
evolveTo?: Array<LangList<string>>
tags: Array<Tag> // made after
tags?: Array<Tag> // made after
illustrator?: string
abilities?: Array<Ability>

View File

@ -9,7 +9,9 @@ export enum Rarity {
// Both RAREULTRA and ULTRARARE are the same until I know the correct name
RAREULTRA = 4,
ULTRARARE = 4
ULTRARARE = 4,
AMAZING,
}

View File

@ -1,9 +1,9 @@
{
"name": "@tcgdex/sdk",
"version": "1.5.0",
"version": "1.7.0",
"main": "./tcgdex.js",
"types": "./tcgdex.d.ts",
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
"repository": "https://github.com/tcgdex/javascript-sdk.git",
"license": "MIT",
"devDependencies": {
"@types/node-fetch": "2.5.7",

View File

@ -25,53 +25,67 @@ export default class TCGdex {
return this.getBaseUrl()
}
public async getCard(id: string|number, set: string): Promise<CardSingle>;
public async getCard(id: string): Promise<CardSingle>;
public async getCard(id: string|number, set?: string): Promise<CardSingle> {
public async getCard(id: string|number, set: string): Promise<CardSingle | undefined>
public async getCard(id: string): Promise<CardSingle | undefined>
public async getCard(id: string|number, set?: string): Promise<CardSingle | undefined> {
const txt = set ? `sets/${set}` : "cards"
const req = this.rwgr<CardSingle>(`${this.gbu()}/${txt}/${id}/`)
return req.get()
}
public async getCards(set?: string): Promise<Array<CardSimple>> {
public async getCards(set?: string): Promise<Array<CardSimple> | undefined> {
if (set) {
const setSingle = await this.getSet(set)
if (!setSingle) {
return undefined
}
return setSingle.list
}
console.warn("note: while it's possible to fetch every cards at once it's not recommended as it take much more time than any other requests")
const req = this.rwgr<CardList>(`${this.gbu()}/cards/`)
const resp = await req.get()
if (!resp) {
return undefined
}
return resp.list
}
public async getSet(set: string, transformDate: false): Promise<SetSingleRaw>
public async getSet(set: string, transformDate?: true): Promise<SetSingle>
public async getSet(set: string, transformDate?: boolean): Promise<SetSingle | SetSingleRaw> {
public async getSet(set: string, transformDate: false): Promise<SetSingleRaw | undefined>
public async getSet(set: string, transformDate?: true): Promise<SetSingle | undefined>
public async getSet(set: string, transformDate?: boolean): Promise<SetSingle | SetSingleRaw | undefined> {
const req = this.rwgr<SetSingle>(`${this.gbu()}/sets/${set}/`)
const resp = await req.get()
if (!resp) {
return undefined
}
if (!transformDate) {
return resp as SetSingleRaw
}
return Object.assign(resp, {releaseDate: new Date(resp.releaseDate)}) as SetSingle
}
public async getExpansion(expansion: string): Promise<ExpansionSingle> {
public async getExpansion(expansion: string): Promise<ExpansionSingle | undefined> {
const req = this.rwgr<ExpansionSingle>(`${this.gbu()}/expansions/${expansion}/`)
return req.get()
}
public async getExpansions(): Promise<ExpansionList> {
public async getExpansions(): Promise<ExpansionList | undefined> {
const req = this.rwgr<ExpansionList>(`${this.gbu()}/expansions/`)
return req.get()
}
public async getSets(expansion?: string): Promise<Array<SetSimple>> {
public async getSets(expansion?: string): Promise<Array<SetSimple> | undefined> {
if (expansion) {
const expansionSingle = await this.getExpansion(expansion)
if (!expansionSingle) {
return undefined
}
return expansionSingle.sets
}
const req = this.rwgr<SetList>(`${this.gbu()}/sets/`)
const list = await req.get()
if (!list) {
return undefined
}
return list.list
}