├── .gitignore
├── .travis.yml
├── stubby
├── json
│ ├── types
│ │ ├── supertypes.json
│ │ ├── types.json
│ │ └── subtypes.json
│ ├── sets
│ │ ├── DRK.json
│ │ ├── LEA.json
│ │ └── LEB.json
│ └── cards
│ │ ├── GiftsGiven.json
│ │ ├── 10.json
│ │ ├── 926234c2fe8863f49220a878346c4c5ca79b6046.json
│ │ ├── 1.json
│ │ ├── 8a5d85644f546525433c4472b76c3b0ebb495b33.json
│ │ ├── ffa00e95-754e-5484-8e4c-e3b707d4c1d2.json
│ │ ├── NicolBolasTheArisen.json
│ │ └── DRKpage2.json
└── stubby-config.yaml
├── stubby-config.yaml
├── src
├── main
│ └── java
│ │ └── io
│ │ └── magicthegathering
│ │ └── javasdk
│ │ ├── exception
│ │ └── HttpRequestFailedException.java
│ │ ├── resource
│ │ ├── Legality.java
│ │ ├── Ruling.java
│ │ ├── ForeignData.java
│ │ ├── MtgSet.java
│ │ └── Card.java
│ │ └── api
│ │ ├── CardAPI.java
│ │ ├── SetAPI.java
│ │ └── MTGAPI.java
└── test
│ └── java
│ └── io
│ └── magicthegathering
│ └── javasdk
│ └── api
│ ├── MTGAPITest.java
│ ├── SetAPITest.java
│ └── CardAPITest.java
├── LICENSE
├── README.md
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
3 | /.settings/
4 | .project
5 | .classpath
6 | settings.xml
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | dist: trusty
4 |
5 | jdk: openjdk7
6 |
7 | install: mvn install -DskipTests -Dgpg.skip
8 |
--------------------------------------------------------------------------------
/stubby/json/types/supertypes.json:
--------------------------------------------------------------------------------
1 | {
2 | "supertypes": [
3 | "Basic",
4 | "Legendary",
5 | "Ongoing",
6 | "Snow",
7 | "World"
8 | ]
9 | }
--------------------------------------------------------------------------------
/stubby-config.yaml:
--------------------------------------------------------------------------------
1 | - request:
2 | url: /cards/-1
3 | method: GET
4 | response:
5 | headers:
6 | Content-Type: application/json
7 | latency: 1000
8 | status: 200
9 | body:
--------------------------------------------------------------------------------
/stubby/json/types/types.json:
--------------------------------------------------------------------------------
1 | {
2 | "types": [
3 | "Artifact",
4 | "Conspiracy",
5 | "Creature",
6 | "Enchantment",
7 | "Instant",
8 | "Land",
9 | "Phenomenon",
10 | "Plane",
11 | "Planeswalker",
12 | "Scheme",
13 | "Sorcery",
14 | "Tribal",
15 | "Vanguard"
16 | ]
17 | }
--------------------------------------------------------------------------------
/stubby/json/sets/DRK.json:
--------------------------------------------------------------------------------
1 | {
2 | "set": {
3 | "code": "DRK",
4 | "name": "The Dark",
5 | "type": "expansion",
6 | "border": "black",
7 | "mkm_id": 8,
8 | "booster": [
9 | "uncommon",
10 | "uncommon",
11 | "common",
12 | "common",
13 | "common",
14 | "common",
15 | "common",
16 | "common"
17 | ],
18 | "mkm_name": "The Dark",
19 | "releaseDate": "1994-08-08",
20 | "gathererCode": "DK",
21 | "magicCardsInfoCode": "dk"
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/exception/HttpRequestFailedException.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.exception;
2 |
3 | import io.magicthegathering.javasdk.api.MTGAPI;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | * Thrown by {@link MTGAPI} when an http request to magicthegathering.io API fails to return anything.
9 | *
10 | * @author nniklas
11 | *
12 | */
13 | public class HttpRequestFailedException extends RuntimeException {
14 |
15 | public HttpRequestFailedException(IOException e) {
16 | super(e);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/stubby/json/sets/LEA.json:
--------------------------------------------------------------------------------
1 | {
2 | "set": {
3 | "code": "LEA",
4 | "name": "Limited Edition Alpha",
5 | "type": "core",
6 | "border": "black",
7 | "mkm_id": 1,
8 | "booster": [
9 | "rare",
10 | "uncommon",
11 | "uncommon",
12 | "uncommon",
13 | "common",
14 | "common",
15 | "common",
16 | "common",
17 | "common",
18 | "common",
19 | "common",
20 | "common",
21 | "common",
22 | "common",
23 | "common"
24 | ],
25 | "mkm_name": "Alpha",
26 | "releaseDate": "1993-08-05",
27 | "gathererCode": "1E",
28 | "magicCardsInfoCode": "al"
29 | }
30 | }
--------------------------------------------------------------------------------
/stubby/json/sets/LEB.json:
--------------------------------------------------------------------------------
1 | {
2 | "set": {
3 | "code": "LEB",
4 | "name": "Limited Edition Beta",
5 | "type": "core",
6 | "border": "black",
7 | "mkm_id": 2,
8 | "booster": [
9 | "rare",
10 | "uncommon",
11 | "uncommon",
12 | "uncommon",
13 | "common",
14 | "common",
15 | "common",
16 | "common",
17 | "common",
18 | "common",
19 | "common",
20 | "common",
21 | "common",
22 | "common",
23 | "common"
24 | ],
25 | "mkm_name": "Beta",
26 | "releaseDate": "1993-10-01",
27 | "gathererCode": "2E",
28 | "magicCardsInfoCode": "be"
29 | }
30 | }
--------------------------------------------------------------------------------
/src/test/java/io/magicthegathering/javasdk/api/MTGAPITest.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.api;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 |
6 | import by.stub.client.StubbyClient;
7 |
8 | /**
9 | * Base class for unit tests. Takes care of starting and stopping a stubby4j
10 | * server to simulate the magicthegathering.io REST APIs locally.
11 | *
12 | * @author nniklas
13 | *
14 | */
15 | public class MTGAPITest {
16 | private StubbyClient stubbyClient;
17 |
18 | @Before
19 | public void initStubby() throws Exception {
20 | stubbyClient = new StubbyClient();
21 | stubbyClient.startJetty("stubby/stubby-config.yaml");
22 | MTGAPI.ENDPOINT = "http://localhost:8882";
23 | }
24 |
25 | @After
26 | public void teardownStubby() throws Exception {
27 | stubbyClient.stopJetty();
28 | // TODO Remove when all tests use stubby instead of real http calls
29 | MTGAPI.ENDPOINT = "https://api.magicthegathering.io/v1";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stubby/json/cards/GiftsGiven.json:
--------------------------------------------------------------------------------
1 | {
2 | "cards": [
3 | {
4 | "name": "Gifts Given",
5 | "manaCost": "{3}{U}",
6 | "cmc": 4,
7 | "colors": [
8 | "Blue"
9 | ],
10 | "colorIdentity": [
11 | "U"
12 | ],
13 | "type": "Instant",
14 | "types": [
15 | "Instant"
16 | ],
17 | "rarity": "Special",
18 | "set": "pHHO",
19 | "setName": "Happy Holidays",
20 | "text": "Search target opponent's library for four cards with different names and reveal them. That player chooses two of those cards. Put the chosen cards into the player's graveyard and the rest into your hand. Then that player shuffles his or her library.",
21 | "flavor": "\"Thanks! You shouldn't have.\"",
22 | "artist": "Jason Chan",
23 | "number": "2",
24 | "layout": "normal",
25 | "releaseDate": "2007",
26 | "printings": [
27 | "pHHO"
28 | ],
29 | "source": "Holiday gift to Wizards internal teams and business partners.",
30 | "id": "689dd21260c8e01942e248e560ee3928ee56aa77"
31 | }
32 | ]
33 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 magicthegathering.io
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/resource/Legality.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.resource;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * This file is part of mtgsdk.
7 | * https://github.com/MagicTheGathering/mtg-sdk-java
8 | *
9 | * Licensed under the MIT license:
10 | * http://www.opensource.org/licenses/MIT-license
11 | *
12 | * Created by thechucklingatom on 5/8/2017.
13 | *
14 | * The Legality sub object in the card json object.
15 | *
16 | * @author thechucklingatom
17 | *
18 | */
19 | public class Legality implements Serializable{
20 | private String format;
21 | private String legality;
22 |
23 | public String getFormat() {
24 | return format;
25 | }
26 |
27 | public void setFormat(String format) {
28 | this.format = format;
29 | }
30 |
31 | public String getLegality() {
32 | return legality;
33 | }
34 |
35 | public void setLegality(String legality) {
36 | this.legality = legality;
37 | }
38 |
39 | @Override
40 | public boolean equals(Object o){
41 | if(o instanceof Legality){
42 | return ((Legality) o).getFormat().equals(format)
43 | && ((Legality) o).getLegality().equals(legality);
44 | }else{
45 | return false;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/resource/Ruling.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.resource;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * This file is part of mtgsdk.
7 | * https://github.com/MagicTheGathering/mtg-sdk-java
8 | *
9 | * Licensed under the MIT license:
10 | * http://www.opensource.org/licenses/MIT-license
11 | *
12 | * Created by BeMacized on 7/23/2017.
13 | *
14 | * The Ruling sub object in the card json object.
15 | *
16 | * @author BeMacized
17 | */
18 | public class Ruling implements Serializable {
19 |
20 | private String date;
21 | private String text;
22 |
23 | public String getDate() {
24 | return date;
25 | }
26 |
27 | public void setDate(String date) {
28 | this.date = date;
29 | }
30 |
31 | public String getText() {
32 | return text;
33 | }
34 |
35 | public void setText(String text) {
36 | this.text = text;
37 | }
38 |
39 | @Override
40 | public boolean equals(Object o) {
41 | if (this == o) return true;
42 | if (o == null || getClass() != o.getClass()) return false;
43 |
44 | Ruling ruling = (Ruling) o;
45 |
46 | if (date != null ? !date.equals(ruling.date) : ruling.date != null) return false;
47 | return text != null ? text.equals(ruling.text) : ruling.text == null;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/stubby/json/cards/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "card": {
3 | "name": "Crystal Rod",
4 | "manaCost": "{1}",
5 | "cmc": 1,
6 | "type": "Artifact",
7 | "types": [
8 | "Artifact"
9 | ],
10 | "rarity": "Uncommon",
11 | "set": "LEA",
12 | "setName": "Limited Edition Alpha",
13 | "text": "Whenever a player casts a blue spell, you may pay {1}. If you do, you gain 1 life.",
14 | "artist": "Amy Weber",
15 | "layout": "normal",
16 | "multiverseid": 10,
17 | "imageUrl": "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=10&type=card",
18 | "printings": [
19 | "LEA",
20 | "LEB",
21 | "2ED",
22 | "CED",
23 | "CEI",
24 | "3ED",
25 | "4ED",
26 | "5ED",
27 | "6ED",
28 | "7ED",
29 | "8ED"
30 | ],
31 | "originalText": "{1}: Any blue spell cast by any player gives you 1 life.",
32 | "originalType": "Poly Artifact",
33 | "legalities": [
34 | {
35 | "format": "Commander",
36 | "legality": "Legal"
37 | },
38 | {
39 | "format": "Legacy",
40 | "legality": "Legal"
41 | },
42 | {
43 | "format": "Modern",
44 | "legality": "Legal"
45 | },
46 | {
47 | "format": "Vintage",
48 | "legality": "Legal"
49 | }
50 | ],
51 | "id": "5c02996ce42975e3835d47c06b044e974835b511"
52 | }
53 | }
--------------------------------------------------------------------------------
/stubby/json/cards/926234c2fe8863f49220a878346c4c5ca79b6046.json:
--------------------------------------------------------------------------------
1 | {
2 | "card": {
3 | "name": "Air Elemental",
4 | "manaCost": "{3}{U}{U}",
5 | "cmc": 5,
6 | "colors": [
7 | "Blue"
8 | ],
9 | "colorIdentity": [
10 | "U"
11 | ],
12 | "type": "Creature — Elemental",
13 | "types": [
14 | "Creature"
15 | ],
16 | "subtypes": [
17 | "Elemental"
18 | ],
19 | "rarity": "Uncommon",
20 | "set": "LEA",
21 | "setName": "Limited Edition Alpha",
22 | "text": "Flying",
23 | "flavor": "These spirits of the air are winsome and wild, and cannot be truly contained. Only marginally intelligent, they often substitute whimsy for strategy, delighting in mischief and mayhem.",
24 | "artist": "Richard Thomas",
25 | "power": "4",
26 | "toughness": "4",
27 | "layout": "normal",
28 | "multiverseid": 94,
29 | "imageUrl": "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=94&type=card",
30 | "printings": [
31 | "LEA",
32 | "LEB",
33 | "2ED",
34 | "CED",
35 | "CEI",
36 | "3ED",
37 | "4ED",
38 | "5ED",
39 | "PO2",
40 | "6ED",
41 | "S99",
42 | "BRB",
43 | "BTD",
44 | "7ED",
45 | "8ED",
46 | "9ED",
47 | "10E",
48 | "DD2",
49 | "M10",
50 | "DPA",
51 | "ME4",
52 | "DD3_JVC"
53 | ],
54 | "originalText": "Flying",
55 | "originalType": "Summon — Elemental",
56 | "legalities": [
57 | {
58 | "format": "Commander",
59 | "legality": "Legal"
60 | },
61 | {
62 | "format": "Legacy",
63 | "legality": "Legal"
64 | },
65 | {
66 | "format": "Modern",
67 | "legality": "Legal"
68 | },
69 | {
70 | "format": "Vintage",
71 | "legality": "Legal"
72 | }
73 | ],
74 | "id": "926234c2fe8863f49220a878346c4c5ca79b6046"
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/resource/ForeignData.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.resource;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * This file is part of mtgsdk.
7 | * https://github.com/MagicTheGathering/mtg-sdk-java
8 | *
9 | * Licensed under the MIT license:
10 | * http://www.opensource.org/licenses/MIT-license
11 | *
12 | * Created by thechucklingatom on 4/07/2019.
13 | *
14 | * Foreign Data class that is created from the JSON set representation.
15 | *
16 | * @author thechucklingatom
17 | */
18 | public class ForeignData implements Serializable {
19 | private String name;
20 | private String text;
21 | private String flavor;
22 | private String imageUrl;
23 | private String language;
24 | private int multiverseId;
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public String getText() {
35 | return text;
36 | }
37 |
38 | public void setText(String text) {
39 | this.text = text;
40 | }
41 |
42 | public String getFlavor() {
43 | return flavor;
44 | }
45 |
46 | public void setFlavor(String flavor) {
47 | this.flavor = flavor;
48 | }
49 |
50 | public String getImageUrl() {
51 | return imageUrl;
52 | }
53 |
54 | public void setImageUrl(String imageUrl) {
55 | this.imageUrl = imageUrl;
56 | }
57 |
58 | public String getLanguage() {
59 | return language;
60 | }
61 |
62 | public void setLanguage(String language) {
63 | this.language = language;
64 | }
65 |
66 | public int getMultiverseId() {
67 | return multiverseId;
68 | }
69 |
70 | public void setMultiverseId(int multiverseId) {
71 | this.multiverseId = multiverseId;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/stubby/json/cards/1.json:
--------------------------------------------------------------------------------
1 | {
2 | "card": {
3 | "name": "Ankh of Mishra",
4 | "manaCost": "{2}",
5 | "cmc": 2,
6 | "type": "Artifact",
7 | "types": [
8 | "Artifact"
9 | ],
10 | "rarity": "Rare",
11 | "set": "LEA",
12 | "setName": "Limited Edition Alpha",
13 | "text": "Whenever a land enters the battlefield, Ankh of Mishra deals 2 damage to that land's controller.",
14 | "artist": "Amy Weber",
15 | "layout": "normal",
16 | "multiverseid": 1,
17 | "imageUrl": "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=1&type=card",
18 | "rulings": [
19 | {
20 | "date": "2004-10-04",
21 | "text": "This triggers on any land entering the battlefield. This includes playing a land or putting a land onto the battlefield using a spell or ability."
22 | },
23 | {
24 | "date": "2004-10-04",
25 | "text": "It determines the land’s controller at the time the ability resolves. If the land leaves the battlefield before the ability resolves, the land’s last controller before it left is used."
26 | }
27 | ],
28 | "printings": [
29 | "LEA",
30 | "LEB",
31 | "2ED",
32 | "CED",
33 | "CEI",
34 | "3ED",
35 | "4ED",
36 | "5ED",
37 | "6ED",
38 | "MED",
39 | "VMA"
40 | ],
41 | "originalText": "Ankh does 2 damage to anyone who puts a new land into play.",
42 | "originalType": "Continuous Artifact",
43 | "legalities": [
44 | {
45 | "format": "Commander",
46 | "legality": "Legal"
47 | },
48 | {
49 | "format": "Legacy",
50 | "legality": "Legal"
51 | },
52 | {
53 | "format": "Vintage",
54 | "legality": "Legal"
55 | }
56 | ],
57 | "id": "8a5d85644f546525433c4472b76c3b0ebb495b33"
58 | }
59 | }
--------------------------------------------------------------------------------
/stubby/json/cards/8a5d85644f546525433c4472b76c3b0ebb495b33.json:
--------------------------------------------------------------------------------
1 | {
2 | "card": {
3 | "name": "Ankh of Mishra",
4 | "manaCost": "{2}",
5 | "cmc": 2,
6 | "type": "Artifact",
7 | "types": [
8 | "Artifact"
9 | ],
10 | "rarity": "Rare",
11 | "set": "LEA",
12 | "setName": "Limited Edition Alpha",
13 | "text": "Whenever a land enters the battlefield, Ankh of Mishra deals 2 damage to that land's controller.",
14 | "artist": "Amy Weber",
15 | "layout": "normal",
16 | "multiverseid": 1,
17 | "imageUrl": "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=1&type=card",
18 | "rulings": [
19 | {
20 | "date": "2004-10-04",
21 | "text": "This triggers on any land entering the battlefield. This includes playing a land or putting a land onto the battlefield using a spell or ability."
22 | },
23 | {
24 | "date": "2004-10-04",
25 | "text": "It determines the land’s controller at the time the ability resolves. If the land leaves the battlefield before the ability resolves, the land’s last controller before it left is used."
26 | }
27 | ],
28 | "printings": [
29 | "LEA",
30 | "LEB",
31 | "2ED",
32 | "CED",
33 | "CEI",
34 | "3ED",
35 | "4ED",
36 | "5ED",
37 | "6ED",
38 | "MED",
39 | "VMA"
40 | ],
41 | "originalText": "Ankh does 2 damage to anyone who puts a new land into play.",
42 | "originalType": "Continuous Artifact",
43 | "legalities": [
44 | {
45 | "format": "Commander",
46 | "legality": "Legal"
47 | },
48 | {
49 | "format": "Legacy",
50 | "legality": "Legal"
51 | },
52 | {
53 | "format": "Vintage",
54 | "legality": "Legal"
55 | }
56 | ],
57 | "id": "8a5d85644f546525433c4472b76c3b0ebb495b33"
58 | }
59 | }
--------------------------------------------------------------------------------
/src/test/java/io/magicthegathering/javasdk/api/SetAPITest.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.api;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import io.magicthegathering.javasdk.resource.Card;
9 | import io.magicthegathering.javasdk.resource.MtgSet;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertFalse;
13 | import static org.junit.Assert.assertNotEquals;
14 | import static org.junit.Assert.assertNotNull;
15 | import static org.junit.Assert.assertNull;
16 | import static org.junit.Assert.assertTrue;
17 |
18 | public class SetAPITest extends MTGAPITest {
19 | @Test
20 | public void testGetSet() {
21 | MtgSet testSet = new MtgSet();
22 | testSet.setGatherercode("1E");
23 | assertEquals(testSet, SetAPI.getSet("LEA"));
24 | assertNotEquals(testSet, SetAPI.getSet("LEB"));
25 | }
26 |
27 | @Test
28 | public void testBadSetId() {
29 | assertNull(SetAPI.getSet("666"));
30 | }
31 |
32 | @Test
33 | public void testGetAllSets() {
34 | List testSetList = SetAPI.getAllSets();
35 | MtgSet testSet = new MtgSet();
36 | testSet.setGatherercode("1E");
37 | assertEquals(testSetList.get(0), testSet);
38 | }
39 |
40 | @Test
41 | public void testGetBoosterFromSet() {
42 | String setCode = "KLD";
43 | List booster = SetAPI.getBooster(setCode);
44 | assertEquals(15, booster.size());
45 | }
46 |
47 | @Test
48 | public void testSetFilter(){
49 | ArrayList filter = new ArrayList<>();
50 | filter.add("name=Alpha");
51 |
52 | MtgSet alpha = SetAPI.getSet("LEA");
53 |
54 | assertTrue(SetAPI.getAllSets(filter).contains(alpha));
55 | }
56 |
57 | @Test
58 | public void testSetGetCards() {
59 | MtgSet testSet;
60 | testSet = SetAPI.getSet("LEA");
61 |
62 | assertNotNull(testSet.getCards());
63 |
64 | Card testCard = new Card();
65 | testCard.setMultiverseid(94);
66 | testCard.setName("Air Elemental");
67 | testCard.setCmc(5);
68 |
69 | assertTrue(testSet.getCards().contains(testCard));
70 | }
71 |
72 | @Test
73 | public void testGetAllSetsWithCards() {
74 | List sets = SetAPI.getAllSetsWithCards();
75 |
76 | assertNotNull(sets.get(0).getCards());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/api/CardAPI.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.api;
2 |
3 | import io.magicthegathering.javasdk.resource.Card;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * {@link CardAPI} is used to fetch {@link Card}s from magicthegathering.io
9 | *
10 | * @author nniklas
11 | */
12 | public class CardAPI extends MTGAPI {
13 | private static final String RESOURCE_PATH = "cards";
14 |
15 | /**
16 | * @return A {@link Card} based on the given cardid
17 | */
18 | public static Card getCard(String cardId) {
19 | String path = String.format("%s/%s/", RESOURCE_PATH, cardId);
20 | return get(path, "card", Card.class);
21 | }
22 |
23 | /**
24 | * @return A {@link Card} based on the given multiverseid
25 | */
26 | public static Card getCard(int multiverseId) {
27 | String path = String.format("%s/%s/", RESOURCE_PATH, multiverseId);
28 | return get(path, "card", Card.class);
29 | }
30 |
31 | /**
32 | * @return All the available {@link Card}s as a list.
33 | */
34 | public static List getAllCards() {
35 | return getList(RESOURCE_PATH, "cards", Card.class);
36 | }
37 |
38 | /**
39 | * @return A {@link List} of all card types as {@link String}s.
40 | *
41 | * @see
42 | * https://docs.magicthegathering.io/#card-types
43 | */
44 | public static List getAllCardTypes() {
45 | String path = "types";
46 | return getList(path, "types", String.class);
47 | }
48 |
49 | /**
50 | * @return A {@link List} of all card types as {@link String}s.
51 | *
52 | * @see
53 | * https://docs.magicthegathering.io/#get-all-supertypes
54 | */
55 | public static List getAllCardSupertypes() {
56 | String path = "supertypes";
57 | return getList(path, "supertypes", String.class);
58 | }
59 |
60 | /**
61 | * @return A {@link List} of all card types as {@link String}s.
62 | *
63 | * @see
64 | * https://docs.magicthegathering.io/#card-types
65 | */
66 | public static List getAllCardSubtypes() {
67 | String path = "subtypes";
68 | return getList(path, "subtypes", String.class);
69 | }
70 |
71 | /**
72 | * Get all the {@link Card} that match a certain filter.
73 | * @param filters List of filters supported by the web API
74 | * @return List of all matching {@link Card}s.
75 | *
76 | * @see
77 | * https://docs.magicthegathering.io/#cards
78 | */
79 | public static List getAllCards(List filters){
80 | return getList(RESOURCE_PATH, "cards", Card.class, filters);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/api/SetAPI.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.api;
2 |
3 | import java.util.Collections;
4 | import java.util.LinkedList;
5 | import java.util.List;
6 |
7 | import io.magicthegathering.javasdk.resource.Card;
8 | import io.magicthegathering.javasdk.resource.MtgSet;
9 |
10 | /**
11 | * {@link SetAPI} is used to fetch {@link MtgSet}s from magicthegathering.io
12 | *
13 | * @author nniklas
14 | */
15 | public class SetAPI extends MTGAPI {
16 | private static final String RESOURCE_PATH = "sets";
17 |
18 | /**
19 | * Returns a {@link MtgSet} based on the given set code.
20 | * @param setCode Code to find the specific set.
21 | */
22 | public static MtgSet getSet(String setCode) {
23 | String path = String.format("%s/%s/", RESOURCE_PATH, setCode);
24 | MtgSet returnSet = get(path, "set", MtgSet.class);
25 | if(returnSet != null) {
26 | returnSet.setCards(CardAPI.getAllCards(new LinkedList<>(Collections.singletonList("set=" + setCode))));
27 | }
28 | return returnSet;
29 | }
30 |
31 | /**
32 | * The method that returns all the {@link MtgSet}.
33 | * If you want all the card lists populated use
34 | * {@link #getAllSetsWithCards()}.
35 | * @return A List of all the sets.
36 | */
37 | public static List getAllSets() {
38 | return getList(RESOURCE_PATH, "sets", MtgSet.class);
39 | }
40 |
41 | /**
42 | * The method that will generate a booster for the selected {@link MtgSet}
43 | * @param setCode Code of which set you want a booster for.
44 | * @return the randomized booster for the set.
45 | */
46 | public static List getBooster(String setCode) {
47 | String path = String.format("%s/%s/%s/", RESOURCE_PATH, setCode,
48 | "booster");
49 | return getList(path, "cards", Card.class);
50 | }
51 |
52 | /**
53 | * Gets a list of {@link MtgSet} based on the provided filters in the
54 | * web API documentation.
55 | * @param filters List of string filters
56 | * @return The list of {@link MtgSet}s that was found by the filter.
57 | */
58 | public static List getAllSets(List filters){
59 | return getList(RESOURCE_PATH, "sets", MtgSet.class, filters);
60 | }
61 |
62 | /**
63 | * Gets a list of {@link MtgSet} with all the card objects populated.
64 | * Performance will be degraded because of all the Api calls that will
65 | * happen.
66 | * @return A list of all the sets with cards populated.
67 | */
68 | public static List getAllSetsWithCards() {
69 | List returnList = getList(RESOURCE_PATH, "sets", MtgSet.class);
70 | for(MtgSet set : returnList){
71 | set.setCards(CardAPI.getAllCards(new LinkedList<>(Collections.singletonList("set=" + set.getCode()))));
72 | }
73 | return returnList;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Magic: The Gathering Java SDK
2 | ===========
3 |
4 | [](https://travis-ci.org/MagicTheGathering/mtg-sdk-java)
5 | [](https://maven-badges.herokuapp.com/maven-central/io.magicthegathering/javasdk)
6 | [](https://www.codacy.com/app/nyholmniklas/mtg-sdk-java?utm_source=github.com&utm_medium=referral&utm_content=MagicTheGathering/mtg-sdk-java&utm_campaign=Badge_Grade)
7 | [](https://github.com/MagicTheGathering/mtg-sdk-java/blob/master/LICENSE)
8 | [](https://discord.gg/qwGJNnP)
9 |
10 | Java SDK for using the [magicthegathering.io](http://magicthegathering.io) APIs.
11 |
12 | Note that API use is free and does not require authentication or registration, but some rate limits apply. Read the official API website for more information.
13 |
14 | Add the dependency to your project and you're good to go! If you are on Android make sure you call on a seperate thread than the main.
15 |
16 | Prerequisites
17 | -------
18 | - Java JDK 7 or higher
19 |
20 | Integration
21 | -------
22 |
23 | #### Maven
24 | ```xml
25 |
26 | io.magicthegathering
27 | javasdk
28 | 0.0.18
29 |
30 | ```
31 | #### Gradle
32 | ```gradle
33 | implementation 'io.magicthegathering:javasdk:0.0.18'
34 | ```
35 |
36 | #### Ivy
37 | ```xml
38 |
39 | ```
40 |
41 | Usage examples
42 | -------
43 |
44 | #### Get a Card
45 | ```java
46 | int multiverseId = 1;
47 | Card card = CardAPI.getCard(multiverseId);
48 | ```
49 |
50 | #### Get all Cards
51 | ```java
52 | List cards = CardAPI.getAllCards();
53 | ```
54 |
55 | #### Get a Set
56 | ```java
57 | String setCode = "KLD";
58 | MtgSet set = SetAPI.getSet(setCode);
59 | ```
60 |
61 | #### Get all Sets
62 | This does **not** populate the card lists by default. This is to improve perfomance if all you need is a set list.
63 | Filter also does not currently load set lists. Will be adding in a future release.
64 | ```java
65 | List sets = SetAPI.getAllSets();
66 | ```
67 |
68 | #### Get all Sets with card lists loaded.
69 | ```java
70 | List sets = SetAPI.getAllSetsWithCards();
71 | ```
72 |
73 | #### Generate a Booster
74 | ```java
75 | String setCode = "KLD";
76 | List booster = SetAPI.getBooster(setCode);
77 | ```
78 | #### Change the connection timeout values that are used by the OkHttpClient
79 | ```java
80 | MTGAPI.setConnectTimeout(60);
81 | MTGAPI.setReadTimeout(60);
82 | MTGAPI.setWriteTimeout(60);
83 | ```
84 | License
85 | -------
86 | This project is licensed under [MIT license](http://opensource.org/licenses/MIT).
87 |
--------------------------------------------------------------------------------
/src/main/java/io/magicthegathering/javasdk/resource/MtgSet.java:
--------------------------------------------------------------------------------
1 | package io.magicthegathering.javasdk.resource;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * This file is part of mtgsdk.
7 | * https://github.com/MagicTheGathering/mtg-sdk-java
8 | *
9 | * Licensed under the MIT license:
10 | * http://www.opensource.org/licenses/MIT-license
11 | *
12 | * Created by thechucklingatom on 2/16/2016.
13 | *
14 | * Set class that is created from the JSON set representation.
15 | *
16 | * @author thechucklingatom
17 | */
18 | public class MtgSet {
19 | private String name;
20 | private String code;
21 | private String gathererCode;
22 | private String oldCode;
23 | private String magicCardsInfoCode;
24 | private String releaseDate;
25 | private String border;
26 | private String type;
27 | private String block;
28 | private boolean onlineOnly;
29 | private List