Bladeren bron

god help me do PUT

nafis nibir 6 jaren geleden
bovenliggende
commit
d362b8f6b4
3 gewijzigde bestanden met toevoegingen van 48 en 6 verwijderingen
  1. 7
    0
      Client/src/main/java/Message.java
  2. 24
    4
      Client/src/main/java/SimpleShell.java
  3. 17
    2
      Client/src/main/java/YouAreEll.java

+ 7
- 0
Client/src/main/java/Message.java Bestand weergeven

@@ -6,6 +6,13 @@ public class Message {
6 6
     private String toid;
7 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 16
     public String getSequence() {
10 17
         return sequence;
11 18
     }

+ 24
- 4
Client/src/main/java/SimpleShell.java Bestand weergeven

@@ -88,12 +88,32 @@ public class SimpleShell {
88 88
 
89 89
                 // messages
90 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 115
                     continue;
94 116
                 }
95
-                // you need to add a bunch more.
96
-
97 117
                 //!! command returns the last command in history
98 118
                 if (list.get(list.size() - 1).equals("!!")) {
99 119
                     pb.command(history.get(history.size() - 2));

+ 17
- 2
Client/src/main/java/YouAreEll.java Bestand weergeven

@@ -34,9 +34,24 @@ public class YouAreEll {
34 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 57
     public String MakeURLCall(String mainurl, String method, String jpayload) throws IOException {