From 5295ec2b3bd7dde0e0dde518359fd599fd69a82b Mon Sep 17 00:00:00 2001 From: Maxopoly Date: Thu, 4 Nov 2021 17:18:02 +0100 Subject: [PATCH] Slightly more API --- .../com/github/maxopoly/tcgdex/CardInfo.java | 49 ++----------------- .../com/github/maxopoly/tcgdex/SetInfo.java | 1 - .../com/github/maxopoly/tcgdex/TCGDexAPI.java | 25 ++++++++++ .../com/github/maxopoly/tcgdex/TestAPI.java | 1 + 4 files changed, 29 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java b/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java index be60899..b746557 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java +++ b/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java @@ -10,12 +10,8 @@ import org.json.JSONObject; * Full description of a card, including all information available about it * */ -public class CardInfo { +public class CardInfo extends CardResume { - private final String id; - private final String localId; - private final String name; - private final String image; private final String illustrator; private final Rarities rarity; private final Categories category; @@ -43,11 +39,7 @@ public class CardInfo { boolean hasFirstEditionPic, SetResume set, List dexIDs, Integer hp, List types, String evolveFrom, String description, String level, String stage, String suffix, List attacks, List weakness, List abilities, Integer retreat, String regulationMark) { - super(); - this.id = id; - this.localId = localId; - this.name = name; - this.image = image; + super(id, localId, name, image); this.illustrator = illustrator; this.rarity = rarity; this.category = category; @@ -72,11 +64,8 @@ public class CardInfo { } CardInfo(JSONObject json) { - this.id = json.getString("id"); - this.localId = json.getString("localId"); + super(json); this.illustrator = json.getString("illustrator"); - this.name = json.getString("name"); - this.image = json.getString("name"); this.rarity = Rarities.parse(json.getString("rarity")); this.category = Categories.parse(json.getString("category")); JSONObject variantSection = json.getJSONObject("variants"); @@ -143,38 +132,6 @@ public class CardInfo { return retreat; } - /** - * - * @return Card unique ID - */ - public String getId() { - return id; - } - - /** - * - * @return Card set ID - */ - public String getLocalId() { - return localId; - } - - /** - * - * @return Card name - */ - public String getName() { - return name; - } - - /** - * - * @return Image URL, may be null - */ - public String getImage() { - return image; - } - /** * * @return Card illustrator diff --git a/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java b/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java index 2268afd..5b1bbb7 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java +++ b/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java @@ -2,7 +2,6 @@ package com.github.maxopoly.tcgdex; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.util.Date; import java.util.List; import org.json.JSONObject; diff --git a/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java b/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java index 6bcc2b6..5ff4f0b 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java +++ b/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java @@ -121,6 +121,18 @@ public class TCGDexAPI { String data = Utils.doGet(buildURL("series", seriesID)); return new SeriesInfo(new JSONObject(data)); } + + /** + * 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 set based on its ID @@ -133,6 +145,19 @@ public class TCGDexAPI { String data = Utils.doGet(buildURL("sets", setID)); return new SetInfo(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)); + } List loadRarities() throws IOException { return loadStringArrayFrom("rarities"); diff --git a/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java b/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java index 1033757..30dd848 100644 --- a/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java +++ b/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java @@ -118,6 +118,7 @@ public class TestAPI { 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