nafis nibir 6 gadus atpakaļ
vecāks
revīzija
d95daa7447

+ 7
- 2
Client/Client.iml Parādīt failu

@@ -9,6 +9,13 @@
9 9
     </content>
10 10
     <orderEntry type="inheritedJdk" />
11 11
     <orderEntry type="sourceFolder" forTests="false" />
12
+    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
13
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.5" level="project" />
14
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.5" level="project" />
15
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
16
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.5" level="project" />
17
+    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" />
18
+    <orderEntry type="library" name="Maven: com.fasterxml.woodstox:woodstox-core:5.0.3" level="project" />
12 19
     <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
13 20
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
14 21
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
@@ -22,7 +29,5 @@
22 29
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
23 30
     <orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.4" level="project" />
24 31
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
25
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
26
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
27 32
   </component>
28 33
 </module>

+ 41
- 0
Client/src/main/java/Id.java Parādīt failu

@@ -0,0 +1,41 @@
1
+public class Id {
2
+
3
+
4
+    String userid = "_";
5
+    String name;
6
+    String github;
7
+
8
+    public Id(String name, String github){
9
+        this.name = name;
10
+        this.github = github;
11
+    }
12
+    public String getUserid() {
13
+        return userid;
14
+    }
15
+
16
+    public void setUserid(String userid) {
17
+        this.userid = userid;
18
+    }
19
+
20
+    public String getName() {
21
+        return name;
22
+    }
23
+
24
+    public void setName(String name) {
25
+        this.name = name;
26
+    }
27
+
28
+    public String getGithub() {
29
+        return github;
30
+    }
31
+
32
+    public void setGithub(String github) {
33
+        this.github = github;
34
+    }
35
+
36
+    @Override
37
+    public String toString(){
38
+        return "{\"github\": " + github + ", \"name\": " + name + ", \"userid\": " + userid + "}";
39
+    }
40
+
41
+}

+ 56
- 0
Client/src/main/java/Message.java Parādīt failu

@@ -0,0 +1,56 @@
1
+public class Message {
2
+
3
+    String sequence = "_";
4
+    String timestamp = "_";
5
+    String fromid;
6
+    String message;
7
+    String toid;
8
+
9
+    public String getSequence() {
10
+        return sequence;
11
+    }
12
+
13
+    public void setSequence(String sequence) {
14
+        this.sequence = sequence;
15
+    }
16
+
17
+    public String getTimestamp() {
18
+        return timestamp;
19
+    }
20
+
21
+    public void setTimestamp(String timestamp) {
22
+        this.timestamp = timestamp;
23
+    }
24
+
25
+    public String getFromid() {
26
+        return fromid;
27
+    }
28
+
29
+    public void setFromid(String fromid) {
30
+        this.fromid = fromid;
31
+    }
32
+
33
+    public String getMessage() {
34
+        return message;
35
+    }
36
+
37
+    public void setMessage(String message) {
38
+        this.message = message;
39
+    }
40
+
41
+    public String getToid() {
42
+        return toid;
43
+    }
44
+
45
+    public void setToid(String toid) {
46
+        this.toid = toid;
47
+    }
48
+
49
+    @Override
50
+    public String toString(){
51
+        return "{\"toid\": " + toid + ", \"sequence\": " + sequence + ", \"message\": "
52
+                + message + ", \"fromid\": " + fromid + ", \"timestamp\": " + timestamp +"}";
53
+    }
54
+
55
+
56
+}

+ 25
- 15
Client/src/main/java/SimpleShell.java Parādīt failu

@@ -1,3 +1,10 @@
1
+
2
+import com.google.gson.Gson;
3
+import com.google.gson.GsonBuilder;
4
+import com.google.gson.JsonElement;
5
+import com.google.gson.JsonParser;
6
+import com.mashape.unirest.http.exceptions.UnirestException;
7
+
1 8
 import java.io.BufferedReader;
2 9
 import java.io.IOException;
3 10
 import java.io.InputStream;
@@ -9,10 +16,13 @@ public class SimpleShell {
9 16
 
10 17
 
11 18
     public static void prettyPrint(String output) {
12
-        // yep, make an effort to format things nicely, eh?
13
-        System.out.println(output);
19
+        Gson gson = new GsonBuilder().setPrettyPrinting().create();
20
+        JsonParser jp = new JsonParser();
21
+        JsonElement je = jp.parse(output);
22
+        String prettyJsonString = gson.toJson(je);
23
+        System.out.println(prettyJsonString);
14 24
     }
15
-    public static void main(String[] args) throws java.io.IOException {
25
+    public static void main(String[] args) throws java.io.IOException , UnirestException {
16 26
 
17 27
         YouAreEll webber = new YouAreEll();
18 28
         String commandLine;
@@ -58,19 +68,19 @@ public class SimpleShell {
58 68
 
59 69
                 // Specific Commands.
60 70
 
61
-//                // ids
62
-//                if (list.contains("ids")) {
63
-//                    String results = webber.get_ids();
64
-//                    SimpleShell.prettyPrint(results);
65
-//                    continue;
66
-//                }
71
+                // ids
72
+                if (list.contains("ids")) {
73
+                    String results = webber.get_ids();
74
+                    SimpleShell.prettyPrint(results);
75
+                    continue;
76
+                }
67 77
 //
68
-//                // messages
69
-//                if (list.contains("messages")) {
70
-//                    String results = webber.get_messages();
71
-//                    SimpleShell.prettyPrint(results);
72
-//                    continue;
73
-//                }
78
+                // messages
79
+                if (list.contains("messages")) {
80
+                    String results = webber.get_messages();
81
+                    SimpleShell.prettyPrint(results);
82
+                    continue;
83
+                }
74 84
 
75 85
                 //
76 86
                 // you need to add a bunch more.

+ 23
- 7
Client/src/main/java/YouAreEll.java Parādīt failu

@@ -10,29 +10,45 @@ public class YouAreEll {
10 10
     private static final String URL = "http://zipcode.rocks:8085";
11 11
 
12 12
     YouAreEll() {
13
+
13 14
     }
14 15
 
16
+
15 17
     public static void main(String[] args) throws UnirestException{
16 18
 
17
-           YouAreEll urlhandler = new YouAreEll();
18
-           System.out.println(urlhandler.get_ids());
19
-           System.out.println(urlhandler.get_messages());
19
+          YouAreEll urlhandler = new YouAreEll();
20
+          System.out.println(urlhandler.get_ids());
21
+          urlhandler.post_id("", "naf", "666");
22
+//        System.out.println(urlhandler.get_messages());
20 23
 //        System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
21 24
     }
22 25
 
23 26
     public String get_ids() throws UnirestException {
24
-        String result = MakeURLCall("/ids", "GET", "").getBody().getArray().toString();
25
-        return result;
27
+        return MakeURLCall("/ids").getBody().getArray().toString();
28
+    }
29
+
30
+    public void post_id(String githubid, String name, String userid) throws UnirestException{
31
+
32
+
33
+        Id id = new Id(name, userid);
34
+        if (!(userid.equals(""))){
35
+            id.setUserid(userid);
36
+        }
37
+
38
+        Unirest.post(URL + "/ids").body(id);
26 39
     }
27 40
 
28 41
     public String get_messages() throws UnirestException{
29
-        return MakeURLCall("/messages", "GET", "").getBody().getArray().toString();
42
+        return MakeURLCall("/messages").getBody().getArray().toString();
30 43
     }
31 44
 
32
-    public HttpResponse<JsonNode> MakeURLCall(String mainurl, String method, String jpayload) throws UnirestException {
45
+    public HttpResponse<JsonNode> MakeURLCall(String mainurl) throws UnirestException {
33 46
         mainurl = URL + mainurl;
34 47
         HttpResponse<JsonNode> jsonResponse = Unirest.get(mainurl).asJson();
48
+
35 49
         System.out.println(jsonResponse);
36 50
         return jsonResponse;
37 51
     }
52
+
53
+
38 54
 }

+ 7
- 2
YouAreEll.iml Parādīt failu

@@ -8,6 +8,13 @@
8 8
     </content>
9 9
     <orderEntry type="inheritedJdk" />
10 10
     <orderEntry type="sourceFolder" forTests="false" />
11
+    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
12
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.5" level="project" />
13
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.5" level="project" />
14
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
15
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.5" level="project" />
16
+    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" />
17
+    <orderEntry type="library" name="Maven: com.fasterxml.woodstox:woodstox-core:5.0.3" level="project" />
11 18
     <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
12 19
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
13 20
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
@@ -21,7 +28,5 @@
21 28
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
22 29
     <orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.4" level="project" />
23 30
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
24
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
25
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
26 31
   </component>
27 32
 </module>

+ 13
- 0
pom.xml Parādīt failu

@@ -13,6 +13,19 @@
13 13
     </modules>
14 14
 
15 15
     <dependencies>
16
+        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
17
+        <dependency>
18
+            <groupId>com.google.code.gson</groupId>
19
+            <artifactId>gson</artifactId>
20
+            <version>2.8.0</version>
21
+        </dependency>
22
+        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
23
+        <dependency>
24
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
25
+            <artifactId>jackson-dataformat-xml</artifactId>
26
+            <version>2.9.5</version>
27
+        </dependency>
28
+
16 29
         <dependency>
17 30
             <groupId>com.mashape.unirest</groupId>
18 31
             <artifactId>unirest-java</artifactId>