Skip to content

Commit c4db7a9

Browse files
author
Swanis
committed
added new requests/jdk 17
1 parent d7f80d9 commit c4db7a9

File tree

13 files changed

+275
-27
lines changed

13 files changed

+275
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mcmarket-api-java-wrapper
22

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/) built with Java SE Development Kit 16.0.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/) built with Java SE Development Kit 17.0.1.
44

55
# Sending a request
66
```java
@@ -52,6 +52,6 @@ mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=<pat
5252
<dependency>
5353
<groupId>is.swan</groupId>
5454
<artifactId>mcmarket-api-java-wrapper</artifactId>
55-
<version>1.0-SNAPSHOT</version>
55+
<version>1.1-SNAPSHOT</version>
5656
</dependency>
5757
```

REQUESTS.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ MarkUnreadAlertsAsReadRequest(boolean read) (Void)
99
ListUnreadConversationsRequest(SortOptions sortOptions) (Conversation[])
1010
StartConversationRequest(int recipientId, String title, String message) (Void)
1111

12+
## Conversation Replies
13+
ListUnreadConversationRepliesRequest(int conversationId, SortOptions sortOptions) (Conversation[])
14+
ReplyToUnreadConversationRequest(int conversationId, String message) (Void)
15+
1216
## Members
1317
ListBansRequest (Ban[])
1418
ModifyYourselfRequest(String customTitle, String aboutMe, String signature) (Void)
15-
RetrieveMemberRequest(int memberId) (Member)
19+
RetrieveMemberByIDRequest(int memberId) (Member)
20+
RetrieveMemberByUsernameRequest(String username) (Member)
1621
RetrieveYourselfRequest (Member)
1722

1823
## Profile Posts
@@ -24,6 +29,7 @@ RetrieveSpecificProfilePostRequest(int profilePostId) (ProfilePost)
2429
## Resources
2530
ListOwnedResourcesRequest(SortOptions sortOptions) (Resource[])
2631
ListPublicResourcesRequest(SortOptions sortOptions) (Resource[])
32+
ListCollaboratedResourcesRequest(SortOptions sortOptions) (Resource[])
2733
ModifyResourceRequest(int resourceId, String title, String tag_line, String description) (Void)
2834
RetrieveResourceRequest(int resourceId) (DetailedResource)
2935

@@ -37,7 +43,8 @@ IssueResourceLicenseRequest(int resourceId, int purchaserId, long startDate, lon
3743
ListResourceLicensesRequest(int resourceId, SortOptions sortOptions) (ResourceLicense[])
3844
ModifyResourceLicenseRequest(int resourceId, int licenseId, long startDate, long endDate, boolean active) (Void)
3945
RetrieveResourceLicenseRequest(int resourceId, int licenseId) (ResourceLicense)
40-
ValidateResourceLicenseRequest(int resourceId, int purchaserId) (ResourceLicense)
46+
ValidateResourceLicenseRequest(int resourceId, int purchaserId, int nonce, long timestamp) (ResourceLicense)
47+
RetrieveResourceLicenseByMemberRequest(int resourceId, int purchaserId, int nonce, long timestamp) (ResourceLicense)
4148

4249
## Resource Purchases
4350
ListResourcePurchasesRequest(int resourceId, SortOptions sortOptions) (ResourcePurchase[])

pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<groupId>is.swan</groupId>
88
<artifactId>mcmarket-api-java-wrapper</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.1-SNAPSHOT</version>
1010

1111
<properties>
12-
<maven.compiler.source>16</maven.compiler.source>
13-
<maven.compiler.target>16</maven.compiler.target>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
1414
</properties>
1515

1616
<build>
@@ -37,8 +37,7 @@
3737
<dependency>
3838
<groupId>com.google.code.gson</groupId>
3939
<artifactId>gson</artifactId>
40-
<version>2.8.7</version>
41-
<scope>compile</scope>
40+
<version>2.8.9</version>
4241
</dependency>
4342
</dependencies>
4443
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package is.swan.mcmarketapi.classes;
2+
3+
public class ConversationReply {
4+
5+
private final int message_id;
6+
private final long message_date;
7+
private final int author_id;
8+
private final String message;
9+
10+
public ConversationReply(int message_id, long message_date, int author_id, String message) {
11+
this.message_id = message_id;
12+
this.message_date = message_date;
13+
this.author_id = author_id;
14+
this.message = message;
15+
}
16+
17+
public int getMessageId() {
18+
return message_id;
19+
}
20+
21+
public long getMessageDate() {
22+
return message_date;
23+
}
24+
25+
public int getAuthorId() {
26+
return author_id;
27+
}
28+
29+
public String getMessage() {
30+
return message;
31+
}
32+
}

src/main/java/is/swan/mcmarketapi/request/Client.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,11 @@ public Response sendOrWait(Request request) {
4646
}
4747

4848
private Response getResponse(Request request) {
49-
Response response = null;
50-
51-
if (request.getMethod() == Request.Method.GET) {
52-
response = HTTPUtil.get(request.getURL(), token);
53-
} else if (request.getMethod() == Request.Method.POST) {
54-
response = HTTPUtil.post(request.getURL(), request.getBody(), token);
55-
} else if (request.getMethod() == Request.Method.DELETE) {
56-
response = HTTPUtil.delete(request.getURL(), token);
57-
} else if (request.getMethod() == Request.Method.PATCH) {
58-
response = HTTPUtil.patch(request.getURL(), request.getBody(), token);
59-
}
60-
61-
return response;
49+
return switch(request.getMethod()) {
50+
case GET -> HTTPUtil.get(request.getURL(), token);
51+
case POST -> HTTPUtil.post(request.getURL(), request.getBody(), token);
52+
case DELETE -> HTTPUtil.delete(request.getURL(), token);
53+
case PATCH -> HTTPUtil.patch(request.getURL(), request.getBody(), token);
54+
};
6255
}
6356
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package is.swan.mcmarketapi.request.requests.conversation.reply;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import is.swan.mcmarketapi.classes.Conversation;
6+
import is.swan.mcmarketapi.classes.ConversationReply;
7+
import is.swan.mcmarketapi.request.Request;
8+
import is.swan.mcmarketapi.request.sorting.SortOptions;
9+
import is.swan.mcmarketapi.utils.SortUtil;
10+
11+
public class ListUnreadConversationRepliesRequest implements Request<ConversationReply[]> {
12+
13+
private final int conversationId;
14+
private final SortOptions sortOptions;
15+
16+
public ListUnreadConversationRepliesRequest(int conversationId, SortOptions sortOptions) {
17+
this.conversationId = conversationId;
18+
this.sortOptions = sortOptions;
19+
}
20+
21+
@Override
22+
public String getURL() {
23+
return "https://api.mc-market.org/v1/conversations/" + conversationId + "/replies" + SortUtil.optionsToString(sortOptions);
24+
}
25+
26+
@Override
27+
public Method getMethod() {
28+
return Method.GET;
29+
}
30+
31+
@Override
32+
public ConversationReply[] handleJson(String json) {
33+
Gson gson = new Gson();
34+
JsonElement element = gson.fromJson(json, JsonElement.class);
35+
String conversationRepliesJson = element.getAsJsonObject().get("data").getAsJsonArray().toString();
36+
ConversationReply[] conversationReplies = gson.fromJson(conversationRepliesJson, ConversationReply[].class);
37+
38+
return conversationReplies;
39+
}
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package is.swan.mcmarketapi.request.requests.conversation.reply;
2+
3+
import com.google.gson.Gson;
4+
import is.swan.mcmarketapi.request.Request;
5+
6+
import java.util.HashMap;
7+
8+
public class ReplyToUnreadConversationRequest implements Request<Void> {
9+
10+
private final int conversationId;
11+
private final String message;
12+
13+
public ReplyToUnreadConversationRequest(int conversationId, String message) {
14+
this.conversationId = conversationId;
15+
this.message = message;
16+
}
17+
18+
@Override
19+
public String getURL() {
20+
return "https://api.mc-market.org/v1/conversations/" + conversationId + "/replies";
21+
}
22+
23+
@Override
24+
public Method getMethod() {
25+
return Method.POST;
26+
}
27+
28+
@Override
29+
public String getBody() {
30+
Gson gson = new Gson();
31+
HashMap<String, Object> parameters = new HashMap<>();
32+
33+
parameters.put("message", message);
34+
35+
return gson.toJson(parameters);
36+
}
37+
}

src/main/java/is/swan/mcmarketapi/request/requests/member/RetrieveMemberRequest.java renamed to src/main/java/is/swan/mcmarketapi/request/requests/member/RetrieveMemberByIDRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import is.swan.mcmarketapi.classes.Member;
66
import is.swan.mcmarketapi.request.Request;
77

8-
public class RetrieveMemberRequest implements Request<Member> {
8+
public class RetrieveMemberByIDRequest implements Request<Member> {
99

1010
private final int memberId;
1111

12-
public RetrieveMemberRequest(int memberId) {
12+
public RetrieveMemberByIDRequest(int memberId) {
1313
this.memberId = memberId;
1414
}
1515

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package is.swan.mcmarketapi.request.requests.member;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import is.swan.mcmarketapi.classes.Member;
6+
import is.swan.mcmarketapi.request.Request;
7+
8+
public class RetrieveMemberByUsernameRequest implements Request<Member> {
9+
10+
private final String username;
11+
12+
public RetrieveMemberByUsernameRequest(String username) {
13+
this.username = username;
14+
}
15+
16+
@Override
17+
public String getURL() {
18+
return "https://api.mc-market.org/v1/members/username/" + username;
19+
}
20+
21+
@Override
22+
public Method getMethod() {
23+
return Method.GET;
24+
}
25+
26+
@Override
27+
public Member handleJson(String json) {
28+
Gson gson = new Gson();
29+
JsonElement element = gson.fromJson(json, JsonElement.class);
30+
String memberJson = element.getAsJsonObject().get("data").getAsJsonObject().toString();
31+
Member member = gson.fromJson(memberJson, Member.class);
32+
33+
return member;
34+
}
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package is.swan.mcmarketapi.request.requests.resource;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import is.swan.mcmarketapi.classes.Resource;
6+
import is.swan.mcmarketapi.request.Request;
7+
import is.swan.mcmarketapi.request.sorting.SortOptions;
8+
import is.swan.mcmarketapi.utils.SortUtil;
9+
10+
public class ListCollaboratedResourcesRequest implements Request<Resource[]> {
11+
12+
private final SortOptions sortOptions;
13+
14+
public ListCollaboratedResourcesRequest(SortOptions sortOptions) {
15+
this.sortOptions = sortOptions;
16+
}
17+
18+
@Override
19+
public String getURL() {
20+
return "https://api.mc-market.org/v1/resources/collaborated" + SortUtil.optionsToString(sortOptions);
21+
}
22+
23+
@Override
24+
public Method getMethod() {
25+
return Method.GET;
26+
}
27+
28+
@Override
29+
public Resource[] handleJson(String json) {
30+
Gson gson = new Gson();
31+
JsonElement element = gson.fromJson(json, JsonElement.class);
32+
String resourcesJson = element.getAsJsonObject().get("data").getAsJsonArray().toString();
33+
Resource[] resources = gson.fromJson(resourcesJson, Resource[].class);
34+
35+
return resources;
36+
}
37+
}

0 commit comments

Comments
 (0)