Skip to content

Commit ae007cf

Browse files
Adding cards into a new All sets request. Made separate from the original request due to a massive performance difference. A few warning fixes as well.
1 parent 22b2c31 commit ae007cf

4 files changed

Lines changed: 44 additions & 13 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Java SDK for using the [magicthegathering.io](http://magicthegathering.io) APIs.
1111

1212
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.
1313

14-
Add the dependency to your project and you're good to go!
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.
1515

1616
Prerequisites
1717
-------
@@ -25,17 +25,17 @@ Integration
2525
<dependency>
2626
<groupId>io.magicthegathering</groupId>
2727
<artifactId>javasdk</artifactId>
28-
<version>0.0.10</version>
28+
<version>0.0.11</version>
2929
</dependency>
3030
```
3131
#### Gradle
3232
```gradle
33-
compile 'io.magicthegathering:javasdk:0.0.10'
33+
compile 'io.magicthegathering:javasdk:0.0.11'
3434
```
3535

3636
#### Ivy
3737
```xml
38-
<dependency org="io.magicthegathering" name="javasdk" rev="0.0.10"/>
38+
<dependency org="io.magicthegathering" name="javasdk" rev="0.0.11"/>
3939
```
4040

4141
Usage examples
@@ -59,10 +59,17 @@ MtgSet set = SetAPI.getSet(setCode);
5959
```
6060

6161
#### 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.
6264
```java
6365
List<MtgSet> sets = SetAPI.getAllSets();
6466
```
6567

68+
#### Get all Sets with card lists loaded.
69+
```java
70+
List<MtgSet> sets = SetAPI.getAllSetsWithCards();
71+
```
72+
6673
#### Generate a Booster
6774
```java
6875
String setCode = "KLD";

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.magicthegathering</groupId>
66
<artifactId>javasdk</artifactId>
7-
<version>0.0.10</version>
7+
<version>0.0.11</version>
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/io/magicthegathering/javasdk/api/SetAPI.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.magicthegathering.javasdk.api;
22

3-
import io.magicthegathering.javasdk.resource.Card;
4-
import io.magicthegathering.javasdk.resource.MtgSet;
5-
6-
import java.util.Arrays;
3+
import java.util.Collections;
74
import java.util.LinkedList;
85
import java.util.List;
96

7+
import io.magicthegathering.javasdk.resource.Card;
8+
import io.magicthegathering.javasdk.resource.MtgSet;
9+
1010
/**
1111
* {@link SetAPI} is used to fetch {@link MtgSet}s from magicthegathering.io
1212
*
@@ -23,13 +23,15 @@ public static MtgSet getSet(String setCode) {
2323
String path = String.format("%s/%s/", RESOURCE_PATH, setCode);
2424
MtgSet returnSet = get(path, "set", MtgSet.class);
2525
if(returnSet != null) {
26-
returnSet.setCards(CardAPI.getAllCards(new LinkedList<>(Arrays.asList("set=" + setCode))));
26+
returnSet.setCards(CardAPI.getAllCards(new LinkedList<>(Collections.singletonList("set=" + setCode))));
2727
}
2828
return returnSet;
2929
}
3030

3131
/**
3232
* The method that returns all the {@link MtgSet}.
33+
* If you want all the card lists populated use
34+
* {@link #getAllSetsWithCards()}.
3335
* @return A List of all the sets.
3436
*/
3537
public static List<MtgSet> getAllSets() {
@@ -39,7 +41,7 @@ public static List<MtgSet> getAllSets() {
3941
/**
4042
* The method that will generate a booster for the selected {@link MtgSet}
4143
* @param setCode Code of which set you want a booster for.
42-
* @return
44+
* @return the randomized booster for the set.
4345
*/
4446
public static List<Card> getBooster(String setCode) {
4547
String path = String.format("%s/%s/%s/", RESOURCE_PATH, setCode,
@@ -56,4 +58,18 @@ public static List<Card> getBooster(String setCode) {
5658
public static List<MtgSet> getAllSets(List<String> filters){
5759
return getList(RESOURCE_PATH, "sets", MtgSet.class, filters);
5860
}
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<MtgSet> getAllSetsWithCards() {
69+
List<MtgSet> 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+
}
5975
}

src/test/java/io/magicthegathering/javasdk/api/SetAPITest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import static org.junit.Assert.assertEquals;
1212
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertNotEquals;
1314
import static org.junit.Assert.assertNotNull;
1415
import static org.junit.Assert.assertNull;
1516
import static org.junit.Assert.assertTrue;
@@ -20,7 +21,7 @@ public void testGetSet() {
2021
MtgSet testSet = new MtgSet();
2122
testSet.setGatherercode("1E");
2223
assertEquals(testSet, SetAPI.getSet("LEA"));
23-
assertFalse(testSet.equals(SetAPI.getSet("LEB")));
24+
assertNotEquals(testSet, SetAPI.getSet("LEB"));
2425
}
2526

2627
@Test
@@ -56,7 +57,7 @@ public void testSetFilter(){
5657
@Test
5758
public void testSetGetCards() {
5859
MtgSet testSet;
59-
testSet = SetAPI.getSet("DRK");
60+
testSet = SetAPI.getSet("LEA");
6061

6162
assertNotNull(testSet.getCards());
6263

@@ -67,4 +68,11 @@ public void testSetGetCards() {
6768

6869
assertTrue(testSet.getCards().contains(testCard));
6970
}
71+
72+
@Test
73+
public void testGetAllSetsWithCards() {
74+
List<MtgSet> sets = SetAPI.getAllSetsWithCards();
75+
76+
assertNotNull(sets.get(0).getCards());
77+
}
7078
}

0 commit comments

Comments
 (0)