|
@@ -1,12 +1,14 @@
|
1
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
1
|
+import Entity.GitHubUser;
|
|
2
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
3
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
2
|
4
|
import com.mashape.unirest.http.HttpResponse;
|
3
|
5
|
import com.mashape.unirest.http.JsonNode;
|
4
|
|
-import com.mashape.unirest.http.ObjectMapper;
|
5
|
6
|
import com.mashape.unirest.http.Unirest;
|
6
|
7
|
import com.mashape.unirest.http.exceptions.UnirestException;
|
7
|
8
|
import com.mashape.unirest.request.HttpRequestWithBody;
|
8
|
9
|
|
9
|
|
-import java.io.IOException;
|
|
10
|
+import java.util.ArrayList;
|
|
11
|
+import java.util.List;
|
10
|
12
|
|
11
|
13
|
public class YouAreEll {
|
12
|
14
|
|
|
@@ -14,37 +16,50 @@ public class YouAreEll {
|
14
|
16
|
}
|
15
|
17
|
|
16
|
18
|
public static void main(String[] args) {
|
|
19
|
+// jackson mapper
|
|
20
|
+ ObjectMapper mapper = new ObjectMapper();
|
17
|
21
|
YouAreEll urlhandler = new YouAreEll();
|
18
|
22
|
|
19
|
|
- Unirest.setObjectMapper(new ObjectMapper() {
|
20
|
|
- private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
|
21
|
|
- = new com.fasterxml.jackson.databind.ObjectMapper();
|
|
23
|
+// Unirest.setObjectMapper(mapper);
|
|
24
|
+// list to store github users
|
|
25
|
+ String json = urlhandler.MakeURLCall("/ids", "GET", "");
|
|
26
|
+ System.out.println(json);
|
|
27
|
+ List<GitHubUser> list = new ArrayList<GitHubUser>();
|
|
28
|
+ try {
|
|
29
|
+// type reference is a list of github users
|
|
30
|
+ list = mapper.readValue(json, new TypeReference<List<GitHubUser>>(){});
|
|
31
|
+ System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(list));
|
22
|
32
|
|
23
|
|
- public <T> T readValue(String value, Class<T> valueType) {
|
24
|
|
- try {
|
25
|
|
- return jacksonObjectMapper.readValue(value, valueType);
|
26
|
|
- } catch (IOException e) {
|
27
|
|
- throw new RuntimeException(e);
|
28
|
|
- }
|
29
|
|
- }
|
|
33
|
+ } catch (Exception e){
|
|
34
|
+ e.printStackTrace();
|
|
35
|
+ }
|
30
|
36
|
|
31
|
|
- public String writeValue(Object value) {
|
32
|
|
- try {
|
33
|
|
- return jacksonObjectMapper.writeValueAsString(value);
|
34
|
|
- } catch (JsonProcessingException e) {
|
35
|
|
- throw new RuntimeException(e);
|
36
|
|
- }
|
37
|
|
- }
|
38
|
|
- });
|
|
37
|
+ for(GitHubUser gitHubUser : list){
|
|
38
|
+ System.out.println(gitHubUser.toString());
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ GitHubUser april = new GitHubUser("aprilcr8777", "APRILAGAIN", "32585650");
|
|
42
|
+ try {
|
|
43
|
+ String jsonPayLoad = mapper.writeValueAsString(april);
|
|
44
|
+ System.out.println(jsonPayLoad);
|
39
|
45
|
|
40
|
|
- System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
|
41
|
|
- System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
|
|
46
|
+ urlhandler.MakeURLCall("/ids", "POST", mapper.writeValueAsString(april));
|
|
47
|
+ } catch (Exception e){
|
|
48
|
+ e.printStackTrace();
|
|
49
|
+ }
|
42
|
50
|
}
|
43
|
51
|
|
44
|
52
|
public String get_ids() {
|
45
|
53
|
return MakeURLCall("/ids", "GET", "");
|
46
|
54
|
}
|
47
|
55
|
|
|
56
|
+ public List<GitHubUser> get_idsAsList() throws Exception{
|
|
57
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
58
|
+
|
|
59
|
+ return objectMapper.readValue(MakeURLCall("/ids", "GET", ""), new TypeReference<List<GitHubUser>>(){});
|
|
60
|
+
|
|
61
|
+ }
|
|
62
|
+
|
48
|
63
|
public String get_messages() {
|
49
|
64
|
return MakeURLCall("/messages", "GET", "");
|
50
|
65
|
}
|