|
@@ -1,14 +1,39 @@
|
|
1
|
+
|
|
2
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
3
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
4
|
+import com.mashape.unirest.http.Unirest;
|
|
5
|
+import com.mashape.unirest.http.exceptions.UnirestException;
|
|
6
|
+import com.mashape.unirest.request.GetRequest;
|
|
7
|
+
|
1
|
8
|
public class YouAreEll {
|
2
|
9
|
|
3
|
10
|
YouAreEll() {
|
4
|
11
|
}
|
5
|
12
|
|
6
|
|
- public static void main(String[] args) {
|
|
13
|
+ public static void main(String[] args) throws JsonProcessingException {
|
7
|
14
|
YouAreEll urlhandler = new YouAreEll();
|
8
|
15
|
System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
|
9
|
16
|
System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
|
|
17
|
+ urlhandler.postID("G", "Github");
|
|
18
|
+ urlhandler.postMessage("gjarant", "bell7692", "Is it working?");
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public void postID(String name, String github) throws JsonProcessingException {
|
|
22
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
23
|
+ ID idTest = new ID( name, github);
|
|
24
|
+ String payload = objectMapper.writeValueAsString(idTest);
|
|
25
|
+ MakeURLCall("/ids", "POST", payload);
|
10
|
26
|
}
|
11
|
27
|
|
|
28
|
+ public void postMessage(String fromId, String toid, String message) throws JsonProcessingException {
|
|
29
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
30
|
+ Messages messagesTest = new Messages(fromId, toid, message);
|
|
31
|
+ String payload = objectMapper.writeValueAsString(messagesTest);
|
|
32
|
+ String url = "/ids/" + toid + "/messages";
|
|
33
|
+ MakeURLCall(url, "POST", payload);
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+
|
12
|
37
|
public String get_ids() {
|
13
|
38
|
return MakeURLCall("/ids", "GET", "");
|
14
|
39
|
}
|
|
@@ -18,6 +43,30 @@ public class YouAreEll {
|
18
|
43
|
}
|
19
|
44
|
|
20
|
45
|
public String MakeURLCall(String mainurl, String method, String jpayload) {
|
|
46
|
+ String completeURL = "http://zipcode.rocks:8085" + mainurl;
|
|
47
|
+ GetRequest request = Unirest.get(completeURL);
|
|
48
|
+
|
|
49
|
+ if (method.equals("GET")) {
|
|
50
|
+ try {
|
|
51
|
+ return request.asJson().getBody().toString();
|
|
52
|
+ } catch (UnirestException e) {
|
|
53
|
+ e.printStackTrace();
|
|
54
|
+ }
|
|
55
|
+ }
|
|
56
|
+ else if (method.equals("POST")){
|
|
57
|
+ try {
|
|
58
|
+ return Unirest.post(completeURL).body(jpayload).asJson().getBody().toString();
|
|
59
|
+ } catch (UnirestException e) {
|
|
60
|
+ e.printStackTrace();
|
|
61
|
+ }
|
|
62
|
+ }
|
|
63
|
+// else if (method.equals("PUT")){
|
|
64
|
+// try {
|
|
65
|
+// return Unirest.put(completeURL).body(jpayload).asJson().getBody().toString();
|
|
66
|
+// } catch (UnirestException e) {
|
|
67
|
+// e.printStackTrace();
|
|
68
|
+// }
|
|
69
|
+// }
|
21
|
70
|
return "nada";
|
22
|
71
|
}
|
23
|
72
|
}
|