Jennifer Chao e76b007fc9 checkpoint | 6 år sedan | |
---|---|---|
.idea | 6 år sedan | |
Client | 6 år sedan | |
.gitignore | 6 år sedan | |
README.md | 6 år sedan | |
YouAreEll.iml | 6 år sedan | |
pom.xml | 6 år sedan |
SimpleShell
class.You're going to create a way
Under-A-Rock
acts a little (very little) like a twitter server or chat server.
Github_id
.You can send a message to the global timeline by POSTing a Message JSON object to the URL below.
to id
field empty, the message is to the world
.to id
field of the JSON payload, then that message is addressed to that friend.When you send a new Message or Id JSON object to the server, it records it, and fills in one or two fields.
You're going to create a series of REST API handlers that will each perform a specific command.
The Under-A-Rock Server can be reached at http://zipcode.rocks:8085
Everyone uses the same server.
You can explore several ways of doing the HTTP URL calls to the server, using the one of these:
Be prepared to defend your choice if which HTTP client library you chose, with reasons why you chose it.
It's possible you may also need to understand some of what the Jackson package does.
ids
should return a formatted list of the IDs available to you.ids your_name your_github_id
command should post your Name and your GithubId to the server.-
GET
: Get all github ids registeredPOST
: add your github id / name to be registeredPUT
: change the name linked to your github idjson payload for /ids/ - this is a sample
{
"userid": "-", // gets filled w id
"name": "Kris",
"github": "xt0fer"
}
If I type cmd? ids Kris xt0fer
into the shell, your command processor creates a JSON object which looks like:
{
"userid": "-", // gets filled w id
"name": "Kris",
"github": "xt0fer"
}
and send it as the body of a POST request to http://zipcode.rocks:8085/ids/
in the shell
messages
should return the last 20 messages, nicely formatted.messages your_github_id
should return the last 20 messages sent to you.send your_github_id 'Hello World'
should post a new message in the timelinesend your_github_id 'my string message' to some_friend_githubid
should post a message to your friend from you on the timeline.the Messages API is:
GET
: Get last 20 msgs - returns an JSON array of message objectsGET
: Get last 20 msgs for myid - returns an JSON array of message objectsPOST
: 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.GET
: Get msg with a sequence - returns a JSON message object for a sequence numberGET
: Get last 20 msgs for myid from friendidjson payload for /messages/ these are samples, one to a specific friend, one to the timeline.
[
{
"sequence": "-",
"timestamp": "_",
"fromid": "xt0fer",
"toid": "kristofer",
"message": "Hello, Kristofer!"
},
{
"sequence": "-",
"timestamp": "_",
"fromid": "xt0fer",
"toid": "",
"message": "Hello, World!"
}
]
if I type
send xt0fer 'Hello old buddy!' to torvalds
into the shell, your command processor creates a JSON object which looks like:
{
"sequence": "-",
"timestamp": "_",
"fromid": "xt0fer",
"toid": "torvalds",
"message": "Hello old buddy!"
}
and send it as the body of a POST request to http://zipcode.rocks:8085/ids/xt0fer/messages/
What's that ProcessBuilder stuff about? In the SimpleShell class, take a look. How can that be used as a pattern to use threads to make the API calls and wait for the response? Maybe launch a new thread on every request?
Build a better set of commands. Make the "fromid" intrinsic, so it isn't needed on the various shell commands. Add a feature where you can send messages by someone's name. Create a means where the client watches the server for any private messages to you and only prints them once. Add another command that watches the global stream and only prints messages once.