|
@@ -1,5 +1,5 @@
|
1
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
2
|
1
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
2
|
+import org.apache.log4j.*;
|
3
|
3
|
|
4
|
4
|
import java.io.BufferedReader;
|
5
|
5
|
import java.io.IOException;
|
|
@@ -10,17 +10,36 @@ import java.util.List;
|
10
|
10
|
|
11
|
11
|
public class SimpleShell {
|
12
|
12
|
|
13
|
|
- public static void prettyPrint(String output) {
|
14
|
|
- // yep, make an effort to format things nicely, eh?
|
|
13
|
+ private static final Logger logger = LogManager.getLogger(SimpleShell.class);
|
|
14
|
+
|
|
15
|
+ public static void prettyPrintUsers(String output) {
|
15
|
16
|
ObjectMapper mapper = new ObjectMapper();
|
16
|
|
- Object json;
|
|
17
|
+ User[] users = null;
|
17
|
18
|
try {
|
18
|
|
- json = mapper.readValue(output, Object.class);
|
19
|
|
- System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
|
|
19
|
+ users = mapper.readValue(output, User[].class);
|
20
|
20
|
} catch (IOException e) {
|
21
|
21
|
e.printStackTrace();
|
22
|
22
|
}
|
|
23
|
+ for (User user:users){
|
|
24
|
+ System.out.println(user.getName() + " " + user.getGithub() + "\n---------------------------");
|
|
25
|
+ }
|
23
|
26
|
}
|
|
27
|
+
|
|
28
|
+ public static void prettyPrintMessages(String output) {
|
|
29
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
30
|
+ Message[] messages = null;
|
|
31
|
+ try {
|
|
32
|
+ messages = mapper.readValue(output, Message[].class);
|
|
33
|
+ } catch (IOException e) {
|
|
34
|
+ logger.trace("Pretty Print Message exception");
|
|
35
|
+ e.printStackTrace();
|
|
36
|
+ }
|
|
37
|
+ for (Message message:messages){
|
|
38
|
+ if (message.getToid().equals("")) System.out.println(message.getFromid() + ": " + message.getMessage());
|
|
39
|
+ else System.out.println(message.getFromid() + " says to " + message.getToid() + ": " + message.getMessage());
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+
|
24
|
43
|
public static void main(String[] args) throws java.io.IOException {
|
25
|
44
|
|
26
|
45
|
YouAreEll webber = new YouAreEll();
|
|
@@ -76,21 +95,21 @@ public class SimpleShell {
|
76
|
95
|
// ids
|
77
|
96
|
if (list.contains("ids")) {
|
78
|
97
|
String results = webber.get_ids(user);
|
79
|
|
- SimpleShell.prettyPrint(results);
|
|
98
|
+ SimpleShell.prettyPrintUsers(results);
|
80
|
99
|
continue;
|
81
|
100
|
}
|
82
|
101
|
|
83
|
102
|
// messages
|
84
|
103
|
if (list.contains("messages")) {
|
85
|
104
|
String results = webber.get_messages(user);
|
86
|
|
- SimpleShell.prettyPrint(results);
|
|
105
|
+ SimpleShell.prettyPrintMessages(results);
|
87
|
106
|
continue;
|
88
|
107
|
}
|
89
|
108
|
// you need to add a bunch more.
|
90
|
109
|
|
91
|
110
|
if (list.contains("dms")) {
|
92
|
111
|
String results = webber.get_DMs(user);
|
93
|
|
- SimpleShell.prettyPrint(results);
|
|
112
|
+ SimpleShell.prettyPrintMessages(results);
|
94
|
113
|
continue;
|
95
|
114
|
}
|
96
|
115
|
|
|
@@ -107,7 +126,7 @@ public class SimpleShell {
|
107
|
126
|
message = new Message(user.getGithub(), list.get(1), sentence);
|
108
|
127
|
}
|
109
|
128
|
String results = webber.send_message(message);
|
110
|
|
- SimpleShell.prettyPrint(results);
|
|
129
|
+ SimpleShell.prettyPrintMessages(results);
|
111
|
130
|
continue;
|
112
|
131
|
}
|
113
|
132
|
|