Procházet zdrojové kódy

even closer, almost finished

Carolynn Vansant před 6 roky
rodič
revize
4dade8d547

+ 3
- 2
Client/Client.iml Zobrazit soubor

12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
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
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
17
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
18
     <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
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
     <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
20
     <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
20
   </component>
21
   </component>
21
 </module>
22
 </module>

+ 9
- 3
Client/pom.xml Zobrazit soubor

25
             <artifactId>jackson-databind</artifactId>
25
             <artifactId>jackson-databind</artifactId>
26
             <version>2.9.4</version>
26
             <version>2.9.4</version>
27
         </dependency>
27
         </dependency>
28
+        <!--<dependency>-->
29
+            <!--<groupId>org.apache.httpcomponents</groupId>-->
30
+            <!--<artifactId>fluent-hc</artifactId>-->
31
+            <!--<version>4.5.5</version>-->
32
+        <!--</dependency>-->
28
         <dependency>
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
         </dependency>
37
         </dependency>
38
+
33
     </dependencies>
39
     </dependencies>
34
 </project>
40
 </project>

+ 39
- 38
Client/src/main/java/SimpleShell.java Zobrazit soubor

49
                 MessageController mesCont = new MessageController();
49
                 MessageController mesCont = new MessageController();
50
                 IdController idCont = new IdController();
50
                 IdController idCont = new IdController();
51
 
51
 
52
-
53
                 if (commandLine.equalsIgnoreCase("ids")) {
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
                     specificCommand = console.readLine();
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
                     } else {
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
                 if (commandLine.equals("messages")) {
70
                 if (commandLine.equals("messages")) {
71
+                    String results = "";
70
                     System.out.println("To retrieve the last 20 messages posted on the timeline, press enter\n" +
72
                     System.out.println("To retrieve the last 20 messages posted on the timeline, press enter\n" +
71
                             "To retrieve the last twenty messages sent to you enter your github id");
73
                             "To retrieve the last twenty messages sent to you enter your github id");
72
                     specificCommand = console.readLine();
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
                     } else {
77
                     } else {
78
                         commandList.add(specificCommand);
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
                 if(commandLine.equalsIgnoreCase("send")){
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
                     specificCommand = console.readLine();
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
                 //print history, moved it here so full commands will be in history
112
                 //print history, moved it here so full commands will be in history

+ 20
- 20
Client/src/main/java/YouAreEll.java Zobrazit soubor

2
 import org.apache.http.client.fluent.*;
2
 import org.apache.http.client.fluent.*;
3
 import com.fasterxml.jackson.databind.*;
3
 import com.fasterxml.jackson.databind.*;
4
 import java.io.IOException;
4
 import java.io.IOException;
5
+import javax.swing.*;
5
 
6
 
6
 
7
 
7
 public class YouAreEll {
8
 public class YouAreEll {
19
         } catch (JsonProcessingException e) {
20
         } catch (JsonProcessingException e) {
20
             e.printStackTrace();
21
             e.printStackTrace();
21
         }
22
         }
22
-        System.out.println(urlhandler.makeURLCall("/ids", "GET", payload));
23
+        System.out.println(urlhandler.makeURLCall("/ids", "POST", payload));
23
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
24
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
24
     }
25
     }
25
 
26
 
26
     public String makeURLCall(String mainurl, String method, String jpayload) {
27
     public String makeURLCall(String mainurl, String method, String jpayload) {
27
-        ProcessBuilder processBuilder = new ProcessBuilder();
28
         String fullUrl = "http://zipcode.rocks:8085" + mainurl;
28
         String fullUrl = "http://zipcode.rocks:8085" + mainurl;
29
         String requestReturn = "";
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
         return requestReturn;
48
         return requestReturn;
49
     }
49
     }
50
 
50