Browse Source

POST working

Haysel Santiago 6 years ago
parent
commit
7cd6ac696f

+ 5
- 5
Client/src/main/java/ID.java View File

1
 public class ID {
1
 public class ID {
2
 
2
 
3
-    public ID(String uderID, String name, String gitHub) {
3
+    private String name;
4
+    private String github;
5
+
6
+    public ID(String userID, String name, String github) {
4
         this.userID = userID;
7
         this.userID = userID;
5
         this.name = name;
8
         this.name = name;
6
         this.github = github;
9
         this.github = github;
7
     }
10
     }
8
-    public ID(String nme, String github) {
11
+    public ID(String name, String github) {
9
         this.name = name;
12
         this.name = name;
10
         this.github = github;
13
         this.github = github;
11
     }
14
     }
36
         this.github = github;
39
         this.github = github;
37
     }
40
     }
38
 
41
 
39
-    private String name;
40
-    private String github;
41
-
42
     @Override
42
     @Override
43
     public String toString() {
43
     public String toString() {
44
         return "Id{" +
44
         return "Id{" +

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

59
     public void setMessage(String message) {
59
     public void setMessage(String message) {
60
         this.message = message;
60
         this.message = message;
61
     }
61
     }
62
-
63
 }
62
 }

+ 18
- 1
Client/src/main/java/SimpleShell.java View File

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

+ 6
- 1
Client/src/main/java/YouAreEll.java View File

1
+import com.fasterxml.jackson.databind.ObjectMapper;
1
 import okhttp3.*;
2
 import okhttp3.*;
2
 
3
 
3
 import java.io.IOException;
4
 import java.io.IOException;
35
             } catch (IOException e) {
36
             } catch (IOException e) {
36
                 e.printStackTrace();
37
                 e.printStackTrace();
37
             }
38
             }
38
-        } else if (method.equals("PUT")) {
39
+        } else if (method.equals("POST")) {
39
             RequestBody body = RequestBody.create(JSON, jpayload);
40
             RequestBody body = RequestBody.create(JSON, jpayload);
40
             Request request = new Request.Builder().url(myURL).post(body).build();
41
             Request request = new Request.Builder().url(myURL).post(body).build();
41
 
42
 
45
                 e.printStackTrace();
46
                 e.printStackTrace();
46
             }
47
             }
47
         }
48
         }
49
+//        else if (method.equals("PUT")) {
50
+//            ObjectMapper objectMapper = new ObjectMapper();
51
+//
52
+//        }
48
         return "nothing";
53
         return "nothing";
49
     }
54
     }
50
 }
55
 }