Browse Source

Merge 7cd6ac696fe8e88c51b95e8b641ff20db448ab27 into bd1fca498ef63809a3a7a9e8867a8c20219bafbb

Haysel Giovanni Santiago 6 years ago
parent
commit
20249d8a06
No account linked to committer's email

+ 7
- 3
Client/Client.iml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
4
     <output url="file://$MODULE_DIR$/target/classes" />
4
     <output url="file://$MODULE_DIR$/target/classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
     <content url="file://$MODULE_DIR$">
6
     <content url="file://$MODULE_DIR$">
7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10
       <excludeFolder url="file://$MODULE_DIR$/target" />
8
       <excludeFolder url="file://$MODULE_DIR$/target" />
11
     </content>
9
     </content>
12
     <orderEntry type="inheritedJdk" />
10
     <orderEntry type="inheritedJdk" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
16
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" 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" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
20
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
17
   </component>
21
   </component>
18
 </module>
22
 </module>

+ 12
- 0
Client/pom.xml View File

10
     <modelVersion>4.0.0</modelVersion>
10
     <modelVersion>4.0.0</modelVersion>
11
 
11
 
12
     <artifactId>Client</artifactId>
12
     <artifactId>Client</artifactId>
13
+    <build>
14
+        <plugins>
15
+            <plugin>
16
+                <groupId>org.apache.maven.plugins</groupId>
17
+                <artifactId>maven-compiler-plugin</artifactId>
18
+                <configuration>
19
+                    <source>1.7</source>
20
+                    <target>1.7</target>
21
+                </configuration>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
13
 
25
 
14
 
26
 
15
 </project>
27
 </project>

+ 50
- 0
Client/src/main/java/ID.java View File

1
+public class ID {
2
+
3
+    private String name;
4
+    private String github;
5
+
6
+    public ID(String userID, String name, String github) {
7
+        this.userID = userID;
8
+        this.name = name;
9
+        this.github = github;
10
+    }
11
+    public ID(String name, String github) {
12
+        this.name = name;
13
+        this.github = github;
14
+    }
15
+
16
+    private String userID;
17
+
18
+    public String getUserID() {
19
+        return userID;
20
+    }
21
+
22
+    public void setUserID(String userID) {
23
+        this.userID = userID;
24
+    }
25
+
26
+    public String getName() {
27
+        return name;
28
+    }
29
+
30
+    public void setName(String name) {
31
+        this.name = name;
32
+    }
33
+
34
+    public String getGithub() {
35
+        return github;
36
+    }
37
+
38
+    public void setGithub(String github) {
39
+        this.github = github;
40
+    }
41
+
42
+    @Override
43
+    public String toString() {
44
+        return "Id{" +
45
+                "id='" + this.userID + '\'' +
46
+                ", name='" + this.name + '\'' +
47
+                ", gitHubId='" + this.github + '\'' +
48
+                '}';
49
+    }
50
+}

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

1
+public class Messages {
2
+    private String sequence;
3
+    private String timestamp;
4
+    private String fromID;
5
+    private String toID;
6
+    private String message;
7
+
8
+    public Messages(String sequence, String timestamp, String fromID, String toID, String message) {
9
+        this.sequence = sequence;
10
+        this.timestamp = timestamp;
11
+        this.fromID = fromID;
12
+        this.toID = toID;
13
+
14
+        this.message = message;
15
+    }
16
+
17
+    public Messages(String fromID, String toID, String message) {
18
+        this.fromID = fromID;
19
+        this.toID = toID;
20
+        this.message = message;
21
+    }
22
+
23
+    public String getSequence() {
24
+        return sequence;
25
+    }
26
+
27
+    public void setSequence(String sequence) {
28
+        this.sequence = sequence;
29
+    }
30
+
31
+    public String getTimestamp() {
32
+        return timestamp;
33
+    }
34
+
35
+    public void setTimestamp(String timestamp) {
36
+        this.timestamp = timestamp;
37
+    }
38
+
39
+    public String getFromID() {
40
+        return fromID;
41
+    }
42
+
43
+    public void setFromID(String fromID) {
44
+        this.fromID = fromID;
45
+    }
46
+
47
+    public String getToID() {
48
+        return toID;
49
+    }
50
+
51
+    public void setToID(String toID) {
52
+        this.toID = toID;
53
+    }
54
+
55
+    public String getMessage() {
56
+        return message;
57
+    }
58
+
59
+    public void setMessage(String message) {
60
+        this.message = message;
61
+    }
62
+}

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

1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+
1
 import java.io.BufferedReader;
3
 import java.io.BufferedReader;
2
 import java.io.IOException;
4
 import java.io.IOException;
3
 import java.io.InputStream;
5
 import java.io.InputStream;
9
 
11
 
10
 
12
 
11
     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
+        }
12
         // yep, make an effort to format things nicely, eh?
22
         // yep, make an effort to format things nicely, eh?
13
         System.out.println(output);
23
         System.out.println(output);
14
     }
24
     }
19
         BufferedReader console = new BufferedReader
29
         BufferedReader console = new BufferedReader
20
                 (new InputStreamReader(System.in));
30
                 (new InputStreamReader(System.in));
21
 
31
 
32
+        ObjectMapper mapper = new ObjectMapper();
22
         ProcessBuilder pb = new ProcessBuilder();
33
         ProcessBuilder pb = new ProcessBuilder();
23
         List<String> history = new ArrayList<String>();
34
         List<String> history = new ArrayList<String>();
24
         int index = 0;
35
         int index = 0;
59
                 // Specific Commands.
70
                 // Specific Commands.
60
 
71
 
61
                 // ids
72
                 // ids
62
-                if (list.contains("ids")) {
73
+                if (list.contains("ids") && list.size() == 1) {
63
                     String results = webber.get_ids();
74
                     String results = webber.get_ids();
64
                     SimpleShell.prettyPrint(results);
75
                     SimpleShell.prettyPrint(results);
65
                     continue;
76
                     continue;
66
                 }
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
+                }
67
 
86
 
68
                 // messages
87
                 // messages
69
                 if (list.contains("messages")) {
88
                 if (list.contains("messages")) {

+ 35
- 3
Client/src/main/java/YouAreEll.java View File

1
-public class YouAreEll {
1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+import okhttp3.*;
3
+
4
+import java.io.IOException;
5
+
6
+
2
 
7
 
3
-    YouAreEll() {
8
+public class YouAreEll {
9
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
10
+    OkHttpClient client = new OkHttpClient();
11
+            YouAreEll() {
4
     }
12
     }
5
 
13
 
6
     public static void main(String[] args) {
14
     public static void main(String[] args) {
18
     }
26
     }
19
 
27
 
20
     public String MakeURLCall(String mainurl, String method, String jpayload) {
28
     public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
29
+        String myURL = "http://zipcode.rocks:8085" + mainurl;
30
+        OkHttpClient client = new OkHttpClient();
31
+
32
+        if(method.equals("GET")) {
33
+            Request request = new Request.Builder().url(myURL).build();
34
+            try (Response response = client.newCall(request).execute()) {
35
+                return response.body().string();
36
+            } catch (IOException e) {
37
+                e.printStackTrace();
38
+            }
39
+        } else if (method.equals("POST")) {
40
+            RequestBody body = RequestBody.create(JSON, jpayload);
41
+            Request request = new Request.Builder().url(myURL).post(body).build();
42
+
43
+            try (Response response = client.newCall(request).execute()) {
44
+                return response.body().string();
45
+            } catch (IOException e) {
46
+                e.printStackTrace();
47
+            }
48
+        }
49
+//        else if (method.equals("PUT")) {
50
+//            ObjectMapper objectMapper = new ObjectMapper();
51
+//
52
+//        }
53
+        return "nothing";
22
     }
54
     }
23
 }
55
 }

+ 6
- 0
YouAreEll.iml View File

11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
14
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
15
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
14
   </component>
20
   </component>
15
 </module>
21
 </module>

+ 11
- 0
pom.xml View File

18
             <artifactId>jackson-databind</artifactId>
18
             <artifactId>jackson-databind</artifactId>
19
             <version>2.8.6</version>
19
             <version>2.8.6</version>
20
         </dependency>
20
         </dependency>
21
+        <dependency>
22
+            <groupId>com.squareup.okhttp3</groupId>
23
+            <artifactId>okhttp</artifactId>
24
+            <version>3.10.0</version>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>com.squareup.okhttp3</groupId>
28
+            <artifactId>mockwebserver</artifactId>
29
+            <version>3.10.0</version>
30
+            <scope>test</scope>
31
+        </dependency>
21
     </dependencies>
32
     </dependencies>
22
 </project>
33
 </project>