|
1 | | -# mcmarket-api-java-wrapper |
| 1 | +# mcmarket-api-java-wrapper |
| 2 | + |
| 3 | +This is a complete and easy-to-use Java Wrapper for the [MC-Market Ultimate API](https://www.mc-market.org/wiki/ultimate-api/). |
| 4 | + |
| 5 | +# Send a request |
| 6 | +```java |
| 7 | +Client client = new Client(new Token("TOKEN STRING", Token.Type.PRIVATE)); |
| 8 | +Response<Member> response = client.sendOrWait(new RetrieveYourselfRequest()); |
| 9 | + |
| 10 | +//client.send(new RetrieveYourselfRequest()) also works, but in that case you'd have to handle eventual ratelimits yourself with the help of our built-in methods (response.isRatelimited() and response.getMillisecondsToWait()). |
| 11 | + |
| 12 | +if (response.getError() == null) { |
| 13 | + Member member = response.getValue(); |
| 14 | + System.out.println(member.getUsername()); |
| 15 | +} else { |
| 16 | + Error error = response.getError(); |
| 17 | + System.out.println(error.getCode() + ": " + error.getMessage()); |
| 18 | +} |
| 19 | +``` |
| 20 | +A list of requests along with their expected response types can be found [here](requests.md). |
| 21 | + |
| 22 | +# Sorting |
| 23 | +Sorting is possible by passing a SortOptions object into the constructor of supported requests (simply pass null if you don't care about sorting). |
| 24 | +```java |
| 25 | +//Example printing the 20 top-purchased resources. |
| 26 | +Client client = new Client(new Token("TOKEN STRING", Token.Type.PRIVATE)); |
| 27 | +Response<Resource[]> response = client.sendOrWait(new ListPublicResourcesRequest(new SortOptions("purchase_count", Order.DESCENDING, 1))); |
| 28 | + |
| 29 | +if (response.getError() == null) { |
| 30 | + Resource[] resources = response.getValue(); |
| 31 | + |
| 32 | + for (Resource resource : resources) { |
| 33 | + System.out.println(resource.getTitle()); |
| 34 | + } |
| 35 | +} else { |
| 36 | + Error error = response.getError(); |
| 37 | + System.out.println(error.getCode() + ": " + error.getMessage()); |
| 38 | +} |
| 39 | +``` |
| 40 | +Sortable fields can be found at the official API documentation [here](https://www.mc-market.org/wiki/ultimate-api-v1/). |
0 commit comments