Skip to content

Commit af7ecd3

Browse files
committed
simplify notifications()
1 parent 6481409 commit af7ecd3

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

src/com/namelessmc/java_api/NamelessUser.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.google.gson.JsonArray;
55
import com.google.gson.JsonElement;
66
import com.google.gson.JsonObject;
7-
import com.namelessmc.java_api.Notification.Type;
87
import com.namelessmc.java_api.exception.ApiError;
98
import com.namelessmc.java_api.exception.ApiException;
109
import com.namelessmc.java_api.exception.NamelessException;
@@ -223,16 +222,7 @@ public int notificationCount() throws NamelessException {
223222

224223
public List<Notification> notifications() throws NamelessException {
225224
final JsonObject response = this.requests.get("users/" + this.userTransformer + "/notifications");
226-
227-
final List<Notification> notifications = new ArrayList<>();
228-
response.getAsJsonArray("notifications").forEach((element) -> {
229-
final String message = element.getAsJsonObject().get("message").getAsString();
230-
final String url = element.getAsJsonObject().get("url").getAsString();
231-
final Type type = Type.fromString(element.getAsJsonObject().get("type").getAsString());
232-
notifications.add(new Notification(message, url, type));
233-
});
234-
235-
return notifications;
225+
return GsonHelper.toObjectList(response.getAsJsonArray("notifications"), Notification::new);
236226
}
237227

238228
/**

src/com/namelessmc/java_api/Notification.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.namelessmc.java_api;
22

3+
import com.google.gson.JsonObject;
4+
35
public class Notification {
46

57
private final String message;
68
private final String url;
79
private final Type type;
810

9-
public Notification(final String message, final String url, final Type type) {
10-
this.message = message;
11-
this.url = url;
12-
this.type = type;
11+
public Notification(JsonObject json) {
12+
this.message = json.get("message").getAsString();
13+
this.url = json.get("url").getAsString();
14+
this.type = Type.fromString(json.get("type").getAsString());
1315
}
1416

1517
public String message() {

0 commit comments

Comments
 (0)