Browse Source

even closer, almost finished

Carolynn Vansant 6 years ago
parent
commit
4dade8d547
4 changed files with 71 additions and 63 deletions
  1. 3
    2
      Client/Client.iml
  2. 9
    3
      Client/pom.xml
  3. 39
    38
      Client/src/main/java/SimpleShell.java
  4. 20
    20
      Client/src/main/java/YouAreEll.java

+ 3
- 2
Client/Client.iml View File

@@ -12,10 +12,11 @@
12 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
13 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" />
14 14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
15
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:fluent-hc:4.5.5" level="project" />
16
-    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
15
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
16
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
17 17
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
18 18
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
19
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
19 20
     <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
20 21
   </component>
21 22
 </module>

+ 9
- 3
Client/pom.xml View File

@@ -25,10 +25,16 @@
25 25
             <artifactId>jackson-databind</artifactId>
26 26
             <version>2.9.4</version>
27 27
         </dependency>
28
+        <!--<dependency>-->
29
+            <!--<groupId>org.apache.httpcomponents</groupId>-->
30
+            <!--<artifactId>fluent-hc</artifactId>-->
31
+            <!--<version>4.5.5</version>-->
32
+        <!--</dependency>-->
28 33
         <dependency>
29
-            <groupId>org.apache.httpcomponents</groupId>
30
-            <artifactId>fluent-hc</artifactId>
31
-            <version>4.5.5</version>
34
+            <groupId>com.squareup.okhttp3</groupId>
35
+            <artifactId>okhttp</artifactId>
36
+            <version>3.10.0</version>
32 37
         </dependency>
38
+
33 39
     </dependencies>
34 40
 </project>

+ 39
- 38
Client/src/main/java/SimpleShell.java View File

@@ -49,63 +49,64 @@ public class SimpleShell {
49 49
                 MessageController mesCont = new MessageController();
50 50
                 IdController idCont = new IdController();
51 51
 
52
-
53 52
                 if (commandLine.equalsIgnoreCase("ids")) {
54
-                    System.out.println("To retrieve all registered github ids, press enter\nTo register a new id " +
55
-                            "or change the name associated, type the name followed by the github id");
53
+                    String results = "";
54
+                    System.out.println("To retrieve all registered github ids, press enter\n" +
55
+                            "To register a new id or change the name associated, type your name");
56 56
                     specificCommand = console.readLine();
57
-                    if(specificCommand.equals("\n")) {
58
-                        String results = idCont.get_ids(commandList);
59
-                        SimpleShell.prettyPrint(results);
60
-                        continue;
57
+                    if(specificCommand.equals("")) {
58
+                        results = idCont.get_ids(commandList);
61 59
                     } else {
62
-                        String [] c = specificCommand.split(" ");
63
-                        commandList.addAll(Arrays.asList(c));
64
-                        String save = idCont.saveId(commandList);
65
-                        SimpleShell.prettyPrint(save);
60
+                        commandList.add(specificCommand);
61
+                        System.out.println("Please enter your github id");
62
+                        specificCommand = console.readLine();
63
+                        commandList.add(specificCommand);
64
+                        results = idCont.saveId(commandList);
66 65
                     }
66
+                    SimpleShell.prettyPrint(results);
67
+                    continue;
67 68
                 }
68 69
 
69 70
                 if (commandLine.equals("messages")) {
71
+                    String results = "";
70 72
                     System.out.println("To retrieve the last 20 messages posted on the timeline, press enter\n" +
71 73
                             "To retrieve the last twenty messages sent to you enter your github id");
72 74
                     specificCommand = console.readLine();
73
-                    if(specificCommand.equals("\n")) {
74
-                        String results = mesCont.get_messages(commandList);
75
-                        SimpleShell.prettyPrint(results);
76
-                        continue;
75
+                    if(specificCommand.equals("\n") || specificCommand.equals("")) {
76
+                        results = mesCont.get_messages(commandList);
77 77
                     } else {
78 78
                         commandList.add(specificCommand);
79
-                        String results = mesCont.get_my_messages(commandList);
80
-                        SimpleShell.prettyPrint(results);
79
+                        results = mesCont.get_my_messages(commandList);
81 80
                     }
81
+                    SimpleShell.prettyPrint(results);
82
+                    continue;
82 83
                 }
83 84
 
84 85
 
85 86
                 if(commandLine.equalsIgnoreCase("send")){
86
-                    System.out.println("To send a message on the timeline type in 'your message' and your github id.\n" +
87
-                            "To send a message to a friend, type 'your message', within single quotes, followed by your github id and then the");
87
+                    String results = "";
88
+                    System.out.println("Please enter your message");
88 89
                     specificCommand = console.readLine();
89
-                    Pattern pattern = Pattern.compile("'.+'");
90
-                    Matcher matcher = pattern.matcher(specificCommand);
91
-                    if(matcher.find()){
92
-                        String one = matcher.group();
93
-                        String two = specificCommand.substring(matcher.end());
94
-                        String[] twoSplit = two.split(" ");
95
-                        commandList.add(one);
96
-                        if(twoSplit.length == 1){
97
-                            commandList.add(twoSplit[0]);
98
-                            String results = mesCont.post_world(commandList);
99
-                            SimpleShell.prettyPrint(results);
100
-                        }
101
-                        if(twoSplit.length == 2){
102
-                            commandList.add(twoSplit[0]);
103
-                            commandList.add(twoSplit[1]);
104
-                            String results = mesCont.post_friend(commandList);
105
-                            SimpleShell.prettyPrint(results);
106
-                        }
90
+                    if(!specificCommand.equals("")) {
91
+                        commandList.add(specificCommand);
92
+                    }
93
+                    System.out.println(("Enter your github id"));
94
+                    if(!specificCommand.equals("")) {
95
+                        commandList.add(specificCommand);
96
+                        results = mesCont.post_world(commandList);
97
+                    }
98
+                    System.out.println(("If you wish to send your message to another github user, enter their github id." +
99
+                            "If you wish to send a general message to the timeline, press enter"));
100
+                    if (specificCommand.equals("")) {
101
+                        results = mesCont.post_world(commandList);
102
+                    }
103
+                    if(!specificCommand.equals("")) {
104
+                        commandList.add(specificCommand);
105
+                        results = mesCont.post_friend(commandList);
106
+                    }
107
+                    SimpleShell.prettyPrint(results);
108
+                    continue;
107 109
                     }
108
-                }
109 110
 
110 111
 
111 112
                 //print history, moved it here so full commands will be in history

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

@@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
2 2
 import org.apache.http.client.fluent.*;
3 3
 import com.fasterxml.jackson.databind.*;
4 4
 import java.io.IOException;
5
+import javax.swing.*;
5 6
 
6 7
 
7 8
 public class YouAreEll {
@@ -19,32 +20,31 @@ public class YouAreEll {
19 20
         } catch (JsonProcessingException e) {
20 21
             e.printStackTrace();
21 22
         }
22
-        System.out.println(urlhandler.makeURLCall("/ids", "GET", payload));
23
+        System.out.println(urlhandler.makeURLCall("/ids", "POST", payload));
23 24
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
24 25
     }
25 26
 
26 27
     public String makeURLCall(String mainurl, String method, String jpayload) {
27
-        ProcessBuilder processBuilder = new ProcessBuilder();
28 28
         String fullUrl = "http://zipcode.rocks:8085" + mainurl;
29 29
         String requestReturn = "";
30
-        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("get")){
31
-            try {
32
-                requestReturn = Request.Get(fullUrl).execute().returnContent().asString();
33
-
34
-            } catch (IOException e) {
35
-                e.printStackTrace();
36
-            }
37
-        }
38
-        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("post")){
39
-            requestReturn = Request.Post(jpayload).toString();
40
-        }
41
-        if(mainurl.equalsIgnoreCase("/messages")){
42
-            try {
43
-                Request.Get(fullUrl).execute().returnContent();
44
-            } catch (IOException e) {
45
-                e.printStackTrace();
46
-            }
47
-        }
30
+//        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("get")){
31
+//            try {
32
+//                requestReturn = Request.Get(fullUrl).execute().returnContent().asString();
33
+//
34
+//            } catch (IOException e) {
35
+//                e.printStackTrace();
36
+//            }
37
+//        }
38
+//        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("post")){
39
+//            requestReturn = Request.Post(jpayload).toString();
40
+//        }
41
+//        if(mainurl.equalsIgnoreCase("/messages")){
42
+//            try {
43
+//                Request.Get(fullUrl).execute().returnContent();
44
+//            } catch (IOException e) {
45
+//                e.printStackTrace();
46
+//            }
47
+//        }
48 48
         return requestReturn;
49 49
     }
50 50