This repository was archived by the owner on Jan 5, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/com/scorpiac/javarant Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ public class DevRant {
5656 private int timeout = 15000 ;
5757 private boolean hideReposts = false ;
5858 private int numNotifs ;
59+ private News news ;
5960
6061 /**
6162 * Log in to devRant.
@@ -416,6 +417,10 @@ private JsonObject executeRequest(Request request) {
416417 if (json .has ("num_notifs" ))
417418 numNotifs = json .get ("num_notifs" ).getAsInt ();
418419
420+ // Save the news.
421+ if (json .has ("news" ))
422+ news = News .fromJson (json .get ("news" ).getAsJsonObject ());
423+
419424 return json ;
420425 }
421426
@@ -457,4 +462,11 @@ public boolean getHideReposts() {
457462 public int getNotifCount () {
458463 return numNotifs ;
459464 }
465+
466+ /**
467+ * Get the news.
468+ */
469+ public News getNews () {
470+ return news ;
471+ }
460472}
Original file line number Diff line number Diff line change 1+ package com .scorpiac .javarant ;
2+
3+ import com .google .gson .JsonObject ;
4+
5+ public class News {
6+ private String headline ;
7+ private String body ;
8+ private String footer ;
9+
10+ private News (String headline , String body , String footer ) {
11+ this .headline = headline ;
12+ this .body = body ;
13+ this .footer = footer ;
14+ }
15+
16+ static News fromJson (JsonObject json ) {
17+ return new News (
18+ json .has ("headline" ) ? json .get ("headline" ).getAsString () : "" ,
19+ json .has ("body" ) ? json .get ("body" ).getAsString () : "" ,
20+ json .has ("footer" ) ? json .get ("footer" ).getAsString () : ""
21+ );
22+ }
23+
24+ @ Override
25+ public String toString () {
26+ return headline + '\n' + body + '\n' + footer ;
27+ }
28+
29+ /**
30+ * Get the headline.
31+ */
32+ public String getHeadline () {
33+ return headline ;
34+ }
35+
36+ /**
37+ * Get the body text.
38+ */
39+ public String getBody () {
40+ return body ;
41+ }
42+
43+ /**
44+ * Get the footer.
45+ */
46+ public String getFooter () {
47+ return footer ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments