aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/query
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2015-06-04 20:57:10 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2015-06-04 20:57:10 +0200
commit1f0159bcf903c0f422ab47b07cd296da1e816f87 (patch)
tree237ea7d5a71313cc0bb4db850174a76462de35cb /src/eu/equalparts/cardbase/query
parent129cfbf8d5afec5725a88835869203a8825de22a (diff)
Made a plan, now i'm following it. CLI is well under way
Diffstat (limited to 'src/eu/equalparts/cardbase/query')
-rw-r--r--src/eu/equalparts/cardbase/query/IO.java43
-rw-r--r--src/eu/equalparts/cardbase/query/Test.java9
2 files changed, 47 insertions, 5 deletions
diff --git a/src/eu/equalparts/cardbase/query/IO.java b/src/eu/equalparts/cardbase/query/IO.java
new file mode 100644
index 0000000..65a3a34
--- /dev/null
+++ b/src/eu/equalparts/cardbase/query/IO.java
@@ -0,0 +1,43 @@
+package eu.equalparts.cardbase.query;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import eu.equalparts.cardbase.data.CardBase;
+import eu.equalparts.cardbase.data.CardSet;
+import eu.equalparts.cardbase.data.MetaCardSet;
+
+public class IO {
+
+ public static final String BASE_URL = "http://mtgjson.com/json/";
+ public static final String SETS_URL = BASE_URL + "SetList.json";
+
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ public static CardSet getCardSet(String setId) {
+ return new CardSet();
+ }
+
+ public static ArrayList<MetaCardSet> getAllMetaSets() throws JsonParseException, JsonMappingException, IOException {
+ //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return mapper.readValue(new URL(SETS_URL), new TypeReference<ArrayList<MetaCardSet>>() {});
+ }
+
+ public static CardBase readCardBase(File file) throws JsonParseException, JsonMappingException, IOException {
+ return mapper.readValue(file, CardBase.class);
+ }
+
+ public static void writeCardBase(File file, CardBase cardBase) throws JsonGenerationException, JsonMappingException, IOException {
+ mapper.writeValue(file, cardBase);
+ }
+
+}
diff --git a/src/eu/equalparts/cardbase/query/Test.java b/src/eu/equalparts/cardbase/query/Test.java
index 646139e..2050c76 100644
--- a/src/eu/equalparts/cardbase/query/Test.java
+++ b/src/eu/equalparts/cardbase/query/Test.java
@@ -7,7 +7,6 @@ import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -50,7 +49,7 @@ public class Test {
// @SuppressWarnings("unchecked")
CardSet set = mapper.readValue(new File("M15.json"), CardSet.class);
- System.out.println(set.getCardByNumber("281").getName());
+ System.out.println(set.getCardByNumber("281").name);
}
@@ -58,9 +57,9 @@ public class Test {
List<Card> allCards = new ArrayList<Card>();
for (CardSet set : sets.values()) {
- for (Card card : set.getCards()) {
- card.setSetCode(set.getCode());
- card.setSetName(set.getName());
+ for (Card card : set.cards) {
+ card.setCode = set.code;
+ card.setName = set.name;
// System.out.println(set.getName() + ": " + card.getName());
allCards.add(card);