File tree Expand file tree Collapse file tree
src/com/namelessmc/java_api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import com .google .gson .JsonArray ;
55import com .google .gson .JsonElement ;
66import com .google .gson .JsonObject ;
7- import com .namelessmc .java_api .Notification .Type ;
87import com .namelessmc .java_api .exception .ApiError ;
98import com .namelessmc .java_api .exception .ApiException ;
109import 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 /**
Original file line number Diff line number Diff line change 11package com .namelessmc .java_api ;
22
3+ import com .google .gson .JsonObject ;
4+
35public 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 () {
You can’t perform that action at this time.
0 commit comments