Compare commits

...

10 Commits
1.0.8 ... 1.3.0

Author SHA1 Message Date
624337467b v1.3.0 2020-03-18 09:54:05 +01:00
eb96cb971c v1.2.1 2020-03-14 20:08:22 +01:00
9902888304 Fix datas not in interface
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-14 20:08:00 +01:00
2f1a293e3d v1.2.0 2020-03-14 20:00:43 +01:00
04d13bd450 Updated DB to add items
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-14 19:56:59 +01:00
a886302e05 v1.2.0-beta.1 2020-03-11 23:08:33 +01:00
75bc7249f1 Updated DB
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-11 23:05:27 +01:00
00316364fa fix error
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-11 21:59:31 +01:00
3cdc149845 Add new functions
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-11 21:57:40 +01:00
d0088d62cb Fix translation not getting the correct file
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-11 11:45:20 +01:00
5 changed files with 120 additions and 13 deletions

View File

@ -14,7 +14,7 @@ export default class TranslationUtil {
public static translate(master: "tag",a: Tag, lang: Langs): string|undefined;
public static translate(master: "type",a: Type, lang: Langs): string|undefined;
public static translate(master: possibilities,a: number, lang: Langs): string|undefined {
const trans = require(`./${master}`).default as translations
const trans = require(`./translations/${master}`).default as translations
const tmp = trans[lang]
if (!tmp) return
return tmp[a]

View File

@ -11,6 +11,7 @@ import Set from "./Set";
export interface CardSimple {
id: string
localId: string|number
name: string
image: string
}
@ -32,11 +33,43 @@ export interface CardSingle {
name: string
code: string
}
/**
* Some Pokémons have item like a berry
*/
item?: {
name: string
effect: string
}
cardTypes?: {
normal: boolean
reverse: boolean
holo: boolean
firstEd: boolean
/**
* normal card without anything special
*
*
* @type {boolean} consider `undefined` to true
*/
normal?: boolean
/**
* Card which has a holographic background
* but not the picture
*
* @type {boolean} `undefined` === `true`
*/
reverse?: boolean
/**
* Card which has a hologaphic picture
*
* @type {boolean} `undefined` === `false`
*/
holo?: boolean
/**
* Card which can have a `1st ed` icon
*
* only the base expansion should received it
*
* @type {boolean} `undefined` === `false`
*/
firstEd?: boolean
}
// Pokémon only
@ -95,6 +128,11 @@ type Card = {
// If card is trainer or energy effect is here
effect?: LangList<string>
item?: {
name: LangList<string>
effect: LangList<string>
}
weaknesses?: Array<{
type: Type
value?: string

View File

@ -36,6 +36,8 @@ export type SetSingle = {
export type SetSimple = {
code: string
name: string
logo?: string
symbol?: string
total: number
}

View File

@ -1,8 +1,8 @@
{
"name": "@tcgdex/sdk",
"version": "1.0.8",
"version": "1.3.0",
"main": "./tcgdex.js",
"types": "./types/tcgdex.d.ts",
"types": "./tcgdex.d.ts",
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
"license": "MIT",
"devDependencies": {

View File

@ -1,8 +1,8 @@
import fetch from 'isomorphic-unfetch'
import { Langs } from './interfaces/Langs'
import { SetSingle, SetRequest } from './interfaces/Set'
import { CardSingle } from './interfaces/Card'
import { ExpansionSingle } from './interfaces/Expansion'
import { SetSingle, SetRequest, SetSimple, SetList } from './interfaces/Set'
import { CardSingle, CardList, CardSimple } from './interfaces/Card'
import { ExpansionSingle, ExpansionList } from './interfaces/Expansion'
export default class TCGdex {
public lang: Langs = "en"
@ -24,7 +24,7 @@ export default class TCGdex {
public async getCard(id: string|number, set?: string): Promise<CardSingle> {
try {
const txt = set ? `sets/${set}` : "cards"
const resp = await fetch(`${this.gbu()}/${txt}/${id}`)
const resp = await fetch(`${this.gbu()}/${txt}/${id}/`)
if (resp.status !== 200) throw new Error("Card not found")
try {
return await resp.json()
@ -36,9 +36,35 @@ export default class TCGdex {
}
}
public async getCards(set?: string): Promise<Array<CardSimple>> {
if (set) {
try {
const setSingle = await this.getSet(set)
return setSingle.list
} catch (e) {
throw e
}
}
try {
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 resp = await fetch(`${this.gbu()}/cards/`)
if (resp.status !== 200) {
throw new Error("Could not fetch cards")
}
try {
const t: CardList = await resp.json()
return t.list
} catch (e) {
throw e
}
} catch (e) {
throw e
}
}
public async getSet(set: string): Promise<SetSingle> {
try {
const resp = await fetch(`${this.gbu()}/sets/${set}`)
const resp = await fetch(`${this.gbu()}/sets/${set}/`)
console.log(resp.status)
if (resp.status !== 200) throw new Error("Set not found")
try {
@ -54,7 +80,7 @@ export default class TCGdex {
public async getExpansion(expansion: string): Promise<ExpansionSingle> {
try {
const resp = await fetch(`${this.gbu()}/expansions/${expansion}`)
const resp = await fetch(`${this.gbu()}/expansions/${expansion}/`)
if (resp.status !== 200) throw new Error("Expansion not found")
try {
return await resp.json()
@ -65,4 +91,45 @@ export default class TCGdex {
throw e
}
}
public async getExpansions(): Promise<ExpansionList> {
try {
const resp = await fetch(`${this.gbu()}/expansions/`)
if (resp.status !== 200) throw new Error("Could not fetch expansions")
try {
return await resp.json()
} catch (e) {
throw e
}
} catch (e) {
throw e
}
}
public async getSets(expansion?: string): Promise<Array<SetSimple>> {
if (expansion) {
try {
const expansionSingle = await this.getExpansion(expansion)
return expansionSingle.sets
} catch (e) {
throw e
}
} else {
try {
const resp = await fetch(`${this.gbu()}/sets/`)
if (resp.status !== 200) {
throw new Error("Could not fetch sets")
}
try {
const sets: SetList = await resp.json()
return sets.list
} catch (e) {
throw e
}
} catch (e) {
throw e
}
}
}
}