|
@@ -1,3 +1,4 @@
|
|
1
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
1
|
2
|
import com.mashape.unirest.http.HttpResponse;
|
2
|
3
|
import com.mashape.unirest.http.JsonNode;
|
3
|
4
|
import com.mashape.unirest.http.Unirest;
|
|
@@ -13,10 +14,16 @@ import java.util.List;
|
13
|
14
|
public class SimpleShell {
|
14
|
15
|
|
15
|
16
|
|
16
|
|
- public static void prettyPrint(String output) {
|
17
|
|
- // yep, make an effort to format things nicely, eh?
|
18
|
|
- System.out.println(output);
|
|
17
|
+ public static void prettyPrint(JsonNode jsonNode) {
|
|
18
|
+ try {
|
|
19
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
20
|
+ Object json = mapper.readValue(jsonNode.toString(), Object.class);
|
|
21
|
+ System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
|
|
22
|
+ } catch (Exception e) {
|
|
23
|
+ System.out.println("Sorry, pretty print didn't work");
|
|
24
|
+ }
|
19
|
25
|
}
|
|
26
|
+
|
20
|
27
|
public static void main(String[] args) throws java.io.IOException {
|
21
|
28
|
|
22
|
29
|
YouAreEll webber = new YouAreEll();
|
|
@@ -65,15 +72,13 @@ public class SimpleShell {
|
65
|
72
|
|
66
|
73
|
// ids
|
67
|
74
|
if (list.contains("ids")) {
|
68
|
|
- String results = webber.get_ids();
|
69
|
|
- SimpleShell.prettyPrint(results);
|
|
75
|
+ webber.get_ids();
|
70
|
76
|
continue;
|
71
|
77
|
}
|
72
|
78
|
|
73
|
79
|
// messages
|
74
|
80
|
if (list.contains("messages")) {
|
75
|
|
- String results = webber.get_messages();
|
76
|
|
- SimpleShell.prettyPrint(results);
|
|
81
|
+ webber.get_messages();
|
77
|
82
|
continue;
|
78
|
83
|
}
|
79
|
84
|
// you need to add a bunch more.
|
|
@@ -111,8 +116,6 @@ public class SimpleShell {
|
111
|
116
|
//catch ioexception, output appropriate message, resume waiting for input
|
112
|
117
|
catch (IOException e) {
|
113
|
118
|
System.out.println("Input Error, Please try again!");
|
114
|
|
- } catch (UnirestException e) {
|
115
|
|
- e.printStackTrace();
|
116
|
119
|
}
|
117
|
120
|
// So what, do you suppose, is the meaning of this comment?
|
118
|
121
|
/** The steps are:
|