Browse Source

god help me do PUT

nafis nibir 6 years ago
parent
commit
d362b8f6b4

+ 7
- 0
Client/src/main/java/Message.java View File

6
     private String toid;
6
     private String toid;
7
     private String message;
7
     private String message;
8
 
8
 
9
+    public Message(String sequence, String fromid, String toid, String message) {
10
+        this.sequence = sequence;
11
+        this.fromid = fromid;
12
+        this.toid = toid;
13
+        this.message = message;
14
+    }
15
+
9
     public String getSequence() {
16
     public String getSequence() {
10
         return sequence;
17
         return sequence;
11
     }
18
     }

+ 24
- 4
Client/src/main/java/SimpleShell.java View File

88
 
88
 
89
                 // messages
89
                 // messages
90
                 if (list.contains("messages")) {
90
                 if (list.contains("messages")) {
91
-                    String results = webber.get_messages();
92
-                    SimpleShell.prettyPrint(results);
91
+                    if(list.size() == 1) {
92
+                        String results = webber.get_messages();
93
+                        SimpleShell.prettyPrint(results);
94
+                    } else if (list.size() == 2){
95
+                        String results = webber.get_messages(list.get(1));
96
+                        SimpleShell.prettyPrint(results);
97
+                    } else if (list.size() == 3){
98
+                        String results = webber.get_messages(list.get(1), list.get(2));
99
+                        SimpleShell.prettyPrint(results);
100
+                    }
101
+                    continue;
102
+                }
103
+                // send
104
+
105
+                if(list.contains("send")){
106
+                    if(list.size() == 3){
107
+                        Message msg = new Message("-", list.get(1), "", list.get(2));
108
+                        String response = webber.post_messages(msg);
109
+                        SimpleShell.prettyPrint(response);
110
+                    } else if (list.size() == 4){
111
+                        Message msg = new Message("-", list.get(1), list.get(2), list.get(3));
112
+                        String response = webber.post_messages(msg);
113
+                        SimpleShell.prettyPrint(response);
114
+                    }
93
                     continue;
115
                     continue;
94
                 }
116
                 }
95
-                // you need to add a bunch more.
96
-
97
                 //!! command returns the last command in history
117
                 //!! command returns the last command in history
98
                 if (list.get(list.size() - 1).equals("!!")) {
118
                 if (list.get(list.size() - 1).equals("!!")) {
99
                     pb.command(history.get(history.size() - 2));
119
                     pb.command(history.get(history.size() - 2));

+ 17
- 2
Client/src/main/java/YouAreEll.java View File

34
         return MakeURLCall("/ids", "PUT", payload);
34
         return MakeURLCall("/ids", "PUT", payload);
35
     }
35
     }
36
 
36
 
37
-    public String get_messages() throws IOException{
37
+    public String get_messages(String...path) throws IOException{
38
+        String mainurl = "/messages";
39
+        if (path.length > 0)
40
+            mainurl = "/ids/" + path[0] + mainurl;
38
 
41
 
39
-        return MakeURLCall("/messages", "GET", "");
42
+        if (path.length > 1)
43
+            mainurl = mainurl + "/" + path[1];
44
+
45
+        return MakeURLCall(mainurl, "GET", "");
46
+    }
47
+
48
+    public String post_messages(Message message) throws IOException{
49
+        String jpayload = mapper.writeValueAsString(message);
50
+        if (message.getToid().equalsIgnoreCase("")){
51
+
52
+            return MakeURLCall("/ids/" + message.getToid() + "/message", "POST", jpayload);
53
+        }
54
+        return MakeURLCall("/ids/" + message.getFromid() + "/messages", "POST", jpayload);
40
     }
55
     }
41
 
56
 
42
     public String MakeURLCall(String mainurl, String method, String jpayload) throws IOException {
57
     public String MakeURLCall(String mainurl, String method, String jpayload) throws IOException {