|
@@ -22,7 +22,7 @@ public class YouAreEll {
|
22
|
22
|
String userChoice = Console.printMainMenu();
|
23
|
23
|
switch (userChoice) {
|
24
|
24
|
case "GET":
|
25
|
|
- url.sendGetIDsRequest(url);
|
|
25
|
+ url.prettyPrint(url.sendGetIDsRequest(url));
|
26
|
26
|
Console.printSuccess(userChoice);
|
27
|
27
|
break;
|
28
|
28
|
case "ADD":
|
|
@@ -34,7 +34,7 @@ public class YouAreEll {
|
34
|
34
|
Console.printSuccess(userChoice);
|
35
|
35
|
break;
|
36
|
36
|
case "SEE":
|
37
|
|
- url.sendGetGlobalMessagesRequest(url);
|
|
37
|
+ url.prettyPrint(url.sendGetGlobalMessagesRequest(url));
|
38
|
38
|
Console.printSuccess(userChoice);
|
39
|
39
|
break;
|
40
|
40
|
case "QUIT":
|
|
@@ -100,6 +100,16 @@ public class YouAreEll {
|
100
|
100
|
.asJson();
|
101
|
101
|
jsonResponse.getStatus();
|
102
|
102
|
}
|
|
103
|
+//
|
|
104
|
+// public String prettyPrint() {
|
|
105
|
+// try {
|
|
106
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
107
|
+// Object json = mapper.readValue(jsonNode.toString(), Object.class);
|
|
108
|
+// return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
|
|
109
|
+// } catch (Exception e) {
|
|
110
|
+// return "Sorry, pretty print didn't work";
|
|
111
|
+// }
|
|
112
|
+// }
|
103
|
113
|
|
104
|
114
|
public void inputDirectMessage() throws UnirestException {
|
105
|
115
|
String fromID = getInput(Console.getFromID());
|
|
@@ -114,28 +124,39 @@ public class YouAreEll {
|
114
|
124
|
jsonResponse.getStatus();
|
115
|
125
|
}
|
116
|
126
|
|
117
|
|
- public void getAllUserIDs() throws UnirestException {
|
|
127
|
+ public JsonNode getAllUserIDs() throws UnirestException {
|
118
|
128
|
HttpResponse<JsonNode> jsonResponse = Unirest.get("http://zipcode.rocks:8085/ids")
|
119
|
129
|
// .header("accept", "application/json")
|
120
|
130
|
.asJson();
|
121
|
|
- jsonResponse.getBody();
|
122
|
|
- System.out.println(jsonResponse.getBody());
|
|
131
|
+ return jsonResponse.getBody();
|
|
132
|
+ // System.out.println(jsonResponse.getBody());
|
123
|
133
|
}
|
124
|
134
|
|
125
|
|
- public void getGlobalMessages() throws UnirestException {
|
|
135
|
+ public JsonNode getGlobalMessages() throws UnirestException {
|
126
|
136
|
HttpResponse<JsonNode> jsonResponse = Unirest.get("http://zipcode.rocks:8085/messages")
|
127
|
137
|
// .header("accept", "application/json")
|
128
|
138
|
.asJson();
|
129
|
|
- jsonResponse.getBody();
|
130
|
|
- System.out.println(jsonResponse.getBody());
|
|
139
|
+ return jsonResponse.getBody();
|
|
140
|
+// System.out.println(jsonResponse.getBody());
|
131
|
141
|
// jackson --> pretty print
|
132
|
142
|
}
|
133
|
143
|
|
134
|
|
- public void sendGetGlobalMessagesRequest(YouAreEll url) {
|
|
144
|
+ public void prettyPrint(JsonNode jsonNode) {
|
135
|
145
|
try {
|
136
|
|
- url.getGlobalMessages();
|
|
146
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
147
|
+ Object json = mapper.readValue(jsonNode.toString(), Object.class);
|
|
148
|
+ System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
|
|
149
|
+ } catch (Exception e) {
|
|
150
|
+ System.out.println("Nope");
|
|
151
|
+ }
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ public JsonNode sendGetGlobalMessagesRequest(YouAreEll url) {
|
|
155
|
+ try {
|
|
156
|
+ return url.getGlobalMessages();
|
137
|
157
|
} catch (UnirestException u) {
|
138
|
158
|
System.out.println("Error getting global messages.");
|
|
159
|
+ return null;
|
139
|
160
|
}
|
140
|
161
|
}
|
141
|
162
|
|
|
@@ -163,11 +184,12 @@ public class YouAreEll {
|
163
|
184
|
}
|
164
|
185
|
}
|
165
|
186
|
|
166
|
|
- public void sendGetIDsRequest(YouAreEll url) {
|
|
187
|
+ public JsonNode sendGetIDsRequest(YouAreEll url) {
|
167
|
188
|
try {
|
168
|
|
- url.getAllUserIDs();
|
|
189
|
+ return url.getAllUserIDs();
|
169
|
190
|
} catch (UnirestException u) {
|
170
|
191
|
System.out.println("Error getting user IDs.");
|
|
192
|
+ return null;
|
171
|
193
|
}
|
172
|
194
|
}
|
173
|
195
|
}
|