Browse Source

ID post working

Anthony Jordan 6 years ago
parent
commit
feefff40bc

+ 5
- 0
Client/src/main/java/IDs.java View File

@@ -27,4 +27,9 @@ public class IDs {
27 27
     public void setGithub(String github) {
28 28
         this.github = github;
29 29
     }
30
+
31
+    @Override
32
+    public String toString(){
33
+        return "\n\nUserId = " + userid + "\nName = " + name + "\nGitHub = " + github;
34
+    }
30 35
 }

+ 6
- 0
Client/src/main/java/Messages.java View File

@@ -45,4 +45,10 @@ public class Messages {
45 45
     public void setMessage(String message) {
46 46
         this.message = message;
47 47
     }
48
+
49
+    @Override
50
+    public String toString(){
51
+        return "\n\nSequence = " + sequence + "\nTime Stamp = " + timestamp + "\nFrom Id = " + fromid + "\nTo Id = " + toid
52
+                + "\nMessage = " + message;
53
+    }
48 54
 }

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

@@ -59,14 +59,18 @@ public class SimpleShell {
59 59
                 // Specific Commands.
60 60
 
61 61
                 // ids
62
-                if (list.contains("ids")) {
63
-                    String results = webber.get_ids();
64
-                    SimpleShell.prettyPrint(results);
62
+                if (list.get(0).equals("ids")) {
63
+                    if (list.size() > 1){
64
+                        webber.postID(list.get(1), list.get(2));
65
+                    } else {
66
+                        String results = webber.get_ids();
67
+                        SimpleShell.prettyPrint(results);
68
+                    }
65 69
                     continue;
66 70
                 }
67 71
 
68 72
                 // messages
69
-                if (list.contains("messages")) {
73
+                if (list.get(0).equals("messages")) {
70 74
                     String results = webber.get_messages();
71 75
                     SimpleShell.prettyPrint(results);
72 76
                     continue;

+ 20
- 4
Client/src/main/java/YouAreEll.java View File

@@ -28,8 +28,23 @@ public class YouAreEll {
28 28
         return null;
29 29
     }
30 30
 
31
+    public void postID(String name, String gitHubID){
32
+        String jsonPackage = "{ \"userid\": \"-\", \"name\": \"" + name + "\", \"github\": \"" + gitHubID + "\"}";
33
+
34
+        System.out.println(MakeURLCall("/ids", "PUT", jsonPackage));
35
+    }
36
+
31 37
     public String get_messages() {
32
-        return MakeURLCall("/messages", "GET", "");
38
+        ObjectMapper jsonMapper = new ObjectMapper();
39
+        String jsonString = MakeURLCall("/messages", "GET", "");
40
+        try {
41
+            Messages[] messagesList = jsonMapper.readValue(jsonString, Messages[].class);
42
+            Messages[] last20 = Arrays.copyOf(messagesList, 20);
43
+            return Arrays.toString(last20);
44
+        } catch (IOException e) {
45
+            e.printStackTrace();
46
+        }
47
+        return null;
33 48
     }
34 49
 
35 50
     public String MakeURLCall(String mainurl, String method, String jpayload) {
@@ -38,11 +53,12 @@ public class YouAreEll {
38 53
             if (method.equals("GET")) {
39 54
                 return Unirest.get("http://zipcode.rocks:8085" + mainurl).asString().getBody();
40 55
             }
56
+            if (method.equals("PUT")){
57
+                return Unirest.post("http://zipcode.rocks:8085" + mainurl).body(jpayload).asString().getStatusText();
58
+            }
41 59
         }catch (UnirestException e){
42 60
             e.printStackTrace();
43 61
         }
44
-            return null;
62
+        return null;
45 63
     }
46
-
47
-
48 64
 }