Ver código fonte

going to lunch, made progress

Keith Brinker 6 anos atrás
pai
commit
105c9871ea

+ 40
- 0
Client/src/main/java/Messages.java Ver arquivo

@@ -24,6 +24,46 @@ public class Messages {
24 24
                 '}';
25 25
     }
26 26
 
27
+    public String getSequence() {
28
+        return sequence;
29
+    }
30
+
31
+    public void setSequence(String sequence) {
32
+        this.sequence = sequence;
33
+    }
34
+
35
+    public String getTimestamp() {
36
+        return timestamp;
37
+    }
38
+
39
+    public void setTimestamp(String timestamp) {
40
+        this.timestamp = timestamp;
41
+    }
42
+
43
+    public String getFromid() {
44
+        return fromid;
45
+    }
46
+
47
+    public void setFromid(String fromid) {
48
+        this.fromid = fromid;
49
+    }
50
+
51
+    public String getToid() {
52
+        return toid;
53
+    }
54
+
55
+    public void setToid(String toid) {
56
+        this.toid = toid;
57
+    }
58
+
59
+    public String getMessage() {
60
+        return message;
61
+    }
62
+
63
+    public void setMessage(String message) {
64
+        this.message = message;
65
+    }
66
+
27 67
 
28 68
 //timestamp = "2018-03-21T01:00:00.0Z"
29 69
 

+ 22
- 2
Client/src/main/java/SimpleShell.java Ver arquivo

@@ -1,3 +1,5 @@
1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+
1 3
 import java.io.BufferedReader;
2 4
 import java.io.IOException;
3 5
 import java.io.InputStream;
@@ -10,6 +12,15 @@ public class SimpleShell {
10 12
 
11 13
     public static void prettyPrint(String output) {
12 14
         // yep, make an effort to format things nicely, eh?
15
+        ObjectMapper mapper = new ObjectMapper();
16
+        try {
17
+            Object json = mapper.readValue(output, Object.class);
18
+            String prettyPrint = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
19
+            System.out.println(prettyPrint);
20
+        } catch (IOException e) {
21
+            e.printStackTrace();
22
+        }
23
+
13 24
         System.out.println(output);
14 25
     }
15 26
     public static void main(String[] args) throws java.io.IOException {
@@ -18,7 +29,7 @@ public class SimpleShell {
18 29
         String commandLine;
19 30
         BufferedReader console = new BufferedReader
20 31
                 (new InputStreamReader(System.in));
21
-
32
+        ObjectMapper mapper = new ObjectMapper();
22 33
         ProcessBuilder pb = new ProcessBuilder();
23 34
         List<String> history = new ArrayList<String>();
24 35
         int index = 0;
@@ -59,12 +70,21 @@ public class SimpleShell {
59 70
                 // Specific Commands.
60 71
 
61 72
                 // ids
62
-                if (list.contains("ids")) {
73
+                if (list.contains("ids") && list.size() ==1) {
63 74
                     String results = webber.get_ids();
64 75
                     SimpleShell.prettyPrint(results);
65 76
                     continue;
66 77
                 }
67 78
 
79
+                if (list.contains("ids") && list.size() ==3){
80
+                    String name = list.get(1); //name
81
+                    String github= list.get(2);
82
+                    User user = new User(name, github);
83
+                    String newUserInfo = mapper.writeValueAsString(user);
84
+                    webber.MakeURLCall("/ids", "POST",newUserInfo);
85
+                    continue;
86
+                }
87
+
68 88
                 // messages
69 89
                 if (list.contains("messages")) {
70 90
                     String results = webber.get_messages();

+ 24
- 0
Client/src/main/java/User.java Ver arquivo

@@ -25,4 +25,28 @@ public class User {
25 25
                 ", github='" + github + '\'' +
26 26
                 '}';
27 27
     }
28
+
29
+    public String getUserid() {
30
+        return userid;
31
+    }
32
+
33
+    public void setUserid(String userid) {
34
+        this.userid = userid;
35
+    }
36
+
37
+    public String getName() {
38
+        return name;
39
+    }
40
+
41
+    public void setName(String name) {
42
+        this.name = name;
43
+    }
44
+
45
+    public String getGithub() {
46
+        return github;
47
+    }
48
+
49
+    public void setGithub(String github) {
50
+        this.github = github;
51
+    }
28 52
 }

+ 13
- 2
Client/src/main/java/YouAreEll.java Ver arquivo

@@ -1,3 +1,4 @@
1
+import com.fasterxml.jackson.databind.ObjectMapper;
1 2
 import jdk.nashorn.internal.ir.RuntimeNode;
2 3
 import okhttp3.*;
3 4
 
@@ -15,7 +16,16 @@ public class YouAreEll {
15 16
         YouAreEll urlhandler = new YouAreEll();
16 17
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
17 18
         System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
18
-    }
19
+
20
+
21
+//            ObjectMapper mapper = new ObjectMapper();
22
+//            jpayload = mapper.writeValueAsString();
23
+
24
+
25
+        }
26
+
27
+
28
+
19 29
 
20 30
     public String get_ids() {
21 31
         return MakeURLCall("/ids", "GET", "");
@@ -37,7 +47,7 @@ public class YouAreEll {
37 47
             } catch (IOException ioe) {
38 48
                 ioe.printStackTrace();
39 49
             }
40
-        } else if (method.equals("PUT")) {
50
+        } else if (method.equals("POST")) {
41 51
             RequestBody body = RequestBody.create(JSON, jpayload);
42 52
             Request request = new Request.Builder().url(myUrl).post(body).build();
43 53
 
@@ -47,6 +57,7 @@ public class YouAreEll {
47 57
                 e.printStackTrace();
48 58
             }
49 59
         }
60
+
50 61
         return "nada";
51 62
     }
52 63