mirror of
https://github.com/tcgdex/java-sdk.git
synced 2025-06-06 00:09:56 +00:00
feat: Full rework to support both Kotlin and Java and make it work like the Other SDKs (#2)
This commit is contained in:
parent
82aaf7cb01
commit
7ad76513e0
34
.editorconfig
Normal file
34
.editorconfig
Normal file
@ -0,0 +1,34 @@
|
||||
root = true
|
||||
|
||||
# Base Configuration
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 80
|
||||
end_of_line = lf
|
||||
|
||||
# Yaml Standard
|
||||
[*.{yaml,yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# Markdown Standards
|
||||
[*.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
# C++ Standards
|
||||
[*.{cpp,h,ino}]
|
||||
indent_style = space
|
||||
|
||||
# PHP Standards
|
||||
[*.php]
|
||||
indent_style = space
|
||||
|
||||
# Java/Kotlin Standards
|
||||
[*.{java,kt,kts}]
|
||||
indent_style = space
|
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
* text=auto eol=lf
|
32
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
32
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Bug
|
||||
description: Use this template if you have found a bug in the SDK
|
||||
title: "bug: "
|
||||
labels: [bug]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this Form!
|
||||
- type: textarea
|
||||
id: happening
|
||||
attributes:
|
||||
label: What is Hapening
|
||||
placeholder: "Ex: When using this function the SDK crash..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: happen
|
||||
attributes:
|
||||
label: Please explain what should happen
|
||||
description: If you selected Other or new Data Type please put it as the first line
|
||||
placeholder: "Ex: The SDK should not crash"
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproducre
|
||||
attributes:
|
||||
label: Please give us a way to reproduce
|
||||
description: You can list a way or give us access to a minimal Github repo to reproduce it
|
||||
placeholder: "Ex: https://github.com/you/your-repository"
|
||||
validations:
|
||||
required: true
|
16
.github/ISSUE_TEMPLATE/enhancement.yml
vendored
Normal file
16
.github/ISSUE_TEMPLATE/enhancement.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
name: Enhancement
|
||||
description: Use this template if you have an Idea that will enhance the SDK
|
||||
title: "enhancement: "
|
||||
labels: [enhancement]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this Form!
|
||||
- type: textarea
|
||||
id: explain
|
||||
attributes:
|
||||
label: Please explain in more details what idea you have
|
||||
placeholder: "Ex: I would love to see this or this..."
|
||||
validations:
|
||||
required: true
|
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<!--
|
||||
Thanks for your Pull Request, Please provide the related Issue using "Fix #0" or describe the change(s) you made.
|
||||
The issue title must follow Conventional Commit (verified by Github Actions) conventionalcommits.org.
|
||||
More informations at https://github.com/tcgdex/cards-database/blob/master/CONTRIBUTING.md
|
||||
-->
|
21
.github/dependabot.yml
vendored
Normal file
21
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
commit-message:
|
||||
prefix: build
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
commit-message:
|
||||
prefix: build
|
34
.github/workflows/build.yml
vendored
Normal file
34
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: Java CI with Gradle
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'temurin'
|
||||
- name: Build with Gradle
|
||||
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
|
||||
with:
|
||||
arguments: build
|
45
.github/workflows/publish.yml
vendored
Normal file
45
.github/workflows/publish.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
|
||||
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
|
||||
|
||||
name: Gradle Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'temurin'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build with Gradle
|
||||
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
|
||||
with:
|
||||
arguments: build
|
||||
|
||||
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
|
||||
# the publishing section of your build.gradle
|
||||
- name: Publish to GitHub Packages
|
||||
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
|
||||
with:
|
||||
arguments: publish
|
||||
env:
|
||||
USERNAME: ${{ github.actor }}
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
268
.gitignore
vendored
268
.gitignore
vendored
@ -1,265 +1,3 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/java,batch,linux,macos,maven,windows,eclipse,intellij+all
|
||||
# Edit at https://www.gitignore.io/?templates=java,batch,linux,macos,maven,windows,eclipse,intellij+all
|
||||
|
||||
### Batch ###
|
||||
# BatchFiles
|
||||
*.bat
|
||||
*.cmd
|
||||
*.btm
|
||||
|
||||
### Eclipse ###
|
||||
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
### Eclipse Patch ###
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated
|
||||
|
||||
.sts4-cache/
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
.gradle
|
||||
.idea
|
||||
build
|
||||
|
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright © 2021 Maxopoly
|
||||
Copyright © 2022 Maxopoly and Avior
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
174
README.md
174
README.md
@ -1,31 +1,155 @@
|
||||
# Tcgdex-java
|
||||
<p align="center">
|
||||
<a href="https://www.tcgdex.net">
|
||||
<img src="https://www.tcgdex.net/assets/og.png" width="90%" alt="TCGdex Main Image">
|
||||
</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://jitpack.io/#net.tcgdex/java-sdk">
|
||||
<img src="https://img.shields.io/jitpack/v/github/tcgdex/java-sdk?style=flat-square" alt="Package Version">
|
||||
</a>
|
||||
<!--<a href="http://npmjs.com/@tcgdex/sdk">
|
||||
<img src="https://img.shields.io/npm/dm/@tcgdex/sdk?style=flat-square" alt="NPM Downloads">
|
||||
</a>
|
||||
<a href="https://app.codecov.io/gh/tcgdex/javascript-sdk/">
|
||||
<img src="https://img.shields.io/codecov/c/github/tcgdex/javascript-sdk?style=flat-square&token=FR4BI94N4Q" alt="coverage">
|
||||
</a>-->
|
||||
<a href="https://github.com/tcgdex/java-sdk/stargazers">
|
||||
<img src="https://img.shields.io/github/stars/tcgdex/java-sdk?style=flat-square" alt="Github stars">
|
||||
</a>
|
||||
<a href="https://github.com/tcgdex/javascript-sdk/actions/workflows/build.yml">
|
||||
<img src="https://img.shields.io/github/workflow/status/tcgdex/javascript-sdk/Build%20&%20Test?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
||||
</a>
|
||||
<a href="https://discord.gg/NehYTAhsZE">
|
||||
<img src="https://img.shields.io/discord/857231041261076491?color=%235865F2&label=Discord&style=flat-square" alt="Discord Link">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
This is a Java API for querying the Pokémon TCG database of [TCGdex](https://github.com/tcgdex/).
|
||||
# TCGdex Kotlin/Java SDK
|
||||
|
||||
To use it, first initialize an API instance with the language you want results to be in
|
||||
```java
|
||||
TCGDexAPI api = new TCGDexAPI(TCGDexAPI.Language.EN);
|
||||
The Kotlin/Java SDK provides a convenient access with the Open Source TCGdex API.
|
||||
|
||||
The SDK is available both for Kotlin use and Java.
|
||||
|
||||
## Documentation
|
||||
|
||||
_The full API/SDK documentation in progress at [API Documentation - TCGdex](https://www.tcgdex.dev)_
|
||||
|
||||
### Getting Started
|
||||
|
||||
#### How To install
|
||||
|
||||
**Gradle**
|
||||
|
||||
1. add the repository in you `build.gradle`
|
||||
|
||||
```gradle
|
||||
repositories {
|
||||
...
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
```
|
||||
|
||||
Use it to obtain POJOs representing cards, sets and series. For all of these, there is a function listing all available including short info and a function to get detailed information regarding one.
|
||||
|
||||
```java
|
||||
//all cards available
|
||||
List<CardResume> allCards = api.getAllCards();
|
||||
//detailed card info
|
||||
CardInfo card = api.getCardInfo(allCards.get(23));
|
||||
|
||||
//all sets available
|
||||
List<SetResume> allSets = getAllSets();
|
||||
//Obtained set info either based on the listing of all sets
|
||||
SetInfo set = getSetInfo(allSets.get(1));
|
||||
//or based on some card, also works for CardInfo
|
||||
SetInfo set2 = getSetInfo(allCards.get(10));
|
||||
|
||||
//all series available
|
||||
List<SeriesResume> allSeries = getAllSeries();
|
||||
//same possibilties for series
|
||||
SeriesInfo series = getSeriesInfo(allSeries.get(2));
|
||||
SeriesInfo series2 = getSeriesInfo(set);
|
||||
2. Add the dependency in your `build.gradle`
|
||||
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation 'net.tcgdex:java-sdk:{Version}'
|
||||
}
|
||||
```
|
||||
|
||||
**Maven**
|
||||
|
||||
1. add the repository in your `pom.xml`
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
2. Add the depedency in your `pom.xml`
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>net.tcgdex</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
<version>{Version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
#### Usage
|
||||
|
||||
_Note: a complete documentation is available at [TCGdex.dev](https://www.tcgdex.dev)_
|
||||
|
||||
##### Kotlin
|
||||
|
||||
**Example: Fetch a Card**
|
||||
|
||||
```kotlin
|
||||
// Import the SDK
|
||||
import net.tcgdex.sdk.TCGdex
|
||||
|
||||
// Init the library with the language code (see the API REST documentation for the list)
|
||||
val api = TCGdex("en")
|
||||
|
||||
// returns you a Card Class with every informations filled!
|
||||
val card = api.fetchCard("swsh1-1")
|
||||
```
|
||||
|
||||
**Other Functions**
|
||||
|
||||
```kotlin
|
||||
api.fetchCard("swsh3-136")
|
||||
api.fetchCard("swsh3", "136")
|
||||
api.fetchSet("swsh3")
|
||||
api.fetchSets()
|
||||
api.fetchSerie("swsh")
|
||||
api.fetchSeries()
|
||||
api.fetchTypes()
|
||||
api.fetchType("Colorless")
|
||||
api.fetchRetreats()
|
||||
api.fetchRetreat("1")
|
||||
api.fetchRarities()
|
||||
api.fetchRarity("Uncommon")
|
||||
api.fetchIllustrators()
|
||||
api.fetchIllustrator("tetsuya koizumi")
|
||||
api.fetchHPs()
|
||||
api.fetchHP("110")
|
||||
api.fetchCategories()
|
||||
api.fetchCategory("Pokemon")
|
||||
api.fetchDexIds()
|
||||
api.fetchDexId("162")
|
||||
api.fetchEnergyTypes()
|
||||
api.fetchEnergyType("Special")
|
||||
api.fetchRegulationMarks()
|
||||
api.fetchRegulationMark("D")
|
||||
api.fetchStages()
|
||||
api.fetchStage("Basic")
|
||||
api.fetchSuffixes()
|
||||
api.fetchSuffix("EX")
|
||||
api.fetchTrainerTypes()
|
||||
api.fetchTrainerType("Tool")
|
||||
api.fetchVariants()
|
||||
api.fetchVariant("holo")
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](https://github.com/tcgdex/javascript-sdk/blob/master/CONTRIBUTING.md)
|
||||
|
||||
TL::DR
|
||||
|
||||
- Fork
|
||||
|
||||
- Commit your changes
|
||||
|
||||
- Pull Request on this Repository
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License. A copy of the license is available at [LICENSE.md](https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md)
|
||||
|
||||
This is based on the [Maxopoly](https://github.com/Maxopoly) TCGdex Java SDK
|
||||
|
89
build.gradle.kts
Normal file
89
build.gradle.kts
Normal file
@ -0,0 +1,89 @@
|
||||
plugins {
|
||||
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
|
||||
kotlin("jvm") version "1.6.20"
|
||||
id("org.jetbrains.dokka") version "1.6.21"
|
||||
|
||||
// Apply the java-library plugin for API and implementation separation.
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
val artifact = System.getenv("artifact") ?: "sdk"
|
||||
group = System.getenv("group") ?: "net.tcgdex"
|
||||
version = System.getenv("version") ?: "2.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
// Use the Kotlin JDK 8 standard library.
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
// Gson
|
||||
implementation("com.google.code.gson:gson:2.9.0")
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tasks {
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
// Javadocs
|
||||
val javadocJar = tasks.named<Jar>("javadocJar") {
|
||||
from(tasks.named("dokkaJavadoc"))
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
// groupId = group
|
||||
artifactId = artifact
|
||||
// version = ver
|
||||
|
||||
from(components["java"])
|
||||
|
||||
pom {
|
||||
name.set("TCGdex SDK")
|
||||
description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK")
|
||||
url.set("https://github.com/tcgdex/java-sdk")
|
||||
licenses {
|
||||
license {
|
||||
name.set("MIT License")
|
||||
url.set("https://github.com/tcgdex/java-sdk/blob/master/LICENSE.txt")
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id.set("avior")
|
||||
name.set("Avior")
|
||||
email.set("contact@tcgdex.net")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection.set("scm:git@github.com:tcgdex/java-sdk.git")
|
||||
url.set("https://github.com/tcgdex/java-sdk")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
gradle.properties
Normal file
1
gradle.properties
Normal file
@ -0,0 +1 @@
|
||||
kotlin.code.style=official
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
234
gradlew
vendored
Executable file
234
gradlew
vendored
Executable file
@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
64
pom.xml
64
pom.xml
@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.tcgdex</groupId>
|
||||
|
||||
<artifactId>tcgdex</artifactId>
|
||||
|
||||
<name>tcgdex</name>
|
||||
<version>1.0.0</version>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20160810</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
2
settings.gradle.kts
Normal file
2
settings.gradle.kts
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
rootProject.name = "tcgdex-sdk"
|
@ -1,79 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Describes a single ability of a pokemon
|
||||
*
|
||||
*/
|
||||
public class Ability {
|
||||
|
||||
static List<Ability> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Ability> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
result.add(new Ability(array.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
private final String name;
|
||||
private final String effect;
|
||||
|
||||
Ability(JSONObject json) {
|
||||
this(json.getString("type"), json.getString("name"), json.getString("effect"));
|
||||
}
|
||||
|
||||
Ability(String type, String name, String effect) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Ability)) {
|
||||
return false;
|
||||
}
|
||||
Ability other = (Ability) o;
|
||||
return Objects.deepEquals(new Object[] { this.type, this.name, this.effect },
|
||||
new Object[] { other.type, other.name, other.effect });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Description/Effect of the ability
|
||||
*/
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of the ability
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type of the ability, for example 'Poke-POWER'
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.name, this.effect);
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Describes a single attack of a pokemon, for example 'Confuse Ray'
|
||||
*
|
||||
*/
|
||||
public class Attack {
|
||||
|
||||
static List<Attack> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Attack> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
result.add(new Attack(array.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final List<Types> cost;
|
||||
private final String name;
|
||||
private final String effect;
|
||||
private final String damage;
|
||||
|
||||
Attack(JSONObject json) {
|
||||
this(Types.parse(json.optJSONArray("cost")), json.getString("name"), json.optString("effect"),
|
||||
json.optString("damage"));
|
||||
}
|
||||
|
||||
Attack(List<Types> cost, String name, String effect, String damage) {
|
||||
super();
|
||||
this.cost = cost;
|
||||
this.name = name;
|
||||
this.effect = effect;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Attack)) {
|
||||
return false;
|
||||
}
|
||||
Attack other = (Attack) o;
|
||||
return Objects.deepEquals(new Object[] { this.cost, this.name, this.effect, this.damage },
|
||||
new Object[] { other.cost, other.name, other.effect, other.damage });
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Cost of the attack in the same order as listed on the card
|
||||
*/
|
||||
public List<Types> getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Damage the attack deals. May just be a number like '30', but can also
|
||||
* be a multiplier like 'x20'
|
||||
*/
|
||||
public String getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Effect/Description of the attack, may be null for attacks without text
|
||||
*/
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of the attack
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.cost, this.name, this.effect, this.damage);
|
||||
}
|
||||
|
||||
}
|
@ -1,259 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Full description of a card, including all information available about it
|
||||
*
|
||||
*/
|
||||
public class CardInfo extends CardResume {
|
||||
|
||||
private final String illustrator;
|
||||
private final Rarities rarity;
|
||||
private final Categories category;
|
||||
private final boolean hasNormalVariant;
|
||||
private final boolean hasReverseVariant;
|
||||
private final boolean hasHolo;
|
||||
private final boolean hasFirstEditionPic;
|
||||
private final SetResume set;
|
||||
private final List<Integer> dexIDs;
|
||||
private final Integer hp;
|
||||
private final List<Types> types;
|
||||
private final String evolveFrom;
|
||||
private final String description;
|
||||
private final String level;
|
||||
private final String stage;
|
||||
private final String suffix;
|
||||
private final List<Attack> attacks;
|
||||
private final List<Weakness> weakness;
|
||||
private final List<Ability> abilities;
|
||||
private final Integer retreat;
|
||||
private final String regulationMark;
|
||||
|
||||
CardInfo(JSONObject json) {
|
||||
super(json);
|
||||
this.illustrator = json.optString("illustrator");
|
||||
this.rarity = Rarities.parse(json.getString("rarity"));
|
||||
this.category = Categories.parse(json.getString("category"));
|
||||
JSONObject variantSection = json.getJSONObject("variants");
|
||||
this.hasNormalVariant = variantSection.getBoolean("normal");
|
||||
this.hasReverseVariant = variantSection.getBoolean("reverse");
|
||||
this.hasHolo = variantSection.getBoolean("holo");
|
||||
this.hasFirstEditionPic = variantSection.getBoolean("firstEdition");
|
||||
this.set = new SetResume(json.getJSONObject("set"));
|
||||
this.dexIDs = new ArrayList<>(1);
|
||||
JSONArray dexArray = json.optJSONArray("dexId");
|
||||
if (dexArray != null) {
|
||||
for (int i = 0; i < dexArray.length(); i++) {
|
||||
this.dexIDs.add(dexArray.getInt(i));
|
||||
}
|
||||
}
|
||||
this.hp = json.optInt("hp", -1) > 0 ? json.getInt("hp") : null;
|
||||
this.types = Types.parse(json.optJSONArray("types"));
|
||||
this.stage = json.optString("stage");
|
||||
this.suffix = json.optString("suffix");
|
||||
this.attacks = Attack.parse(json.optJSONArray("attacks"));
|
||||
this.weakness = Weakness.parse(json.optJSONArray("weaknesses"));
|
||||
this.retreat = json.optInt("retreat", -1) > 0 ? json.getInt("retreat") : null;
|
||||
this.regulationMark = json.optString("regulationMark");
|
||||
this.level = json.optString("level");
|
||||
this.evolveFrom = json.optString("evolveFrom");
|
||||
this.description = json.optString("effect");
|
||||
this.abilities = Ability.parse(json.optJSONArray("abilities"));
|
||||
}
|
||||
|
||||
public CardInfo(String id, String localId, String name, String image, String illustrator, Rarities rarity,
|
||||
Categories category, boolean hasNormalVariant, boolean hasReverseVariant, boolean hasHolo,
|
||||
boolean hasFirstEditionPic, SetResume set, List<Integer> dexIDs, Integer hp, List<Types> types,
|
||||
String evolveFrom, String description, String level, String stage, String suffix, List<Attack> attacks,
|
||||
List<Weakness> weakness, List<Ability> abilities, Integer retreat, String regulationMark) {
|
||||
super(id, localId, name, image);
|
||||
this.illustrator = illustrator;
|
||||
this.rarity = rarity;
|
||||
this.category = category;
|
||||
this.hasNormalVariant = hasNormalVariant;
|
||||
this.hasReverseVariant = hasReverseVariant;
|
||||
this.hasHolo = hasHolo;
|
||||
this.hasFirstEditionPic = hasFirstEditionPic;
|
||||
this.set = set;
|
||||
this.dexIDs = dexIDs;
|
||||
this.hp = hp;
|
||||
this.types = types;
|
||||
this.evolveFrom = evolveFrom;
|
||||
this.description = description;
|
||||
this.level = level;
|
||||
this.stage = stage;
|
||||
this.suffix = suffix;
|
||||
this.attacks = attacks;
|
||||
this.weakness = weakness;
|
||||
this.abilities = abilities;
|
||||
this.retreat = retreat;
|
||||
this.regulationMark = regulationMark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Pokemon's abilities. May be empty if it doesn't have any, but never
|
||||
* null
|
||||
*/
|
||||
public List<Ability> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attacks the pokemon has. Empty for cards without attacks
|
||||
*/
|
||||
public List<Attack> getAttacks() {
|
||||
return attacks;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card category
|
||||
*/
|
||||
public Categories getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return List of the national pokedex IDs of the pokemon on the card (may be
|
||||
* multiple)
|
||||
*/
|
||||
public List<Integer> getDexIDs() {
|
||||
return dexIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card effect/description, may be null
|
||||
*/
|
||||
public String getEffect() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Name of the pokemon this one evolves from
|
||||
*/
|
||||
public String getEvolveFrom() {
|
||||
return evolveFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HP of the pokemon, will be null if the card is not a pokemon
|
||||
*/
|
||||
public Integer getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card illustrator, may be null
|
||||
*/
|
||||
public String getIllustrator() {
|
||||
return illustrator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Pokemon level, may be 'X', hence not an integer
|
||||
*/
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card rarity
|
||||
*/
|
||||
public Rarities getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card's regulation mark. May be null if unknown or doesn't exist
|
||||
*/
|
||||
public String getRegulationMark() {
|
||||
return regulationMark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Card's retreat. Will be null for cards without retreat
|
||||
*/
|
||||
public Integer getRetreat() {
|
||||
return retreat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resume of the set the card belongs to
|
||||
*/
|
||||
public SetResume getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Pokemon's stage, like 'Basic'
|
||||
*/
|
||||
public String getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Suffix, like 'V', may be null
|
||||
*/
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Types of the pokemon
|
||||
*/
|
||||
public List<Types> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Weaknesses the pokemon has. Empty for cards without attacks
|
||||
*/
|
||||
public List<Weakness> getWeakness() {
|
||||
return weakness;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Does the card have a small first edition in the middle left
|
||||
*/
|
||||
public boolean hasFirstEditionPic() {
|
||||
return hasFirstEditionPic;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Does the card have a holo variant (picture is shining)
|
||||
*/
|
||||
public boolean hasHoloVariant() {
|
||||
return hasHolo;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Does the card have a normal variant without any shines
|
||||
*/
|
||||
public boolean hasNormalVariant() {
|
||||
return hasNormalVariant;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Does the card have a reverse variant (colored background is shining)
|
||||
*/
|
||||
public boolean hasReverseVariant() {
|
||||
return hasReverseVariant;
|
||||
}
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Core information to describe a single card
|
||||
*
|
||||
*/
|
||||
public class CardResume implements Comparable<CardResume> {
|
||||
|
||||
static List<CardResume> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<CardResume> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
result.add(new CardResume(array.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final String localId;
|
||||
private final String name;
|
||||
private final String image;
|
||||
|
||||
CardResume(JSONObject json) {
|
||||
this(json.getString("id"), json.getString("localId"), json.getString("name"), json.optString("image"));
|
||||
}
|
||||
|
||||
CardResume(String id, String localId, String name, String image) {
|
||||
this.id = id;
|
||||
this.localId = localId;
|
||||
this.name = name;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s (%s): %s,%s", name, id, localId, image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Globally unique card ID based on the set ID and the cards ID within the set
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card image, can be null
|
||||
*/
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID indexing this card within its set, usually just its number
|
||||
*/
|
||||
public String getLocalId() {
|
||||
return localId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Card name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof CardResume)) {
|
||||
return false;
|
||||
}
|
||||
CardResume other = (CardResume) o;
|
||||
return this.id.equals(other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CardResume arg0) {
|
||||
return this.id.compareTo(arg0.id);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
public enum Categories {
|
||||
|
||||
POKEMON, ENERGY, TRAINER;
|
||||
|
||||
static Categories parse(String raw) {
|
||||
return Categories.valueOf(raw.toUpperCase().replace(" ", "_"));
|
||||
}
|
||||
|
||||
public String toPrettyString() {
|
||||
return Utils.prettifyEnumName(this);
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
public enum Rarities {
|
||||
|
||||
RARE, COMMON, NONE, ULTRA_RARE, UNCOMMON, AMAZING, SECRET_RARE;
|
||||
|
||||
static Rarities parse(String raw) {
|
||||
return Rarities.valueOf(raw.toUpperCase().replace(" ", "_"));
|
||||
}
|
||||
|
||||
public String toPrettyString() {
|
||||
return Utils.prettifyEnumName(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Detailed info regarding a series, including which sets it includes
|
||||
*
|
||||
*/
|
||||
public class SeriesInfo extends SeriesResume {
|
||||
|
||||
private final List<SetResume> sets;
|
||||
|
||||
SeriesInfo(JSONObject json) {
|
||||
super(json);
|
||||
this.sets = SetResume.parse(json.optJSONArray("sets"));
|
||||
}
|
||||
|
||||
SeriesInfo(String id, String name, List<SetResume> sets) {
|
||||
super(id, name);
|
||||
this.sets = sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resumes of the sets part of this series
|
||||
*/
|
||||
public List<SetResume> getSets() {
|
||||
return sets;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Contains all information describing a series, an overarching group of sets, for example XY
|
||||
*
|
||||
*/
|
||||
public class SeriesResume {
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
|
||||
SeriesResume(JSONObject json) {
|
||||
this(json.getString("id"), json.getString("name"));
|
||||
}
|
||||
|
||||
SeriesResume(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Serie unique ID
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Serie name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Detailed information regarding a set
|
||||
*
|
||||
*/
|
||||
public class SetInfo extends SetResume {
|
||||
|
||||
private static final DateTimeFormatter timeParser = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
private final int holo;
|
||||
private final int normal;
|
||||
private final int firstEd;
|
||||
private final int reverse;
|
||||
private final SeriesResume series;
|
||||
private final String tcgOnlineCode;
|
||||
private final LocalDate releaseDate;
|
||||
private final boolean legalInStandard;
|
||||
private final boolean legalInExpanded;
|
||||
private final List<CardResume> cards;
|
||||
|
||||
SetInfo(JSONObject json) {
|
||||
super(json);
|
||||
JSONObject count = json.getJSONObject("cardCount");
|
||||
this.holo = count.getInt("holo");
|
||||
this.firstEd = count.getInt("firstEd");
|
||||
this.reverse = count.getInt("reverse");
|
||||
this.normal = count.getInt("normal");
|
||||
this.series = new SeriesResume(json.getJSONObject("serie"));
|
||||
this.tcgOnlineCode = json.getString("tcgOnline");
|
||||
this.releaseDate = LocalDate.parse(json.getString("releaseDate"), timeParser);
|
||||
JSONObject legality = json.getJSONObject("legal");
|
||||
this.legalInExpanded = legality.getBoolean("expanded");
|
||||
this.legalInStandard = legality.getBoolean("standard");
|
||||
this.cards = CardResume.parse(json.getJSONArray("cards"));
|
||||
|
||||
}
|
||||
|
||||
SetInfo(String id, String name, String logo, String symbol, int officialCardCount, int totalCardCount, int holo,
|
||||
int normal, int firstEd, int reverse, SeriesResume series, String tcgOnlineCode, LocalDate releaseDate,
|
||||
boolean legalInStandard, boolean legalInExpanded, List<CardResume> cards) {
|
||||
super(id, name, logo, symbol, officialCardCount, totalCardCount);
|
||||
this.holo = holo;
|
||||
this.normal = normal;
|
||||
this.firstEd = firstEd;
|
||||
this.reverse = reverse;
|
||||
this.series = series;
|
||||
this.tcgOnlineCode = tcgOnlineCode;
|
||||
this.releaseDate = releaseDate;
|
||||
this.legalInStandard = legalInStandard;
|
||||
this.legalInExpanded = legalInExpanded;
|
||||
this.cards = cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return All cards part of the set
|
||||
*/
|
||||
public List<CardResume> getCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount of first edition cards the set has
|
||||
*/
|
||||
public int getFirstEdCardCount() {
|
||||
return firstEd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount of holo cards the set has
|
||||
*/
|
||||
public int getHoloCardCount() {
|
||||
return holo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount of normal cards the set has
|
||||
*/
|
||||
public int getNormalCardCount() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return When the set was released
|
||||
*/
|
||||
public LocalDate getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount of reverse cards the set has
|
||||
*/
|
||||
public int getReverseCardCount() {
|
||||
return reverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Series the set is part of
|
||||
*/
|
||||
public SeriesResume getSeries() {
|
||||
return series;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Pokémon TCG Online Set code
|
||||
*/
|
||||
public String getTcgOnlineCode() {
|
||||
return tcgOnlineCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ability to use this set in Expanded competitions
|
||||
*/
|
||||
public boolean isLegalInExpanded() {
|
||||
return legalInExpanded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ability to use this set in standard competitions
|
||||
*/
|
||||
public boolean isLegalInStandard() {
|
||||
return legalInStandard;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Contains all information describing a set of cards
|
||||
*
|
||||
*/
|
||||
public class SetResume {
|
||||
|
||||
static List<SetResume> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<SetResume> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
result.add(new SetResume(array.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String logo;
|
||||
private final String symbol;
|
||||
private final int officialCardCount;
|
||||
private final int totalCardCount;
|
||||
|
||||
public SetResume(JSONObject json) {
|
||||
this(json.getString("id"), json.getString("name"), json.optString("logo"), json.optString("symbol"),
|
||||
json.getJSONObject("cardCount").getInt("total"), json.getJSONObject("cardCount").getInt("official"));
|
||||
}
|
||||
|
||||
SetResume(String id, String name, String logo, String symbol, int officialCardCount, int totalCardCount) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.logo = logo;
|
||||
this.symbol = symbol;
|
||||
this.officialCardCount = officialCardCount;
|
||||
this.totalCardCount = totalCardCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set unique ID
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set logo URL, may be null
|
||||
*/
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Official amount of cards in this set
|
||||
*/
|
||||
public int getOfficialCardCount() {
|
||||
return officialCardCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set symbol URL, may be null
|
||||
*/
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Total amount of cards in this set
|
||||
*/
|
||||
public int getTotalCardCount() {
|
||||
return totalCardCount;
|
||||
}
|
||||
}
|
@ -1,243 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class TCGDexAPI {
|
||||
|
||||
public enum Language {
|
||||
DE, EN, ES, FR, IT, PT;
|
||||
|
||||
public String getAPIID() {
|
||||
return toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ImageResolution {
|
||||
HIGH, LOW;
|
||||
|
||||
public String forUseInURL() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String API_URL = "https://api.tcgdex.net/v2/%s/%s";
|
||||
|
||||
private Language language;
|
||||
|
||||
/**
|
||||
* Construct a new API instance. Does not do any networking, merely initialized
|
||||
* the local state. Multiple instances of this class may be held and used at the
|
||||
* same time without issue
|
||||
*
|
||||
* @param language Language to use for all queries
|
||||
*/
|
||||
public TCGDexAPI(Language language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
private String buildURL(String path, String... optional) {
|
||||
String result = String.format(API_URL, this.language.getAPIID(), path);
|
||||
// not gonna do a string builder here, because we intend this array to be of
|
||||
// length 1 in almost all cases
|
||||
for (String opt : optional) {
|
||||
result += "/" + opt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the image of a card
|
||||
* @param card Card to get image for
|
||||
* @param resolution High is recommended if the card is supposed to be readable and more than a thumbnail
|
||||
* @return BufferedImage loaded, possibly null if no image of this card exists for this language
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public BufferedImage getImage(CardResume card, ImageResolution resolution) throws IOException {
|
||||
String url = card.getImage() + "/" + resolution.forUseInURL() + ".png";
|
||||
return Utils.getImage(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list containing the core information for every core
|
||||
*
|
||||
* @return Resume of every card available
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public List<CardResume> getAllCards() throws IOException {
|
||||
String data = Utils.doGet(buildURL("cards"));
|
||||
return CardResume.parse(new JSONArray(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all known card illustrators
|
||||
*
|
||||
* @return List of all illustrators
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public List<String> getAllIllustrators() throws IOException {
|
||||
return loadStringArrayFrom("illustrators");
|
||||
}
|
||||
|
||||
public List<Integer> getAllPossibleHPValues() throws IOException {
|
||||
String data = Utils.doGet(buildURL("hp"));
|
||||
JSONArray json = new JSONArray(data);
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < json.length(); i++) {
|
||||
result.add(json.getInt(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list containing the core information regarding all series
|
||||
*
|
||||
* @return Resume of each series
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public List<SeriesResume> getAllSeries() throws IOException {
|
||||
String data = Utils.doGet(buildURL("series"));
|
||||
JSONArray json = new JSONArray(data);
|
||||
List<SeriesResume> result = new ArrayList<>();
|
||||
for (int i = 0; i < json.length(); i++) {
|
||||
result.add(new SeriesResume(json.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list containing the core information regarding all sets
|
||||
*
|
||||
* @return Resume of each set
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public List<SetResume> getAllSets() throws IOException {
|
||||
String data = Utils.doGet(buildURL("sets"));
|
||||
return SetResume.parse(new JSONArray(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a card based on its resume
|
||||
*
|
||||
* @param card Card to get info for
|
||||
* @return Card info obtained
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public CardInfo getCardInfo(CardResume card) throws IOException {
|
||||
return getCardInfo(card.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a card based on its globally unique identifier,
|
||||
* for example 'base4-1'
|
||||
*
|
||||
* @param globalCardID Globally unique ID of the card
|
||||
* @return Card info obtained
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public CardInfo getCardInfo(String globalCardID) throws IOException {
|
||||
String data = Utils.doGet(buildURL("cards", globalCardID));
|
||||
JSONObject json = new JSONObject(data);
|
||||
if (json.has("error")) {
|
||||
return null;
|
||||
}
|
||||
return new CardInfo(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a card based on a sets identifier and the
|
||||
* identifier/index of a card within this set. Note that for example 'base4-1'
|
||||
* is already a combined identifier, here the correct setID would be 'base4' and
|
||||
* the cardID '1'
|
||||
*
|
||||
* @param setID Unique ID of the set
|
||||
* @param cardID ID/index describing the card within the set
|
||||
* @return Card info obtained
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public CardInfo getCardInfo(String setID, String cardID) throws IOException {
|
||||
String data = Utils.doGet(buildURL("sets", setID, cardID));
|
||||
JSONObject json = new JSONObject(data);
|
||||
if (json.has("error")) {
|
||||
return null;
|
||||
}
|
||||
return new CardInfo(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a series based on a set belonging to it
|
||||
*
|
||||
* @param set Set the series belongs to
|
||||
* @return Detailed information of the series
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public SeriesInfo getSeriesInfo(SetInfo set) throws IOException {
|
||||
String data = Utils.doGet(buildURL("series", set.getSeries().getId()));
|
||||
return new SeriesInfo(new JSONObject(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a series based on its ID
|
||||
*
|
||||
* @param seriesID ID of the series
|
||||
* @return Detailed information of the series
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public SeriesInfo getSeriesInfo(String seriesID) throws IOException {
|
||||
String data = Utils.doGet(buildURL("series", seriesID));
|
||||
return new SeriesInfo(new JSONObject(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a set based on a card belonging to it
|
||||
*
|
||||
* @param setID ID of the set
|
||||
* @return Detailed information of the set
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public SetInfo getSetInfo(CardResume card) throws IOException {
|
||||
String id = card.getId();
|
||||
String data = Utils.doGet(buildURL("sets", id.substring(0, id.lastIndexOf("-"))));
|
||||
return new SetInfo(new JSONObject(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information of a set based on its ID
|
||||
*
|
||||
* @param setID ID of the set
|
||||
* @return Detailed information of the set
|
||||
* @throws IOException Thrown in response to any kind of networking error
|
||||
*/
|
||||
public SetInfo getSetInfo(String setID) throws IOException {
|
||||
String data = Utils.doGet(buildURL("sets", setID));
|
||||
return new SetInfo(new JSONObject(data));
|
||||
}
|
||||
|
||||
List<String> loadCategories() throws IOException {
|
||||
return loadStringArrayFrom("categories");
|
||||
}
|
||||
|
||||
List<String> loadRarities() throws IOException {
|
||||
return loadStringArrayFrom("rarities");
|
||||
}
|
||||
|
||||
private List<String> loadStringArrayFrom(String path) throws IOException {
|
||||
String data = Utils.doGet(buildURL(path));
|
||||
JSONArray json = new JSONArray(data);
|
||||
List<String> result = new ArrayList<>();
|
||||
for (int i = 0; i < json.length(); i++) {
|
||||
result.add(json.getString(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
List<String> loadTypes() throws IOException {
|
||||
return loadStringArrayFrom("types");
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
public enum Types {
|
||||
|
||||
PSYCHIC, FIGHTING, COLORLESS, LIGHTNING, GRASS, DRAGON, METAL, FIRE, WATER, DARKNESS, FAIRY;
|
||||
|
||||
static List<Types> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Types> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
Types type = parse(array.getString(i));
|
||||
if (type != null) {
|
||||
result.add(type);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Types parse(String raw) {
|
||||
try {
|
||||
return Types.valueOf(raw.toUpperCase().replace(" ", "_"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toPrettyString() {
|
||||
return Utils.prettifyEnumName(this);
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
class Utils {
|
||||
|
||||
static String doGet(String url) throws IOException {
|
||||
CloseableHttpClient client = null;
|
||||
CloseableHttpResponse response = null;
|
||||
|
||||
client = HttpClients.createDefault();
|
||||
HttpGet httpPost = new HttpGet(url);
|
||||
|
||||
response = client.execute(httpPost);
|
||||
|
||||
String output = null;
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||
String line = null;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
output = builder.toString();
|
||||
return output;
|
||||
}
|
||||
|
||||
public static BufferedImage getImage(String imageUrl) throws IOException {
|
||||
return ImageIO.read(new URL(imageUrl));
|
||||
}
|
||||
|
||||
public static String prettifyEnumName(Enum<?> enumInstance) {
|
||||
boolean space = true;
|
||||
String rawRepresentation = enumInstance.name();
|
||||
StringBuilder output = new StringBuilder(rawRepresentation.length());
|
||||
for (int i = 0; i < rawRepresentation.length(); i++) {
|
||||
String character = rawRepresentation.substring(i, i + 1);
|
||||
if (character.equals("_")) {
|
||||
output.append(" ");
|
||||
space = true;
|
||||
continue;
|
||||
}
|
||||
if (space) {
|
||||
// keep upper case
|
||||
space = false;
|
||||
output.append(character);
|
||||
} else {
|
||||
output.append(character.toLowerCase());
|
||||
}
|
||||
}
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Describes the weakness of a single pokemon, for example: 2x to Fire
|
||||
*
|
||||
*/
|
||||
public class Weakness {
|
||||
|
||||
static List<Weakness> parse(JSONArray array) {
|
||||
if (array == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Weakness> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
result.add(new Weakness(array.getJSONObject(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final Types type;
|
||||
private final String value;
|
||||
|
||||
|
||||
Weakness(JSONObject json) {
|
||||
this(Types.parse(json.getString("type")), json.optString("value"));
|
||||
}
|
||||
|
||||
Weakness(Types type, String value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Weakness)) {
|
||||
return false;
|
||||
}
|
||||
Weakness other = (Weakness) o;
|
||||
return Objects.deepEquals(new Object[] { this.type, this.value},
|
||||
new Object[] { other.type, other.value});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type the weakness is to
|
||||
*/
|
||||
public Types getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Descriptor of the weakness multiplier, including a leading x, for example 'x2'. May be null
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s", this.type, this.value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
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
|
||||
)
|
@ -1,169 +0,0 @@
|
||||
package net.tcgdex;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.time.Month;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.tcgdex.TCGDexAPI.ImageResolution;
|
||||
import net.tcgdex.TCGDexAPI.Language;
|
||||
|
||||
public class TestAPI {
|
||||
|
||||
private TCGDexAPI api;
|
||||
|
||||
@Before
|
||||
public void initAPI() {
|
||||
this.api = new TCGDexAPI(Language.EN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRarities() {
|
||||
assertEquals("Rare", Rarities.RARE.toPrettyString());
|
||||
assertEquals("Ultra Rare", Rarities.ULTRA_RARE.toPrettyString());
|
||||
assertEquals("Secret Rare", Rarities.SECRET_RARE.toPrettyString());
|
||||
assertEquals("Common", Rarities.COMMON.toPrettyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareRarityEnumToAPI() throws IOException {
|
||||
List<String> rarities = api.loadRarities();
|
||||
assertNotNull(rarities);
|
||||
assertEquals(rarities.size(), Rarities.values().length);
|
||||
for (String rawRarity : rarities) {
|
||||
Rarities rarity = Rarities.parse(rawRarity);
|
||||
assertNotNull(rarity);
|
||||
assert (rarity.toPrettyString().equals(rawRarity));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareCategoryEnumToAPI() throws IOException {
|
||||
List<String> categories = api.loadCategories();
|
||||
assertNotNull(categories);
|
||||
assertEquals(categories.size(), Categories.values().length);
|
||||
for (String rawCategory : categories) {
|
||||
Categories category = Categories.parse(rawCategory);
|
||||
assertNotNull(category);
|
||||
assert (category.toPrettyString().equals(rawCategory));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTypeEnumToAPI() throws IOException {
|
||||
List<String> types = api.loadTypes();
|
||||
assertNotNull(types);
|
||||
assertEquals(types.size(), Types.values().length);
|
||||
for (String rawType : types) {
|
||||
Types type = Types.parse(rawType);
|
||||
assertNotNull(type);
|
||||
assert (type.toPrettyString().equals(rawType));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHPAPI() throws IOException {
|
||||
List<Integer> hp = api.getAllPossibleHPValues();
|
||||
assertNotNull(hp);
|
||||
assert (hp.size() > 30);
|
||||
assert (hp.contains(60));
|
||||
assert (hp.contains(140));
|
||||
assert (hp.contains(320));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullCardInfo() throws IOException {
|
||||
CardInfo info = api.getCardInfo("base4", "1");
|
||||
assertNotNull(info);
|
||||
assertEquals(Categories.POKEMON, info.getCategory());
|
||||
assertEquals("base4-1", info.getId());
|
||||
assertEquals("Ken Sugimori", info.getIllustrator());
|
||||
assertEquals("1", info.getLocalId());
|
||||
assertEquals("Alakazam", info.getName());
|
||||
assertEquals(Rarities.RARE, info.getRarity());
|
||||
SetResume resume = info.getSet();
|
||||
assertNotNull(resume);
|
||||
assertEquals(130, resume.getOfficialCardCount());
|
||||
assertEquals(130, resume.getTotalCardCount());
|
||||
assertEquals("base4", resume.getId());
|
||||
assertEquals("Base Set 2", resume.getName());
|
||||
assertFalse(info.hasFirstEditionPic());
|
||||
assertTrue(info.hasHoloVariant());
|
||||
assertTrue(info.hasNormalVariant());
|
||||
assertTrue(info.hasReverseVariant());
|
||||
assertArrayEquals(new Integer[] { 65 }, info.getDexIDs().toArray());
|
||||
Attack attack = new Attack(Arrays.asList(Types.PSYCHIC, Types.PSYCHIC, Types.PSYCHIC), "Confuse Ray",
|
||||
"Flip a coin. If heads, the Defending Pokémon is now Confused.", "30");
|
||||
assertArrayEquals(new Attack[] { attack }, info.getAttacks().toArray());
|
||||
assertEquals(80, (int) info.getHp());
|
||||
assertArrayEquals(new Types[] { Types.PSYCHIC }, info.getTypes().toArray());
|
||||
Ability ability = new Ability("Poke-POWER", "Damage Swap",
|
||||
"As often as you like during your turn (before your attack), you may move 1 damage counter from 1 of your "
|
||||
+ "Pokémon to another as long as you don't Knock Out that Pokémon. This power can't be used if Alakazam is Asleep, "
|
||||
+ "Confused, or Paralyzed.");
|
||||
assertArrayEquals(new Ability[] { ability }, info.getAbilities().toArray());
|
||||
assertEquals("Stage2", info.getStage());
|
||||
assertEquals("Kadabra", info.getEvolveFrom());
|
||||
assertArrayEquals(new Weakness[] { new Weakness(Types.PSYCHIC, "×2") }, info.getWeakness().toArray());
|
||||
|
||||
// fetch a few more cards of different types to make sure there are no
|
||||
// exceptions due to weird combinations of fields missing
|
||||
assertNotNull(api.getCardInfo("sm10-183"));
|
||||
assertNotNull(api.getCardInfo("ex8-90"));
|
||||
assertNotNull(api.getCardInfo("swsh3-84"));
|
||||
assertNotNull(api.getCardInfo("swsh4-98"));
|
||||
assertNotNull(api.getCardInfo("ex13-96"));
|
||||
assertEquals("ex13", api.getSetInfo(api.getCardInfo("ex13-96")).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSets() throws IOException {
|
||||
SetInfo set = api.getSetInfo("sm10");
|
||||
assertNotNull(set);
|
||||
assertEquals(234, set.getCards().size());
|
||||
assertEquals(234, set.getOfficialCardCount());
|
||||
assertEquals(0, set.getReverseCardCount());
|
||||
assertEquals(0, set.getHoloCardCount());
|
||||
assertEquals(0, set.getFirstEdCardCount());
|
||||
assertEquals("Unbroken Bonds", set.getName());
|
||||
assertEquals(3, set.getReleaseDate().getDayOfMonth());
|
||||
assertEquals(Month.MAY, set.getReleaseDate().getMonth());
|
||||
assertEquals("UNB", set.getTcgOnlineCode());
|
||||
assertEquals("Sun & Moon", set.getSeries().getName());
|
||||
assertTrue(set.isLegalInExpanded());
|
||||
assertFalse(set.isLegalInStandard());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeries() throws IOException {
|
||||
SeriesInfo info = api.getSeriesInfo("sm");
|
||||
assertEquals("sm", info.getId());
|
||||
assertEquals("Sun & Moon", info.getName());
|
||||
assertEquals(18, info.getSets().size());
|
||||
assertEquals("Shining Legends", info.getSets().get(4).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImage() throws IOException {
|
||||
CardInfo info = api.getCardInfo("base4", "1");
|
||||
BufferedImage high = api.getImage(info, ImageResolution.HIGH);
|
||||
assertNotNull(high);
|
||||
assertEquals(825, high.getHeight());
|
||||
assertEquals(600, high.getWidth());
|
||||
BufferedImage low = api.getImage(info, ImageResolution.LOW);
|
||||
assertNotNull(low);
|
||||
assertEquals(337, low.getHeight());
|
||||
assertEquals(245, low.getWidth());
|
||||
}
|
||||
|
||||
}
|
52
src/test/kotlin/net/tcgdex/sdk/APITest.kt
Normal file
52
src/test/kotlin/net/tcgdex/sdk/APITest.kt
Normal file
@ -0,0 +1,52 @@
|
||||
package net.tcgdex.sdk
|
||||
|
||||
import java.io.IOException
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class APITest {
|
||||
private lateinit var api: TCGdex
|
||||
@BeforeTest
|
||||
fun initAPI() {
|
||||
api = TCGdex("en")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testFullCardInfo() {
|
||||
assertNotNull(api.fetchCards())
|
||||
assertNotNull(api.fetchCard("swsh3-136"))
|
||||
assertNotNull(api.fetchCard("swsh3", "136"))
|
||||
assertNotNull(api.fetchSet("swsh3"))
|
||||
assertNotNull(api.fetchSets())
|
||||
assertNotNull(api.fetchSerie("swsh"))
|
||||
assertNotNull(api.fetchSeries())
|
||||
assertNotNull(api.fetchTypes())
|
||||
assertNotNull(api.fetchType("Colorless"))
|
||||
assertNotNull(api.fetchRetreats())
|
||||
assertNotNull(api.fetchRetreat("1"))
|
||||
assertNotNull(api.fetchRarities())
|
||||
assertNotNull(api.fetchRarity("Uncommon"))
|
||||
assertNotNull(api.fetchIllustrators())
|
||||
assertNotNull(api.fetchIllustrator("tetsuya koizumi"))
|
||||
assertNotNull(api.fetchHPs())
|
||||
assertNotNull(api.fetchHP("110"))
|
||||
assertNotNull(api.fetchCategories())
|
||||
assertNotNull(api.fetchCategory("Pokemon"))
|
||||
assertNotNull(api.fetchDexIds())
|
||||
assertNotNull(api.fetchDexId("162"))
|
||||
assertNotNull(api.fetchEnergyTypes())
|
||||
assertNotNull(api.fetchEnergyType("Special"))
|
||||
assertNotNull(api.fetchRegulationMarks())
|
||||
assertNotNull(api.fetchRegulationMark("D"))
|
||||
assertNotNull(api.fetchStages())
|
||||
assertNotNull(api.fetchStage("Basic"))
|
||||
assertNotNull(api.fetchSuffixes())
|
||||
assertNotNull(api.fetchSuffix("EX"))
|
||||
assertNotNull(api.fetchTrainerTypes())
|
||||
assertNotNull(api.fetchTrainerType("Tool"))
|
||||
assertNotNull(api.fetchVariants())
|
||||
assertNotNull(api.fetchVariant("holo"))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user