nafis nibir 6 years ago
parent
commit
6867b74453

+ 6
- 4
Client/Client.iml View File

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 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 4
     <output url="file://$MODULE_DIR$/target/classes" />
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
@@ -11,8 +11,10 @@
11 11
     </content>
12 12
     <orderEntry type="inheritedJdk" />
13 13
     <orderEntry type="sourceFolder" forTests="false" />
14
-    <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" />
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-databind:2.9.4" level="project" />
15
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
16
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
17
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
18
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
17 19
   </component>
18 20
 </module>

+ 24
- 0
Client/pom.xml View File

@@ -10,6 +10,30 @@
10 10
     <modelVersion>4.0.0</modelVersion>
11 11
 
12 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>7</source>
20
+                    <target>7</target>
21
+                </configuration>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
13 25
 
26
+    <dependencies>
27
+        <dependency>
28
+            <groupId>com.fasterxml.jackson.core</groupId>
29
+            <artifactId>jackson-databind</artifactId>
30
+            <version>2.9.4</version>
31
+        </dependency>
32
+        <dependency>
33
+            <groupId>com.squareup.okhttp3</groupId>
34
+            <artifactId>okhttp</artifactId>
35
+            <version>3.10.0</version>
36
+        </dependency>
37
+    </dependencies>
14 38
 
15 39
 </project>

+ 45
- 0
Client/src/main/java/Id.java View File

@@ -0,0 +1,45 @@
1
+public class Id {
2
+    private String userid;
3
+    private String name;
4
+    private String github;
5
+
6
+    public String getUserid() {
7
+        return userid;
8
+    }
9
+
10
+    public Id(){}
11
+
12
+    public Id(String userid, String name, String github) {
13
+        this.userid = userid;
14
+        this.name = name;
15
+        this.github = github;
16
+    }
17
+
18
+    public void setUserid(String userid) {
19
+        this.userid = userid;
20
+    }
21
+
22
+    public String getName() {
23
+        return name;
24
+    }
25
+
26
+    public void setName(String name) {
27
+        this.name = name;
28
+    }
29
+
30
+    public String getGithub() {
31
+        return github;
32
+    }
33
+
34
+    public void setGithub(String github) {
35
+        this.github = github;
36
+    }
37
+
38
+    @Override
39
+    public String toString() {
40
+        return String.format("userid: " + userid + "\n" +
41
+                               "name: " + name + "\n" +
42
+                             "github: " +  github);
43
+    }
44
+
45
+}

+ 61
- 0
Client/src/main/java/Message.java View File

@@ -0,0 +1,61 @@
1
+public class Message {
2
+
3
+    private String sequence;
4
+    private String timestamp;
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public String getSequence() {
10
+        return sequence;
11
+    }
12
+
13
+    public void setSequence(String sequence) {
14
+        this.sequence = sequence;
15
+    }
16
+
17
+    public String getTimestamp() {
18
+        return timestamp;
19
+    }
20
+
21
+    public void setTimestamp(String timestamp) {
22
+        this.timestamp = timestamp;
23
+    }
24
+
25
+    public String getFromid() {
26
+        return fromid;
27
+    }
28
+
29
+    public void setFromid(String fromid) {
30
+        this.fromid = fromid;
31
+    }
32
+
33
+    public String getToid() {
34
+        return toid;
35
+    }
36
+
37
+    public void setToid(String toid) {
38
+        this.toid = toid;
39
+    }
40
+
41
+    public String getMessage() {
42
+        return message;
43
+    }
44
+
45
+    public void setMessage(String message) {
46
+        this.message = message;
47
+    }
48
+
49
+    @Override
50
+    public String toString() {
51
+        return "Message{" +
52
+                "sequence='" + sequence + '\'' +
53
+                ", fromid='" + fromid + '\'' +
54
+                ", toid='" + toid + '\'' +
55
+                ", message='" + message + '\'' +
56
+                '}';
57
+    }
58
+
59
+
60
+
61
+}

+ 30
- 5
Client/src/main/java/YouAreEll.java View File

@@ -1,23 +1,48 @@
1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+import okhttp3.*;
3
+
4
+import java.io.IOException;
5
+
1 6
 public class YouAreEll {
7
+    final String BASEURL ="http://zipcode.rocks:8085";
8
+    private OkHttpClient client;
2 9
 
3 10
     YouAreEll() {
4 11
     }
5 12
 
6
-    public static void main(String[] args) {
13
+    public static void main(String[] args) throws IOException{
7 14
         YouAreEll urlhandler = new YouAreEll();
8 15
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9 16
         System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
10 17
     }
11 18
 
12
-    public String get_ids() {
19
+    public String get_ids() throws IOException{
20
+
13 21
         return MakeURLCall("/ids", "GET", "");
14 22
     }
15 23
 
16
-    public String get_messages() {
24
+    public String get_messages() throws IOException{
25
+
17 26
         return MakeURLCall("/messages", "GET", "");
18 27
     }
19 28
 
20
-    public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
29
+    public String MakeURLCall(String mainurl, String method, String jpayload) throws IOException {
30
+
31
+        String finalURL = BASEURL + mainurl;
32
+        Request request = null;
33
+
34
+        if (method.equalsIgnoreCase("get")) {
35
+            request = new Request.Builder()
36
+                                 .url(finalURL)
37
+                                 .build();
38
+        }
39
+
40
+        if (request != null) {
41
+            try (Response response = client.newCall(request).execute()) {
42
+                return response.body().string();
43
+            }
44
+        }
45
+
46
+        return "wtf are you smokin bro? \"" + method + "\" doesn't do anything.";
22 47
     }
23 48
 }