mirror of
https://github.com/tcgdex/java-sdk.git
synced 2025-04-22 10:52:14 +00:00
Slightly more API
This commit is contained in:
parent
fb49f92735
commit
5295ec2b3b
@ -10,12 +10,8 @@ import org.json.JSONObject;
|
|||||||
* Full description of a card, including all information available about it
|
* 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 String illustrator;
|
||||||
private final Rarities rarity;
|
private final Rarities rarity;
|
||||||
private final Categories category;
|
private final Categories category;
|
||||||
@ -43,11 +39,7 @@ public class CardInfo {
|
|||||||
boolean hasFirstEditionPic, SetResume set, List<Integer> dexIDs, Integer hp, List<Types> types,
|
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,
|
String evolveFrom, String description, String level, String stage, String suffix, List<Attack> attacks,
|
||||||
List<Weakness> weakness, List<Ability> abilities, Integer retreat, String regulationMark) {
|
List<Weakness> weakness, List<Ability> abilities, Integer retreat, String regulationMark) {
|
||||||
super();
|
super(id, localId, name, image);
|
||||||
this.id = id;
|
|
||||||
this.localId = localId;
|
|
||||||
this.name = name;
|
|
||||||
this.image = image;
|
|
||||||
this.illustrator = illustrator;
|
this.illustrator = illustrator;
|
||||||
this.rarity = rarity;
|
this.rarity = rarity;
|
||||||
this.category = category;
|
this.category = category;
|
||||||
@ -72,11 +64,8 @@ public class CardInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CardInfo(JSONObject json) {
|
CardInfo(JSONObject json) {
|
||||||
this.id = json.getString("id");
|
super(json);
|
||||||
this.localId = json.getString("localId");
|
|
||||||
this.illustrator = json.getString("illustrator");
|
this.illustrator = json.getString("illustrator");
|
||||||
this.name = json.getString("name");
|
|
||||||
this.image = json.getString("name");
|
|
||||||
this.rarity = Rarities.parse(json.getString("rarity"));
|
this.rarity = Rarities.parse(json.getString("rarity"));
|
||||||
this.category = Categories.parse(json.getString("category"));
|
this.category = Categories.parse(json.getString("category"));
|
||||||
JSONObject variantSection = json.getJSONObject("variants");
|
JSONObject variantSection = json.getJSONObject("variants");
|
||||||
@ -143,38 +132,6 @@ public class CardInfo {
|
|||||||
return retreat;
|
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
|
* @return Card illustrator
|
||||||
|
@ -2,7 +2,6 @@ package com.github.maxopoly.tcgdex;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -122,6 +122,18 @@ public class TCGDexAPI {
|
|||||||
return new SeriesInfo(new JSONObject(data));
|
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
|
* Gets detailed information of a set based on its ID
|
||||||
*
|
*
|
||||||
@ -134,6 +146,19 @@ public class TCGDexAPI {
|
|||||||
return new SetInfo(new JSONObject(data));
|
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<String> loadRarities() throws IOException {
|
List<String> loadRarities() throws IOException {
|
||||||
return loadStringArrayFrom("rarities");
|
return loadStringArrayFrom("rarities");
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@ public class TestAPI {
|
|||||||
assertNotNull(api.getCardInfo("swsh3-84"));
|
assertNotNull(api.getCardInfo("swsh3-84"));
|
||||||
assertNotNull(api.getCardInfo("swsh4-98"));
|
assertNotNull(api.getCardInfo("swsh4-98"));
|
||||||
assertNotNull(api.getCardInfo("ex13-96"));
|
assertNotNull(api.getCardInfo("ex13-96"));
|
||||||
|
assertEquals("ex13", api.getSetInfo(api.getCardInfo("ex13-96")).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user