|
@@ -1,3 +1,5 @@
|
|
1
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
2
|
+
|
1
|
3
|
import java.io.BufferedReader;
|
2
|
4
|
import java.io.IOException;
|
3
|
5
|
import java.io.InputStream;
|
|
@@ -10,8 +12,18 @@ public class SimpleShell {
|
10
|
12
|
|
11
|
13
|
public static void prettyPrint(String output) {
|
12
|
14
|
// yep, make an effort to format things nicely, eh?
|
13
|
|
- System.out.println(output);
|
|
15
|
+
|
|
16
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
17
|
+
|
|
18
|
+ try {
|
|
19
|
+ Object json = mapper.readValue(output, Object.class);
|
|
20
|
+ String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
|
|
21
|
+ System.out.println(pretty);
|
|
22
|
+ } catch (IOException ioe) {
|
|
23
|
+ ioe.printStackTrace();
|
|
24
|
+ }
|
14
|
25
|
}
|
|
26
|
+
|
15
|
27
|
public static void main(String[] args) throws java.io.IOException {
|
16
|
28
|
|
17
|
29
|
YouAreEll webber = new YouAreEll();
|
|
@@ -21,6 +33,7 @@ public class SimpleShell {
|
21
|
33
|
|
22
|
34
|
ProcessBuilder pb = new ProcessBuilder();
|
23
|
35
|
List<String> history = new ArrayList<String>();
|
|
36
|
+ ObjectMapper mapper = new ObjectMapper();
|
24
|
37
|
int index = 0;
|
25
|
38
|
//we break out with <ctrl c>
|
26
|
39
|
while (true) {
|
|
@@ -58,6 +71,15 @@ public class SimpleShell {
|
58
|
71
|
|
59
|
72
|
// Specific Commands.
|
60
|
73
|
|
|
74
|
+ if (list.contains("ids") && list.size() > 2) {
|
|
75
|
+ String name = list.get(1);
|
|
76
|
+ String githubid = list.get(2);
|
|
77
|
+ Identifier id = new Identifier(name, githubid);
|
|
78
|
+ String json = mapper.writeValueAsString(id);
|
|
79
|
+ webber.MakeURLCall("/ids", "POST", json);
|
|
80
|
+ continue;
|
|
81
|
+ }
|
|
82
|
+
|
61
|
83
|
// ids
|
62
|
84
|
if (list.contains("ids")) {
|
63
|
85
|
String results = webber.get_ids();
|
|
@@ -65,11 +87,57 @@ public class SimpleShell {
|
65
|
87
|
continue;
|
66
|
88
|
}
|
67
|
89
|
|
|
90
|
+ if (list.contains("send")) {
|
|
91
|
+ String fromid = list.get(1);
|
|
92
|
+ StringBuilder message = new StringBuilder();
|
|
93
|
+ int indexEndMessage = 0;
|
|
94
|
+
|
|
95
|
+ for (int i = 3; i < list.size(); i++) {
|
|
96
|
+ if (list.get(i).contains("'")) {
|
|
97
|
+ indexEndMessage = i;
|
|
98
|
+ break;
|
|
99
|
+ }
|
|
100
|
+ indexEndMessage = 2;
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ for (int i = 2; i < indexEndMessage; i++) {
|
|
104
|
+ if (i == 2) {
|
|
105
|
+ message.append(list.get(i).substring(1));
|
|
106
|
+ message.append(" ");
|
|
107
|
+ } else {
|
|
108
|
+ message.append(list.get(i));
|
|
109
|
+ message.append(" ");
|
|
110
|
+ }
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ message.append(list.get(indexEndMessage).substring(0, list.get(indexEndMessage).length()-1));
|
|
114
|
+ String messageString = message.toString();
|
|
115
|
+
|
|
116
|
+ if (list.size() - 1 == indexEndMessage) {
|
|
117
|
+ Message obj = new Message(fromid, messageString);
|
|
118
|
+ String json = mapper.writeValueAsString(obj);
|
|
119
|
+ webber.MakeURLCall("/ids/" + fromid + "/messages", "POST", json);
|
|
120
|
+ } else {
|
|
121
|
+ String toid = list.get(list.size() - 1);
|
|
122
|
+ Message obj = new Message(fromid, toid, messageString);
|
|
123
|
+ String json = mapper.writeValueAsString(obj);
|
|
124
|
+ webber.MakeURLCall("/ids/" + fromid + "/messages", "POST", json);
|
|
125
|
+ }
|
|
126
|
+ continue;
|
|
127
|
+ }
|
|
128
|
+
|
68
|
129
|
// messages
|
69
|
130
|
if (list.contains("messages")) {
|
70
|
|
- String results = webber.get_messages();
|
71
|
|
- SimpleShell.prettyPrint(results);
|
72
|
|
- continue;
|
|
131
|
+ if (list.size() == 1) {
|
|
132
|
+ String results = webber.get_messages();
|
|
133
|
+ SimpleShell.prettyPrint(results);
|
|
134
|
+ continue;
|
|
135
|
+ } else {
|
|
136
|
+ String urlpath = "/ids/" + list.get(1) + "/messages";
|
|
137
|
+ String results = webber.MakeURLCall(urlpath, "GET", "");
|
|
138
|
+ SimpleShell.prettyPrint(results);
|
|
139
|
+ continue;
|
|
140
|
+ }
|
73
|
141
|
}
|
74
|
142
|
// you need to add a bunch more.
|
75
|
143
|
|