|
@@ -28,8 +28,23 @@ public class YouAreEll {
|
28
|
28
|
return null;
|
29
|
29
|
}
|
30
|
30
|
|
|
31
|
+ public void postID(String name, String gitHubID){
|
|
32
|
+ String jsonPackage = "{ \"userid\": \"-\", \"name\": \"" + name + "\", \"github\": \"" + gitHubID + "\"}";
|
|
33
|
+
|
|
34
|
+ System.out.println(MakeURLCall("/ids", "PUT", jsonPackage));
|
|
35
|
+ }
|
|
36
|
+
|
31
|
37
|
public String get_messages() {
|
32
|
|
- return MakeURLCall("/messages", "GET", "");
|
|
38
|
+ ObjectMapper jsonMapper = new ObjectMapper();
|
|
39
|
+ String jsonString = MakeURLCall("/messages", "GET", "");
|
|
40
|
+ try {
|
|
41
|
+ Messages[] messagesList = jsonMapper.readValue(jsonString, Messages[].class);
|
|
42
|
+ Messages[] last20 = Arrays.copyOf(messagesList, 20);
|
|
43
|
+ return Arrays.toString(last20);
|
|
44
|
+ } catch (IOException e) {
|
|
45
|
+ e.printStackTrace();
|
|
46
|
+ }
|
|
47
|
+ return null;
|
33
|
48
|
}
|
34
|
49
|
|
35
|
50
|
public String MakeURLCall(String mainurl, String method, String jpayload) {
|
|
@@ -38,11 +53,12 @@ public class YouAreEll {
|
38
|
53
|
if (method.equals("GET")) {
|
39
|
54
|
return Unirest.get("http://zipcode.rocks:8085" + mainurl).asString().getBody();
|
40
|
55
|
}
|
|
56
|
+ if (method.equals("PUT")){
|
|
57
|
+ return Unirest.post("http://zipcode.rocks:8085" + mainurl).body(jpayload).asString().getStatusText();
|
|
58
|
+ }
|
41
|
59
|
}catch (UnirestException e){
|
42
|
60
|
e.printStackTrace();
|
43
|
61
|
}
|
44
|
|
- return null;
|
|
62
|
+ return null;
|
45
|
63
|
}
|
46
|
|
-
|
47
|
|
-
|
48
|
64
|
}
|