|
@@ -1,2 +1,162 @@
|
1
|
|
-# YouAreEll
|
2
|
|
-Java URL client shell
|
|
1
|
+# Under-A-Rock
|
|
2
|
+
|
|
3
|
+## Client HTTP/REST API for UnderARock
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+### The Point
|
|
7
|
+
|
|
8
|
+You are to write a command interpreter using the provided SimpleShell class. You're going to create a way for
|
|
9
|
+commands to be typed into your shell, read the typed commands and arguments, send them off to the Under-A-Rock
|
|
10
|
+server using a REST API over the HTTP protocol, read the JSON data returned from the URL call, and print it out
|
|
11
|
+nicely formatted for your user.
|
|
12
|
+
|
|
13
|
+Under-A-Rock acts a little (very little) like a twitter server or chat server.
|
|
14
|
+
|
|
15
|
+You register your name and githubid by creating an ID JSON payload (see below) and POSTing it to the server. You can GET
|
|
16
|
+all the ids registered by sending a GET request to the same URL. Once you've received all the ids, you can send
|
|
17
|
+messages to the world or to a specific Github_id.
|
|
18
|
+
|
|
19
|
+You
|
|
20
|
+can send a message to the global timeline by POSTing a Message JSON object to the URL below.
|
|
21
|
+If you leave the "to id" field empty, the message is "to the world". If you fill out the the JSON template with
|
|
22
|
+a valid github_id in the "to id" field of the JSON payload, then that message is addressed to that friend. Yes, all
|
|
23
|
+messages can be seen by users of the system. There are JSON templates below for both Ids and Messages.
|
|
24
|
+
|
|
25
|
+When you send a new Message or Id JSON object to the server, it records it, and fills in one or two fields.
|
|
26
|
+A Message gets an assigned sequence number and a timestamp of when it was received by the server. An ID
|
|
27
|
+object gets a "user id" field assigned to it.
|
|
28
|
+Any sequence number, timestamp or userid you put into a JSON template
|
|
29
|
+gets overwritten by the server when you POST it.
|
|
30
|
+
|
|
31
|
+You're going to create a series of REST API handlers that will each perform a
|
|
32
|
+specific command. Each one of the command methods will then call a even lower-level method that makes a certain kind
|
|
33
|
+of HTTP request (GET, POST, PUT) to specific filled-in URL.
|
|
34
|
+
|
|
35
|
+The Under-A-Rock Server can be reached at `http://zipcode.rocks:8085` Everyone uses the same server.
|
|
36
|
+
|
|
37
|
+There are two segments to the API and two kinds of commands in the shell, the ID segment and the Messages segment.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+You can explore several ways of doing the HTTP URL calls to the server, using the one of these:
|
|
41
|
+* Core Java version
|
|
42
|
+URL https://docs.oracle.com/javase/8/docs/api/java/net/URL.html and
|
|
43
|
+HttpURLConnection https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html,
|
|
44
|
+* Apache HTTP Client Library http://hc.apache.org/httpcomponents-client-ga/index.html
|
|
45
|
+* Unirest for Java http://unirest.io/java.html
|
|
46
|
+* Square's OKHttp https://github.com/square/okhttp
|
|
47
|
+
|
|
48
|
+Be prepared to defend your choice if which HTTP client library you chose, with reasons why you chose it.
|
|
49
|
+You should also create some unit tests for your REST API handlers.
|
|
50
|
+
|
|
51
|
+It's possible you may also need to understand some of what the Jackson package does for you.
|
|
52
|
+* jackson json
|
|
53
|
+
|
|
54
|
+## IDs
|
|
55
|
+
|
|
56
|
+#### ID commands in shell
|
|
57
|
+In the shell,
|
|
58
|
+`ids` should return a formatted list of the IDs available to you.
|
|
59
|
+
|
|
60
|
+`ids your_name your_github_id` command should post your Name and your GithubId to the server.
|
|
61
|
+If you do this twice with two different Names, but the name GithubId, the name on the server gets changed.
|
|
62
|
+
|
|
63
|
+the IDs API is:
|
|
64
|
+
|
|
65
|
+#### URL: /ids/
|
|
66
|
+* `GET` : Get all github ids registered
|
|
67
|
+* `POST` : add your github id / name to be registered
|
|
68
|
+* `PUT` : change the name linked to your github id
|
|
69
|
+
|
|
70
|
+json payload for /ids/ - this is a sample
|
|
71
|
+```json
|
|
72
|
+{
|
|
73
|
+ "userid": "-", // gets filled w id
|
|
74
|
+ "name": "Kris",
|
|
75
|
+ "githubid": "xt0fer"
|
|
76
|
+}
|
|
77
|
+```
|
|
78
|
+
|
|
79
|
+ #### Example:
|
|
80
|
+
|
|
81
|
+ if I type
|
|
82
|
+ ```aidl
|
|
83
|
+cmd?
|
|
84
|
+ ids Kris xt0fer
|
|
85
|
+```
|
|
86
|
+ into the shell, your command processor creates a JSON object which looks like:
|
|
87
|
+ ```json
|
|
88
|
+ {
|
|
89
|
+ "userid": "-", // gets filled w id
|
|
90
|
+ "name": "Kris",
|
|
91
|
+ "githubid": "xt0fer"
|
|
92
|
+ }
|
|
93
|
+ ```
|
|
94
|
+and send it as the body of a POST request to `http://zipcode.rocks:8085/ids/`
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+## Messages
|
|
98
|
+
|
|
99
|
+#### Message comands in shell
|
|
100
|
+
|
|
101
|
+in the shell,
|
|
102
|
+* `messages` should return the last 20 messages, nicely formatted.
|
|
103
|
+* `messages your_github_id` should return the last 20 messages sent to you.
|
|
104
|
+* `send your_github_id 'Hello World' ` should post a new message in the timeline
|
|
105
|
+* `send your_github_id 'my string message' to some_friend_githubid` should post a message to your friend from you on the timeline.
|
|
106
|
+
|
|
107
|
+the Messages API is:
|
|
108
|
+
|
|
109
|
+#### URL: /messages/
|
|
110
|
+* `GET` : Get last 20 msgs - returns an JSON array of message objects
|
|
111
|
+
|
|
112
|
+#### URL: /ids/:mygithubid/messages/
|
|
113
|
+* `GET` : Get last 20 msgs for myid - returns an JSON array of message objects
|
|
114
|
+* `POST` : Create a new message in timeline - need to POST a new message object, and will get back one with a message sequence number and timestamp of the server inserted.
|
|
115
|
+
|
|
116
|
+#### URL: /ids/:mygithubid/messages/:sequence
|
|
117
|
+* `GET` : Get msg with a sequence - returns a JSON message object for a sequence number
|
|
118
|
+
|
|
119
|
+#### URL: /ids/:mygithubid/from/:friendgithubid
|
|
120
|
+* `GET` : Get last 20 msgs for myid from friendid
|
|
121
|
+
|
|
122
|
+json payload for /messages/ these are samples, one to a specific friend, one to the timeline.
|
|
123
|
+```json
|
|
124
|
+[
|
|
125
|
+ {
|
|
126
|
+ "sequence": "-",
|
|
127
|
+ "timestamp": "_",
|
|
128
|
+ "fromid": "xt0fer",
|
|
129
|
+ "toid": "kristofer",
|
|
130
|
+ "message": "Hello, Kristofer!"
|
|
131
|
+ },
|
|
132
|
+
|
|
133
|
+ {
|
|
134
|
+ "sequence": "-",
|
|
135
|
+ "timestamp": "_",
|
|
136
|
+ "fromid": "xt0fer",
|
|
137
|
+ "toid": "",
|
|
138
|
+ "message": "Hello, World!"
|
|
139
|
+ }
|
|
140
|
+]
|
|
141
|
+```
|
|
142
|
+
|
|
143
|
+#### Example:
|
|
144
|
+
|
|
145
|
+ if I type
|
|
146
|
+ ```aidl
|
|
147
|
+cmd?
|
|
148
|
+send xt0fer 'Hello old buddy!' to torvalds
|
|
149
|
+```
|
|
150
|
+ into the shell, your command processor creates a JSON object which looks like:
|
|
151
|
+ ```json
|
|
152
|
+ {
|
|
153
|
+ "sequence": "-",
|
|
154
|
+ "timestamp": "_",
|
|
155
|
+ "fromid": "xt0fer",
|
|
156
|
+ "toid": "torvalds",
|
|
157
|
+ "message": "Hello old buddy!"
|
|
158
|
+ }
|
|
159
|
+ ```
|
|
160
|
+and send it as the body of a POST request to `http://zipcode.rocks:8085/ids/xt0fer/messages/`
|
|
161
|
+
|
|
162
|
+
|