Search in sources :

Example 6 with MagicRuling

use of org.magic.api.beans.MagicRuling in project MtgDesktopCompanion by nicho92.

the class ScryFallProvider method generateRules.

private void generateRules(MagicCard mc) throws IOException {
    String url = "https://api.scryfall.com/cards/" + mc.getId() + "/rulings";
    HttpURLConnection con = (HttpURLConnection) getConnection(url);
    JsonElement el = parser.parse(new JsonReader(new InputStreamReader(con.getInputStream(), encoding)));
    JsonArray arr = el.getAsJsonObject().get("data").getAsJsonArray();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obr = arr.get(i).getAsJsonObject();
        MagicRuling rul = new MagicRuling();
        rul.setDate(obr.get("published_at").getAsString());
        rul.setText(obr.get("comment").getAsString());
        mc.getRulings().add(rul);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) MagicRuling(org.magic.api.beans.MagicRuling)

Aggregations

MagicRuling (org.magic.api.beans.MagicRuling)6 MagicCard (org.magic.api.beans.MagicCard)4 MagicCardNames (org.magic.api.beans.MagicCardNames)3 MagicEdition (org.magic.api.beans.MagicEdition)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 MagicFormat (org.magic.api.beans.MagicFormat)2 JsonReader (com.google.gson.stream.JsonReader)1 Configuration (com.jayway.jsonpath.Configuration)1 JsonPath (com.jayway.jsonpath.JsonPath)1 Option (com.jayway.jsonpath.Option)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 ReadContext (com.jayway.jsonpath.ReadContext)1 CacheProvider (com.jayway.jsonpath.spi.cache.CacheProvider)1 LRUCache (com.jayway.jsonpath.spi.cache.LRUCache)1