|
@@ -1,10 +1,14 @@
|
1
|
1
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
2
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
2
|
3
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
3
|
4
|
import com.mashape.unirest.http.Unirest;
|
4
|
5
|
import com.mashape.unirest.http.exceptions.UnirestException;
|
5
|
6
|
import com.mashape.unirest.request.GetRequest;
|
6
|
7
|
import com.mashape.unirest.request.HttpRequestWithBody;
|
7
|
8
|
|
|
9
|
+import java.io.IOException;
|
|
10
|
+import java.util.List;
|
|
11
|
+
|
8
|
12
|
public class YouAreEll {
|
9
|
13
|
|
10
|
14
|
YouAreEll() {
|
|
@@ -12,13 +16,14 @@ public class YouAreEll {
|
12
|
16
|
|
13
|
17
|
|
14
|
18
|
|
15
|
|
- public static void main(String[] args) throws JsonProcessingException {
|
|
19
|
+ public static void main(String[] args) throws IOException {
|
16
|
20
|
YouAreEll urlhandler = new YouAreEll();
|
17
|
21
|
// System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
|
18
|
|
- // System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
|
|
22
|
+ // System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
|
19
|
23
|
// urlhandler.postId("Bo", "bell7692");
|
20
|
24
|
// urlhandler.postMessage("bell7692", "kfennimore", "The best is yet to come");
|
21
|
|
- urlhandler.get_messages();
|
|
25
|
+ // urlhandler.get_messages();
|
|
26
|
+ urlhandler.messageParse();
|
22
|
27
|
|
23
|
28
|
|
24
|
29
|
}
|
|
@@ -30,20 +35,34 @@ public class YouAreEll {
|
30
|
35
|
|
31
|
36
|
}
|
32
|
37
|
|
33
|
|
- public void postMessage(String fromId, String toId, String message) throws JsonProcessingException {
|
|
38
|
+ public void postMessage(String fromid, String toid, String message) throws JsonProcessingException {
|
34
|
39
|
ObjectMapper objectMapper = new ObjectMapper();
|
35
|
|
- Message myMessage = new Message(fromId, toId, message);
|
|
40
|
+ Message myMessage = new Message(fromid, toid, message);
|
36
|
41
|
String payload = objectMapper.writeValueAsString(myMessage);
|
37
|
|
- String url = "/ids/" +toId +"/messages";
|
|
42
|
+ String url = "/ids/" +toid +"/messages";
|
38
|
43
|
MakeURLCall(url, "POST", payload);
|
39
|
44
|
}
|
40
|
45
|
public String get_ids() {
|
41
|
46
|
return MakeURLCall("/ids", "GET", "");
|
42
|
47
|
}
|
43
|
48
|
|
44
|
|
-// public String get_20_messages(){
|
45
|
|
-//
|
46
|
|
-// }
|
|
49
|
+
|
|
50
|
+ public String messageParse() throws IOException {
|
|
51
|
+ String str = MakeURLCall("/messages", "GET", "");
|
|
52
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
53
|
+ List<Message> message = objectMapper.readValue(str, new TypeReference<List<Message>>(){});
|
|
54
|
+
|
|
55
|
+ StringBuilder sb = new StringBuilder();
|
|
56
|
+ for (int i = 0; i < message.size(); i++) {
|
|
57
|
+ sb.append("Time: " +message.get(i).getTimestamp() + "\n");
|
|
58
|
+ sb.append("From: " +message.get(i).getFromid() + "\n");
|
|
59
|
+ sb.append("To: " +message.get(i).getToid() + "\n");
|
|
60
|
+ sb.append("Message: " +message.get(i).getMessage() + "\n\n");
|
|
61
|
+ }
|
|
62
|
+ System.out.println(sb.toString());
|
|
63
|
+ return sb.toString();
|
|
64
|
+
|
|
65
|
+ }
|
47
|
66
|
public String get_messages() {
|
48
|
67
|
return MakeURLCall("/messages", "GET", "");
|
49
|
68
|
}
|