Browse Source

almost done. need to fix few

thulasi 6 years ago
parent
commit
b100ebb72d

+ 1
- 0
Client/Client.iml View File

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

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

3
 import com.mashape.unirest.http.Unirest;
3
 import com.mashape.unirest.http.Unirest;
4
 import com.mashape.unirest.http.exceptions.UnirestException;
4
 import com.mashape.unirest.http.exceptions.UnirestException;
5
 
5
 
6
-public class IdController {
6
+public class IdOperations {
7
     private Console console;
7
     private Console console;
8
 
8
 
9
-    public IdController(){
9
+    public IdOperations(){
10
         console = new Console();
10
         console = new Console();
11
     }
11
     }
12
 
12
 
23
     private String readGithub(){
23
     private String readGithub(){
24
         return console.readString("Enter Github");
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
 import com.mashape.unirest.http.Unirest;
3
 import com.mashape.unirest.http.Unirest;
4
 import com.mashape.unirest.http.exceptions.UnirestException;
4
 import com.mashape.unirest.http.exceptions.UnirestException;
5
 
5
 
6
-public class MessageController {
6
+public class MessageOperations {
7
     private Console console;
7
     private Console console;
8
 
8
 
9
-    public MessageController(){
9
+    public MessageOperations(){
10
         console = new Console();
10
         console = new Console();
11
     }
11
     }
12
 
12
 

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

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