forked from TCGdex/java-sdk
feat: Full rework to support both Kotlin and Java and make it work like the Other SDKs (#2)
This commit is contained in:
28
src/main/kotlin/net/tcgdex/sdk/Extension.kt
Normal file
28
src/main/kotlin/net/tcgdex/sdk/Extension.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package net.tcgdex.sdk
|
||||
|
||||
/**
|
||||
* The different extension an image is available in
|
||||
*/
|
||||
enum class Extension(
|
||||
|
||||
/**
|
||||
* the string representation of the extension
|
||||
*/
|
||||
val value: String
|
||||
) {
|
||||
|
||||
/**
|
||||
* .png image, with transparent background
|
||||
*/
|
||||
PNG("png"),
|
||||
|
||||
/**
|
||||
* .jpg image, with white background
|
||||
*/
|
||||
JPG("jpg"),
|
||||
|
||||
/**
|
||||
* .webp image, with transparent background
|
||||
*/
|
||||
WEBP("webp")
|
||||
}
|
24
src/main/kotlin/net/tcgdex/sdk/Quality.kt
Normal file
24
src/main/kotlin/net/tcgdex/sdk/Quality.kt
Normal file
@ -0,0 +1,24 @@
|
||||
package net.tcgdex.sdk
|
||||
|
||||
/**
|
||||
* Image quality if applicable
|
||||
* (only cards does have quality selector)
|
||||
*/
|
||||
enum class Quality(
|
||||
|
||||
/**
|
||||
* the string representation of the quality
|
||||
*/
|
||||
val value: String
|
||||
) {
|
||||
|
||||
/**
|
||||
* A High quality image
|
||||
*/
|
||||
HIGH("high"),
|
||||
|
||||
/**
|
||||
* A Low quality image
|
||||
*/
|
||||
LOW("low")
|
||||
}
|
355
src/main/kotlin/net/tcgdex/sdk/TCGdex.kt
Normal file
355
src/main/kotlin/net/tcgdex/sdk/TCGdex.kt
Normal file
@ -0,0 +1,355 @@
|
||||
package net.tcgdex.sdk
|
||||
|
||||
import net.tcgdex.sdk.models.Card
|
||||
import net.tcgdex.sdk.models.CardResume
|
||||
import net.tcgdex.sdk.models.Serie
|
||||
import net.tcgdex.sdk.models.SerieResume
|
||||
import net.tcgdex.sdk.models.Set
|
||||
import net.tcgdex.sdk.models.SetResume
|
||||
import net.tcgdex.sdk.models.StringEndpoint
|
||||
|
||||
/**
|
||||
* The main TCGdex SDK instance
|
||||
*
|
||||
* @constructor Create the TCGdex Instance in the specific language
|
||||
*/
|
||||
class TCGdex(
|
||||
/**
|
||||
* the language you want to use, values: [en,fr,es,de,pt,it]
|
||||
*/
|
||||
var language: String
|
||||
) {
|
||||
|
||||
/**
|
||||
* The API Endpoint you want to use
|
||||
*/
|
||||
var URI = "https://api.tcgdex.net/v2"
|
||||
|
||||
/**
|
||||
* Fetch every Pokémon cards
|
||||
*
|
||||
* _note: take some time as there is around 13k-15k cards depending on the language_
|
||||
*
|
||||
* @return the list of Pokémon Cards
|
||||
*/
|
||||
fun fetchCards(): Array<CardResume>? {
|
||||
return this.fetch(Array<CardResume>::class.java, "cards")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific card
|
||||
*
|
||||
* @param card the card ID
|
||||
* @return The card
|
||||
*/
|
||||
fun fetchCard(cardId: String): Card? {
|
||||
return this.fetch(Card::class.java, "cards", cardId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific card by its set and local IDs
|
||||
*
|
||||
* @param setId the set ID/name
|
||||
* @param cardId the card local ID
|
||||
* @return the card you want
|
||||
*/
|
||||
fun fetchCard(setId: String, cardId: String): Card? {
|
||||
return this.fetch(Card::class.java, "sets", setId, cardId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch every pokémon TCG Sets
|
||||
*
|
||||
* @return the list of Pokémon TCG sets
|
||||
*/
|
||||
fun fetchSets(): Array<SetResume>? {
|
||||
return this.fetch(Array<SetResume>::class.java, "sets")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific set
|
||||
*
|
||||
* @param set the set you want to fetch (you can use the Set ID or name)
|
||||
* @return The set you searched
|
||||
*/
|
||||
fun fetchSet(set: String): Set? {
|
||||
return this.fetch(Set::class.java, "sets", set)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch every pokémon TCG Series
|
||||
*
|
||||
* @return the list of Pokémon TCG Series
|
||||
*/
|
||||
fun fetchSeries(): Array<SerieResume>? {
|
||||
return this.fetch(Array<SerieResume>::class.java, "series")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific serie
|
||||
*
|
||||
* @param serie the serie you want to fetch (you can use the Serie ID or name)
|
||||
* @return The serie you searched
|
||||
*/
|
||||
fun fetchSerie(serie: String): Serie? {
|
||||
return this.fetch(Serie::class.java, "series", serie)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey variants it is possible to have
|
||||
*
|
||||
* @return the list of evey variants it is possible to have
|
||||
*/
|
||||
fun fetchVariants(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "variants")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by variant
|
||||
*
|
||||
* @param variant the variant you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified variant
|
||||
*/
|
||||
fun fetchVariant(variant: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "variants", variant)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey Trainer Types it is possible to have
|
||||
*
|
||||
* @return the list of evey Trainer Types it is possible to have
|
||||
*/
|
||||
fun fetchTrainerTypes(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "trainer-types")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by trainer type
|
||||
*
|
||||
* @param type the trainer type you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified trainer type
|
||||
*/
|
||||
fun fetchTrainerType(type: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "trainer-types", type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey suffixes it is possible to have
|
||||
*
|
||||
* @return the list of evey suffixes it is possible to have
|
||||
*/
|
||||
fun fetchSuffixes(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "suffixes")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by suffix
|
||||
*
|
||||
* @param suffix the suffix you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified suffix
|
||||
*/
|
||||
fun fetchSuffix(suffix: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "suffixes", suffix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey stages it is possible to have
|
||||
*
|
||||
* @return the list of evey stages it is possible to have
|
||||
*/
|
||||
fun fetchStages(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "stages")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by stage
|
||||
*
|
||||
* @param stage the stage you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified stage
|
||||
*/
|
||||
fun fetchStage(stage: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "stages", stage)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey Regulation Marks it is possible to have
|
||||
*
|
||||
* @return the list of evey Regulation Marks it is possible to have
|
||||
*/
|
||||
fun fetchRegulationMarks(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "regulation-marks")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by regulation mark
|
||||
*
|
||||
* @param regulationMark the regulation mark you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified regulation mark
|
||||
*/
|
||||
fun fetchRegulationMark(regulationMark: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "regulation-marks", regulationMark)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey Energy Types it is possible to have
|
||||
*
|
||||
* @return the list of evey Energy Types it is possible to have
|
||||
*/
|
||||
fun fetchEnergyTypes(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "energy-types")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by Energy type
|
||||
*
|
||||
* @param energyType the Energy type you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified Energy type
|
||||
*/
|
||||
fun fetchEnergyType(energyType: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "energy-types", energyType)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey Pokédex IDS it is possible to have
|
||||
*
|
||||
* @return the list of evey Pokédex IDS it is possible to have
|
||||
*/
|
||||
fun fetchDexIds(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "dex-ids")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by pokédex ID
|
||||
*
|
||||
* @param dexId the pokédex ID you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified pokédex ID
|
||||
*/
|
||||
fun fetchDexId(dexId: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "dex-ids", dexId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey types it is possible to have
|
||||
*
|
||||
* @return the list of evey types it is possible to have
|
||||
*/
|
||||
fun fetchTypes(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "types")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by type
|
||||
*
|
||||
* @param type the type you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified type
|
||||
*/
|
||||
fun fetchType(type: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "types", type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey categories it is possible to have
|
||||
*
|
||||
* @return the list of evey categories it is possible to have
|
||||
*/
|
||||
fun fetchCategories(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "categories")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by category
|
||||
*
|
||||
* @param category the category you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified category
|
||||
*/
|
||||
fun fetchCategory(category: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "categories", category)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch evey retreat count it is possible to have
|
||||
*
|
||||
* @return the list of evey retreat count it is possible to have
|
||||
*/
|
||||
fun fetchRetreats(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "retreats")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by retreat
|
||||
*
|
||||
* @param retreat the retreat count you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified retreat count
|
||||
*/
|
||||
fun fetchRetreat(retreat: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "retreats", retreat)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch every Card rarities you can have (in your language)
|
||||
*
|
||||
* @return the list of Card rarities you can have (in your language)
|
||||
*/
|
||||
fun fetchRarities(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "rarities")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by rarity
|
||||
*
|
||||
* @param rarity the rarity you want to filter by (language specific)
|
||||
* @return a StringEndpoint containing the cards with the specified rarity
|
||||
*/
|
||||
fun fetchRarity(rarity: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "rarities", rarity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch every cards illustrators
|
||||
*
|
||||
* @return the list of ilustrators
|
||||
*/
|
||||
fun fetchIllustrators(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "illustrators")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by illustrator
|
||||
*
|
||||
* @param illustrator the illustrator you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified illustrator
|
||||
*/
|
||||
fun fetchIllustrator(illustrator: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "illustrators", illustrator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the list of possible value the HP field can take
|
||||
*
|
||||
* @return the list of possible value the HP field can take
|
||||
*/
|
||||
fun fetchHPs(): Array<String>? {
|
||||
return this.fetch(Array<String>::class.java, "hp")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cards by hp
|
||||
*
|
||||
* @param hp the hp count you want to filter by
|
||||
* @return a StringEndpoint containing the cards with the specified hp count
|
||||
*/
|
||||
fun fetchHP(hp: String): StringEndpoint? {
|
||||
return this.fetch(StringEndpoint::class.java, "hp", hp)
|
||||
}
|
||||
|
||||
private fun <T> fetch(cls: Class<T>, vararg path: String): T? {
|
||||
return Utils.fetch(this, "$URI/$language/${
|
||||
path.joinToString("/") {
|
||||
it.replace(
|
||||
" ",
|
||||
"%20"
|
||||
)
|
||||
}
|
||||
}", cls)
|
||||
}
|
||||
}
|
81
src/main/kotlin/net/tcgdex/sdk/Utils.kt
Normal file
81
src/main/kotlin/net/tcgdex/sdk/Utils.kt
Normal file
@ -0,0 +1,81 @@
|
||||
package net.tcgdex.sdk
|
||||
|
||||
import com.google.gson.Gson
|
||||
import net.tcgdex.sdk.internal.CacheEntry
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
import java.time.LocalDateTime
|
||||
import javax.imageio.ImageIO
|
||||
|
||||
object Utils {
|
||||
/**
|
||||
* Request Time to Live
|
||||
* in minutes
|
||||
*/
|
||||
var ttl: Long = 60
|
||||
|
||||
/**
|
||||
* requests cache
|
||||
*/
|
||||
private val cache: HashMap<String, CacheEntry<String>> = HashMap()
|
||||
|
||||
private val gson = Gson()
|
||||
|
||||
/**
|
||||
* fetch from the API
|
||||
*
|
||||
* @param tcgdex the TCGdex instance to link with it
|
||||
* @param url the url to fetch from
|
||||
* @param cls the Class to build the response into
|
||||
*
|
||||
* @return an initialized cls or null
|
||||
*/
|
||||
fun <T> fetch(tcgdex: TCGdex, url: String, cls: Class<T>): T? {
|
||||
var entry = this.cache[url]
|
||||
val now = LocalDateTime.now().minusMinutes(ttl)
|
||||
if (entry == null || entry.time.isBefore(now)) {
|
||||
val req = URL(url).openConnection()
|
||||
req.setRequestProperty("user-agent", "@tcgdex/java-sdk")
|
||||
|
||||
val br = BufferedReader(InputStreamReader(req.getInputStream()));
|
||||
var txt = ""
|
||||
var line = br.readLine()
|
||||
while (line != null)
|
||||
{
|
||||
txt += line
|
||||
line = br.readLine()
|
||||
}
|
||||
|
||||
entry = CacheEntry(txt)
|
||||
|
||||
this.cache[url] = entry
|
||||
}
|
||||
|
||||
try {
|
||||
val model = gson.fromJson<T>(
|
||||
entry.value, cls
|
||||
)
|
||||
if (model is Model) {
|
||||
model.tcgdex = tcgdex
|
||||
}
|
||||
return model
|
||||
} catch (e: IOException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download an image from the internet
|
||||
*
|
||||
* @param path the url to the image
|
||||
*
|
||||
* @return the download image buffer
|
||||
*/
|
||||
fun downloadImage(path: String): BufferedImage {
|
||||
return ImageIO.read(URL(path))
|
||||
}
|
||||
}
|
8
src/main/kotlin/net/tcgdex/sdk/internal/CacheEntry.kt
Normal file
8
src/main/kotlin/net/tcgdex/sdk/internal/CacheEntry.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package net.tcgdex.sdk.internal
|
||||
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class CacheEntry <T> (
|
||||
val value: T,
|
||||
val time: LocalDateTime = LocalDateTime.now()
|
||||
)
|
18
src/main/kotlin/net/tcgdex/sdk/internal/Model.kt
Normal file
18
src/main/kotlin/net/tcgdex/sdk/internal/Model.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package net.tcgdex.sdk.internal
|
||||
|
||||
import com.google.gson.Gson
|
||||
import net.tcgdex.sdk.TCGdex
|
||||
|
||||
abstract class Model {
|
||||
/**
|
||||
* Give you a string representation of the Model
|
||||
*
|
||||
* @return the model data as JSON
|
||||
*/
|
||||
override fun toString(): String {
|
||||
val gson = Gson()
|
||||
return gson.toJson(this)
|
||||
}
|
||||
|
||||
public lateinit var tcgdex: TCGdex
|
||||
}
|
187
src/main/kotlin/net/tcgdex/sdk/models/Card.kt
Normal file
187
src/main/kotlin/net/tcgdex/sdk/models/Card.kt
Normal file
@ -0,0 +1,187 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Quality
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import net.tcgdex.sdk.models.subs.CardAbility
|
||||
import net.tcgdex.sdk.models.subs.CardAttack
|
||||
import net.tcgdex.sdk.models.subs.CardItem
|
||||
import net.tcgdex.sdk.models.subs.CardVariants
|
||||
import net.tcgdex.sdk.models.subs.CardWeakRes
|
||||
import net.tcgdex.sdk.models.subs.Legal
|
||||
import java.awt.image.BufferedImage
|
||||
/**
|
||||
* Pokémon TCG Card, It contains every informations about a specific card
|
||||
*/
|
||||
data class Card internal constructor(
|
||||
|
||||
/**
|
||||
* Globally unique card ID based on the set ID and the cards ID within the set
|
||||
*/
|
||||
val id: String,
|
||||
|
||||
/**
|
||||
* ID indexing this card within its set, usually just its number
|
||||
*/
|
||||
val localId: String,
|
||||
|
||||
/**
|
||||
* Card name
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* Card image url without the extension and quality
|
||||
*/
|
||||
val image: String?,
|
||||
|
||||
|
||||
/**
|
||||
* Card illustrator
|
||||
*/
|
||||
val illustrator: String?,
|
||||
|
||||
/**
|
||||
* Card rarity
|
||||
*/
|
||||
val rarity: String,
|
||||
|
||||
/**
|
||||
* Card category
|
||||
*/
|
||||
val category: String,
|
||||
|
||||
/**
|
||||
* The card possible variants
|
||||
*/
|
||||
val variants: CardVariants?,
|
||||
|
||||
/**
|
||||
* Resume of the set the card belongs to
|
||||
*/
|
||||
val set: SetResume,
|
||||
|
||||
|
||||
/**
|
||||
* the Pokémon Pokédex IDs (multiple if multiple pokémon appears on the card)
|
||||
*/
|
||||
val dexIDs: List<Int>?,
|
||||
|
||||
/**
|
||||
* HP of the pokemon
|
||||
*/
|
||||
val hp: Int?,
|
||||
|
||||
/**
|
||||
* Types of the pokemon (multiple because some have multiple in the older sets)
|
||||
*/
|
||||
val types: List<String>?,
|
||||
|
||||
/**
|
||||
* Name of the pokemon this one evolves from
|
||||
*/
|
||||
val evolveFrom: String?,
|
||||
|
||||
/**
|
||||
* the Pokémon Pokédex like description
|
||||
*/
|
||||
val description: String?,
|
||||
|
||||
/**
|
||||
*the Pokémon Level (can be "X" if the card is of level X)
|
||||
*/
|
||||
val level: String?,
|
||||
|
||||
/**
|
||||
* the Pokémon Stage (changes depending on the API language)
|
||||
*/
|
||||
val stage: String?,
|
||||
|
||||
/**
|
||||
* the Pokémon Suffix (changes depending on the API language)
|
||||
*/
|
||||
val suffix: String?,
|
||||
|
||||
/**
|
||||
* the Item the Pokémon have
|
||||
*/
|
||||
val item: CardItem?,
|
||||
|
||||
/**
|
||||
* the Card abilities (some cards have multiple abilities)
|
||||
*/
|
||||
val abilities: List<CardAbility>,
|
||||
|
||||
/**
|
||||
* the Card Attacks
|
||||
*/
|
||||
val attacks: List<CardAttack>,
|
||||
|
||||
/**
|
||||
*
|
||||
* the Pokémon Weaknesses
|
||||
*/
|
||||
val weaknesses: List<CardWeakRes>,
|
||||
|
||||
/**
|
||||
*
|
||||
* the Pokémon Resistances
|
||||
*/
|
||||
val resistances: List<CardWeakRes>,
|
||||
|
||||
/**
|
||||
*
|
||||
* the Pokémon retreat Cost
|
||||
*/
|
||||
val retreat: Int?,
|
||||
|
||||
|
||||
/**
|
||||
* effect the Card Effect (Trainer/Energy only)
|
||||
*/
|
||||
val effect: String?,
|
||||
|
||||
/**
|
||||
* the trainer sub type (changes depending on the API language)
|
||||
*/
|
||||
val trainerType: String?,
|
||||
|
||||
/**
|
||||
* the energy sub type (changes depending on the API language)
|
||||
*/
|
||||
val energyType: String?,
|
||||
|
||||
/**
|
||||
* the Card Regulation mark
|
||||
*/
|
||||
val regulationMark: String?,
|
||||
|
||||
/**
|
||||
* the card ability to be played in tournaments
|
||||
*/
|
||||
val legal: Legal
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* the Card Image full URL
|
||||
*
|
||||
* @param quality the quality you want your image to be in
|
||||
* @param extension extension you want you image to be
|
||||
* @return the full card URL with the extension and quality
|
||||
*/
|
||||
fun getImageUrl(quality: Quality, extension: Extension): String {
|
||||
return "${this.image}/${quality.value}.${extension}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image buffer
|
||||
*
|
||||
* @param quality the quality you want your image to be in
|
||||
* @param format extension you want you image to be
|
||||
* @return the full card Buffer in the format you want
|
||||
*/
|
||||
fun getImage(quality: Quality, format: Extension): BufferedImage {
|
||||
return Utils.downloadImage(this.getImageUrl(quality, format))
|
||||
}
|
||||
}
|
67
src/main/kotlin/net/tcgdex/sdk/models/CardResume.kt
Normal file
67
src/main/kotlin/net/tcgdex/sdk/models/CardResume.kt
Normal file
@ -0,0 +1,67 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Quality
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
/**
|
||||
* Card Resume class, contains basic informations about a specific card
|
||||
*
|
||||
* to get the full card you can use the `getFullCard()` function
|
||||
*/
|
||||
data class CardResume internal constructor(
|
||||
|
||||
/**
|
||||
* Globally unique card ID based on the set ID and the cards ID within the set
|
||||
*/
|
||||
val id: String,
|
||||
|
||||
/**
|
||||
* ID indexing this card within its set, usually just its number
|
||||
*/
|
||||
val localId: String,
|
||||
|
||||
/**
|
||||
* Card name
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* Card image url without the extension and quality
|
||||
*/
|
||||
val image: String?
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* the the Card Image full URL
|
||||
*
|
||||
* @param quality the quality you want your image to be in
|
||||
* @param extension extension you want you image to be
|
||||
* @return the full card URL with the extension and quality
|
||||
*/
|
||||
fun getImageUrl(quality: Quality, extension: Extension): String {
|
||||
return "${this.image}/${quality}.${extension.value}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image buffer
|
||||
*
|
||||
* @param quality the quality you want your image to be in
|
||||
* @param format extension you want you image to be
|
||||
* @return the full card Buffer in the format you want
|
||||
*/
|
||||
fun getImage(quality: Quality, format: Extension): BufferedImage {
|
||||
return Utils.downloadImage(this.getImageUrl(quality, format))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full Card
|
||||
*
|
||||
* @return the full card if available
|
||||
*/
|
||||
fun getFullCard(): Card? {
|
||||
return this.tcgdex.fetchCard(this.id)
|
||||
}
|
||||
}
|
57
src/main/kotlin/net/tcgdex/sdk/models/Serie.kt
Normal file
57
src/main/kotlin/net/tcgdex/sdk/models/Serie.kt
Normal file
@ -0,0 +1,57 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
/**
|
||||
* Pokémon TCG Serie
|
||||
*/
|
||||
class Serie (
|
||||
|
||||
/**
|
||||
* the list of sets the Serie contains
|
||||
*/
|
||||
val sets: List<SetResume>,
|
||||
|
||||
/**
|
||||
* the Serie unique ID
|
||||
*/
|
||||
val id: String,
|
||||
|
||||
/**
|
||||
* the Serie name
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* the Serie Logo (basically also the first set logo)
|
||||
*/
|
||||
val logo: String?
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* Get the logo full url
|
||||
*
|
||||
* @param extension the file extension you want to use
|
||||
* @return the full URL of the logo
|
||||
*/
|
||||
fun getLogoUrl(extension: Extension): String? {
|
||||
if (this.logo == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.logo}.${extension.value}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logo buffer
|
||||
*
|
||||
* @param format the image format
|
||||
* @return a buffer containing the image
|
||||
*/
|
||||
fun getLogo(format: Extension): BufferedImage? {
|
||||
val logo = this.getLogoUrl(format) ?: return null
|
||||
return Utils.downloadImage(logo)
|
||||
}
|
||||
}
|
62
src/main/kotlin/net/tcgdex/sdk/models/SerieResume.kt
Normal file
62
src/main/kotlin/net/tcgdex/sdk/models/SerieResume.kt
Normal file
@ -0,0 +1,62 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
|
||||
/**
|
||||
* Serie Resume
|
||||
*/
|
||||
open class SerieResume internal constructor(
|
||||
|
||||
/**
|
||||
* the Serie unique ID
|
||||
*/
|
||||
val id: String,
|
||||
|
||||
/**
|
||||
* the Serie name
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* the Serie Logo (basically also the first set logo)
|
||||
*/
|
||||
val logo: String?
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* Get the logo full url
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getLogoUrl(extension: Extension): String? {
|
||||
if (this.logo == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.logo}.${extension}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logo buffer
|
||||
*
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
fun getLogo(format: Extension): BufferedImage? {
|
||||
val logo = this.getLogoUrl(format) ?: return null
|
||||
return Utils.downloadImage(logo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full Serie
|
||||
*
|
||||
* @return the full serie if available
|
||||
*/
|
||||
fun getFullSerie(): Serie? {
|
||||
return this.tcgdex.fetchSerie(this.id)
|
||||
}
|
||||
}
|
113
src/main/kotlin/net/tcgdex/sdk/models/Set.kt
Normal file
113
src/main/kotlin/net/tcgdex/sdk/models/Set.kt
Normal file
@ -0,0 +1,113 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import net.tcgdex.sdk.models.subs.Legal
|
||||
import net.tcgdex.sdk.models.subs.SetCardCount
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
/**
|
||||
* Pokémon TCG Set class
|
||||
*/
|
||||
data class Set internal constructor(
|
||||
|
||||
/**
|
||||
* Globally unique set ID
|
||||
*/
|
||||
val id: String?,
|
||||
|
||||
/**
|
||||
* the Set mame
|
||||
*/
|
||||
val name: String?,
|
||||
|
||||
/**
|
||||
* the Set Logo incomplete URL (use getLogoUrl/getLogo)
|
||||
*/
|
||||
val logo: String?,
|
||||
|
||||
/**
|
||||
* the Set Symbol imcomplete URL (use getSymbolUrl/getSymbol)
|
||||
*/
|
||||
val symbol: String?,
|
||||
|
||||
/**
|
||||
* the serie this set is a part of
|
||||
*/
|
||||
val serie: SerieResume,
|
||||
|
||||
/**
|
||||
* the TCG Online Code
|
||||
*/
|
||||
val tcgOnline: String?,
|
||||
|
||||
/**
|
||||
* the Set release date as yyyy-mm-dd
|
||||
*/
|
||||
val releaseDate: String?,
|
||||
|
||||
/**
|
||||
* the set legality (won't indicate if a card is banned)
|
||||
*/
|
||||
val legal: Legal,
|
||||
|
||||
/**
|
||||
* the number of card in the set
|
||||
*/
|
||||
val cardCount: SetCardCount,
|
||||
|
||||
/**
|
||||
* the cards contained in this set
|
||||
*/
|
||||
val cards: List<CardResume>
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* Get logo url
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getLogoUrl(extension: Extension): String? {
|
||||
if (this.logo == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.logo}.${extension.value}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getLogo(extension: Extension): BufferedImage? {
|
||||
val logo = this.getLogoUrl(extension) ?: return null
|
||||
return Utils.downloadImage(logo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symbol url
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getSymbolUrl(extension: Extension): String? {
|
||||
if (this.symbol == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.symbol}.${extension.value}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symbol
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getSymbol(extension: Extension): BufferedImage? {
|
||||
val symbol = this.getSymbolUrl(extension) ?: return null
|
||||
return Utils.downloadImage(symbol)
|
||||
}
|
||||
}
|
96
src/main/kotlin/net/tcgdex/sdk/models/SetResume.kt
Normal file
96
src/main/kotlin/net/tcgdex/sdk/models/SetResume.kt
Normal file
@ -0,0 +1,96 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.Extension
|
||||
import net.tcgdex.sdk.Utils
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
import net.tcgdex.sdk.models.subs.SetCardCountResume
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
/**
|
||||
* Set resume
|
||||
*/
|
||||
data class SetResume internal constructor(
|
||||
|
||||
/**
|
||||
* Globally unique set ID
|
||||
*/
|
||||
val id: String,
|
||||
|
||||
/**
|
||||
* the Set mame
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* the Set Logo incomplete URL (use getLogoUrl/getLogo)
|
||||
*/
|
||||
val logo: String?,
|
||||
|
||||
/**
|
||||
* the Set Symbol incomplete URL (use getSymbolUrl/getSymbol)
|
||||
*/
|
||||
val symbol: String?,
|
||||
|
||||
/**
|
||||
* the number of card in the set
|
||||
*/
|
||||
val cardCount: SetCardCountResume
|
||||
) : Model() {
|
||||
|
||||
/**
|
||||
* Get logo url
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getLogoUrl(extension: Extension): String? {
|
||||
if (this.logo == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.logo}.${extension}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getLogo(extension: Extension): BufferedImage? {
|
||||
val logo = this.getLogoUrl(extension) ?: return null
|
||||
return Utils.downloadImage(logo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symbol url
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getSymbolUrl(extension: Extension): String? {
|
||||
if (this.symbol == null) {
|
||||
return null
|
||||
}
|
||||
return "${this.symbol}.${extension}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symbol
|
||||
*
|
||||
* @param extension
|
||||
* @return
|
||||
*/
|
||||
fun getSymbol(extension: Extension): BufferedImage? {
|
||||
val symbol = this.getSymbolUrl(extension) ?: return null
|
||||
return Utils.downloadImage(symbol)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full set
|
||||
*
|
||||
* @return the full set if available
|
||||
*/
|
||||
fun getFullSet(): Set? {
|
||||
return this.tcgdex.fetchSet(this.id)
|
||||
}
|
||||
}
|
20
src/main/kotlin/net/tcgdex/sdk/models/StringEndpoint.kt
Normal file
20
src/main/kotlin/net/tcgdex/sdk/models/StringEndpoint.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package net.tcgdex.sdk.models
|
||||
|
||||
import net.tcgdex.sdk.internal.Model
|
||||
|
||||
/**
|
||||
* Generix class that handle a lot of Endpoints
|
||||
*
|
||||
* @constructor Create empty String endpoint
|
||||
*/
|
||||
data class StringEndpoint(
|
||||
/**
|
||||
* the endpoint value
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* the cards that contain `name` in them
|
||||
*/
|
||||
val cards: List<CardResume>
|
||||
) : Model()
|
23
src/main/kotlin/net/tcgdex/sdk/models/subs/CardAbility.kt
Normal file
23
src/main/kotlin/net/tcgdex/sdk/models/subs/CardAbility.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Describes a single ability of a pokemon
|
||||
*/
|
||||
data class CardAbility internal constructor(
|
||||
|
||||
/**
|
||||
* The Ability type (language dependant)
|
||||
*/
|
||||
val type: String,
|
||||
|
||||
/**
|
||||
* Name of the ability
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
*
|
||||
* Description/Effect of the ability
|
||||
*/
|
||||
val effect: String
|
||||
)
|
28
src/main/kotlin/net/tcgdex/sdk/models/subs/CardAttack.kt
Normal file
28
src/main/kotlin/net/tcgdex/sdk/models/subs/CardAttack.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Describes a single attack of a pokemon, for example 'Confuse Ray'
|
||||
*/
|
||||
data class CardAttack internal constructor(
|
||||
|
||||
|
||||
/**
|
||||
* Name of the attack
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* Cost of the attack in the same order as listed on the card
|
||||
*/
|
||||
val cost: List<String>? = null,
|
||||
|
||||
/**
|
||||
* Effect/Description of the attack, may be null for attacks without text
|
||||
*/
|
||||
val effect: String? = null,
|
||||
|
||||
/**
|
||||
* Damage the attack deals. May just be a number like '30', but can also be a multiplier like 'x20'
|
||||
*/
|
||||
val damage: String? = null
|
||||
)
|
17
src/main/kotlin/net/tcgdex/sdk/models/subs/CardItem.kt
Normal file
17
src/main/kotlin/net/tcgdex/sdk/models/subs/CardItem.kt
Normal file
@ -0,0 +1,17 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Card Item
|
||||
*/
|
||||
data class CardItem(
|
||||
|
||||
/**
|
||||
* the Item name
|
||||
*/
|
||||
val name: String,
|
||||
|
||||
/**
|
||||
* the item effect
|
||||
*/
|
||||
val effect: String
|
||||
)
|
32
src/main/kotlin/net/tcgdex/sdk/models/subs/CardVariants.kt
Normal file
32
src/main/kotlin/net/tcgdex/sdk/models/subs/CardVariants.kt
Normal file
@ -0,0 +1,32 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Card variants
|
||||
*/
|
||||
data class CardVariants(
|
||||
|
||||
/**
|
||||
* basic variant no special effects
|
||||
*/
|
||||
val normal: Boolean?,
|
||||
|
||||
/**
|
||||
* the card have some shine behind colored content
|
||||
*/
|
||||
val reverse: Boolean?,
|
||||
|
||||
/**
|
||||
* the card picture have some shine to it
|
||||
*/
|
||||
val holo: Boolean?,
|
||||
|
||||
/**
|
||||
* the card contains a First Edition Stamp (only Base serie)
|
||||
*/
|
||||
val firstEdition: Boolean?,
|
||||
|
||||
/**
|
||||
* the card has a wPromo stamp on it
|
||||
*/
|
||||
val wPromo: Boolean?
|
||||
)
|
18
src/main/kotlin/net/tcgdex/sdk/models/subs/CardWeakRes.kt
Normal file
18
src/main/kotlin/net/tcgdex/sdk/models/subs/CardWeakRes.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
|
||||
/**
|
||||
* Describes the weakness/resistance of a single pokemon, for example: 2x to Fire
|
||||
*/
|
||||
data class CardWeakRes internal constructor(
|
||||
|
||||
/**
|
||||
* the affecting type
|
||||
*/
|
||||
val type: String,
|
||||
|
||||
/**
|
||||
* the multiplier mostly `x2` but can also be `-30`, `+30` depending on the card
|
||||
*/
|
||||
val value: String?
|
||||
)
|
19
src/main/kotlin/net/tcgdex/sdk/models/subs/Legal.kt
Normal file
19
src/main/kotlin/net/tcgdex/sdk/models/subs/Legal.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Card Legality
|
||||
*
|
||||
* _note: cards are always usable in the unlimited tournaments_
|
||||
*/
|
||||
data class Legal(
|
||||
|
||||
/**
|
||||
* card is usable in standard tournaments
|
||||
*/
|
||||
val standard: Boolean,
|
||||
|
||||
/**
|
||||
* card is usable in expanded tournaments
|
||||
*/
|
||||
val expanded: Boolean
|
||||
)
|
37
src/main/kotlin/net/tcgdex/sdk/models/subs/SetCardCount.kt
Normal file
37
src/main/kotlin/net/tcgdex/sdk/models/subs/SetCardCount.kt
Normal file
@ -0,0 +1,37 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Set card count
|
||||
*/
|
||||
data class SetCardCount (
|
||||
|
||||
/**
|
||||
* total of number of cards
|
||||
*/
|
||||
val total: Int,
|
||||
|
||||
/**
|
||||
* number of cards officialy (on the bottom of each cards)
|
||||
*/
|
||||
val official: Int,
|
||||
|
||||
/**
|
||||
* number of cards having a normal version
|
||||
*/
|
||||
val normal: Int,
|
||||
|
||||
/**
|
||||
* number of cards having an reverse version
|
||||
*/
|
||||
val reverse: Int,
|
||||
|
||||
/**
|
||||
* number of cards having an holo version
|
||||
*/
|
||||
val holo: Int,
|
||||
|
||||
/**
|
||||
* Number of possible cards
|
||||
*/
|
||||
val firstEd: Int?
|
||||
)
|
@ -0,0 +1,17 @@
|
||||
package net.tcgdex.sdk.models.subs
|
||||
|
||||
/**
|
||||
* Set card count resume
|
||||
*/
|
||||
data class SetCardCountResume (
|
||||
|
||||
/**
|
||||
* total of number of cards
|
||||
*/
|
||||
val total: Int,
|
||||
|
||||
/**
|
||||
* number of cards officialy (on the bottom of each cards)
|
||||
*/
|
||||
val official: Int
|
||||
)
|
Reference in New Issue
Block a user