Browse Source

almost done. need to fix few

thulasi 6 years ago
parent
commit
b100ebb72d

+ 1
- 0
Client/Client.iml View File

@@ -5,6 +5,7 @@
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
7 7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
8 9
       <excludeFolder url="file://$MODULE_DIR$/target" />
9 10
     </content>
10 11
     <orderEntry type="inheritedJdk" />

Client/src/main/java/IdController.java → Client/src/main/java/IdOperations.java View File

@@ -3,10 +3,10 @@ import com.mashape.unirest.http.JsonNode;
3 3
 import com.mashape.unirest.http.Unirest;
4 4
 import com.mashape.unirest.http.exceptions.UnirestException;
5 5
 
6
-public class IdController {
6
+public class IdOperations {
7 7
     private Console console;
8 8
 
9
-    public IdController(){
9
+    public IdOperations(){
10 10
         console = new Console();
11 11
     }
12 12
 
@@ -23,4 +23,15 @@ public class IdController {
23 23
     private String readGithub(){
24 24
         return console.readString("Enter Github");
25 25
     }
26
+
27
+    public String updateId(){
28
+
29
+        String id = console.readString("Enter your user id: ");
30
+        String name = console.readString("Enter the new name: ");
31
+        String github = console.readString("Enter new github id: ");
32
+
33
+        return "{\"github\":\"" + github + "\"\n"
34
+                + "\"name\":\"" + name + "\"\n" +
35
+                "\"userid\":\"" + id + "\"}";
36
+    }
26 37
 }

Client/src/main/java/MessageController.java → Client/src/main/java/MessageOperations.java View File

@@ -3,10 +3,10 @@ import com.mashape.unirest.http.JsonNode;
3 3
 import com.mashape.unirest.http.Unirest;
4 4
 import com.mashape.unirest.http.exceptions.UnirestException;
5 5
 
6
-public class MessageController {
6
+public class MessageOperations {
7 7
     private Console console;
8 8
 
9
-    public MessageController(){
9
+    public MessageOperations(){
10 10
         console = new Console();
11 11
     }
12 12
 

+ 16
- 15
Client/src/main/java/YouAreEll.java View File

@@ -5,14 +5,15 @@ import com.mashape.unirest.http.exceptions.UnirestException;
5 5
 
6 6
 public class YouAreEll {
7 7
     static Console console;
8
-    static IdController idController;
9
-    static MessageController messageController;
8
+    static IdOperations idController;
9
+    static MessageOperations messageController;
10 10
     static String url;
11
+    static Message message;
11 12
 
12 13
     YouAreEll() {
13 14
         console = new Console();
14
-        idController = new IdController();
15
-        messageController = new MessageController();
15
+        idController = new IdOperations();
16
+        messageController = new MessageOperations();
16 17
         url = "http://zipcode.rocks:8085";
17 18
     }
18 19
 
@@ -37,6 +38,7 @@ public class YouAreEll {
37 38
                     get_messages();
38 39
                     break;
39 40
                 case "5":
41
+                    putId();
40 42
                     break;
41 43
                 case "6":
42 44
                     System.exit(0);
@@ -69,17 +71,16 @@ public class YouAreEll {
69 71
         }
70 72
     }
71 73
 
72
-   /* public void putId(Id id){
74
+    public static void putId(){
73 75
         try {
74 76
             Unirest.put(url + "/ids")
75 77
                     .header("accept", "application/json")
76
-                    .body(id.toString())
78
+                    .body(idController.updateId())
77 79
                     .asJson();
78 80
         } catch (UnirestException e) {
79 81
             e.printStackTrace();
80 82
         }
81
-
82
-    }*/
83
+    }
83 84
 
84 85
     public static String get_messages() {
85 86
         try {
@@ -95,19 +96,19 @@ public class YouAreEll {
95 96
         }
96 97
     }
97 98
 
99
+    private static void messageGenerator(){
100
+        message = messageController.createMessage();
101
+    }
102
+
98 103
     public static void postMessages() {
104
+        messageGenerator();
99 105
         try {
100
-            Unirest.post(url + "/ids")
106
+            Unirest.post(url + "/ids/" + message.getFromid() + "messages")
101 107
                     .header("accept", "application/json")
102
-                    .body(messageController.createMessage().toString())
108
+                    .body(message.toString())
103 109
                     .asJson();
104 110
         } catch (UnirestException e) {
105 111
             e.printStackTrace();
106 112
         }
107 113
     }
108
-
109
-
110
-    public String MakeURLCall(String mainurl, String method, String jpayload) {
111
-        return "nada";
112
-    }
113 114
 }