AOL Instant Messenger has had a great run...
but it just kept getting older. Sad!
It will be no more in December 2017.
This project is a sample messenging rails 5 API built with docker-compose to commemorate the passing of AIM.
You will need to install:
- docker-machine
- docker
- docker-compose
Here are the versions used to build this project for reference.
$ docker-machine -v && docker -v && docker-compose -v
docker-machine version 0.13.0, build 9ba6da9
Docker version 17.10.0-ce, build f4ffd25
docker-compose version 1.17.0, build ac53b73
There is a script to bootstrap the app for you. Run it like so:
$ cd <app_root>
$ sh ./build/bootstrap-server.sh
It does these things:
- Runs
docker-compose build
- Runs
docker-compose up
in detached mode - Runs
db:migrate
- Runs
db:reset
to setup and seed the database if necessary
To kill the app, just run docker-compose down
.
The main goal of the app is to create users and allow users to send messages to each other.
Only logged-in users can send messages. Here are example requests to get you started.
NOTE: These commands only work after bootstrapping the app
# create user, this will also sign you in
$ curl -H 'Content-Type: application/json' -c ~/cookie.txt \
$(docker-machine ip):3000/v1/users \
-d '{"username":"running_aim_icon", "password":"hello123"}' | \
python -m 'json.tool'
# output
{
"created_at": "2017-11-05T02:24:24.781Z",
"id": "42e808d5-6ba6-4eb8-97be-d1c904ffb99d",
"updated_at": "2017-11-05T02:24:24.781Z",
"username": "running_aim_icon"
}
# or login to an existing account
$ curl -H 'Content-Type: application/json' -c ~/cookie.txt \
$(docker-machine ip):3000/v1/sessions/login \
-d '{"username":"running_aim_icon", "password":"hello123"}' | \
python -m 'json.tool'
# output
{
"created_at": "2017-11-05T02:24:24.781Z",
"id": "42e808d5-6ba6-4eb8-97be-d1c904ffb99d",
"updated_at": "2017-11-05T02:24:24.781Z",
"username": "running_aim_icon"
}
This is a convenience endpoint to find users to send messages to.
Since all the seed data has usernames starting with 'myuser', this example uses that for the search_prefix
.
# limit and page are optional
$ curl -H 'Content-Type: application/json' -b ~/cookie.txt \
"$(docker-machine ip):3000/v1/users?search_prefix=myuser&limit=2&page=2" | \
python -m 'json.tool'
# output
{
"data": [
{
"created_at": "2017-11-05T15:40:54.547Z",
"id": "e9a6b696-6fd7-4bff-908c-ed9c65e88f3b",
"updated_at": "2017-11-05T15:40:54.547Z",
"username": "myusername5"
},
{
"created_at": "2017-11-05T15:40:54.618Z",
"id": "9bd21186-c0f2-4add-917c-b0b4ff36ca70",
"updated_at": "2017-11-05T15:40:54.618Z",
"username": "myusername6"
}
],
"limit": 2,
"page": 2,
"total": 10
}
Now that you have the logged user ID from either POST sessions/login or POST users, try sending a message
your user: 42e808d5-6ba6-4eb8-97be-d1c904ffb99d
myusername6 user: 9bd21186-c0f2-4add-917c-b0b4ff36ca70
$ curl -H 'Content-Type: application/json' -b ~/cookie.txt \
"$(docker-machine ip):3000/v1/42e808d5-6ba6-4eb8-97be-d1c904ffb99d/messages" \
-d '{ "recipient_id": "9bd21186-c0f2-4add-917c-b0b4ff36ca70", "content": "hi-oh", "message_type": "text" }' | \
python -m json.tool
# output
{
"content": "hi-oh",
"created_at": "2017-11-05T02:36:15.362Z",
"message_type": "text",
"metadata": "{\"tags\":\"That sunset tho!\"}",
"modified_at": "2017-11-05T02:36:15.362Z",
"recipient_id": "9bd21186-c0f2-4add-917c-b0b4ff36ca70",
"sender_id": "42e808d5-6ba6-4eb8-97be-d1c904ffb99d"
}
# limit and page are optional
$ curl -H 'Content-Type: application/json' -b ~/cookie.txt \
"$(docker-machine ip):3000/v1/42e808d5-6ba6-4eb8-97be-d1c904ffb99d/messages?recipient_id=9bd21186-c0f2-4add-917c-b0b4ff36ca70&limit=1&page=0" | \
python -m json.tool
# output
{
"data": [
{
"content": "hi-oh",
"created_at": "2017-11-05T02:36:15.362Z",
"message_type": "text",
"metadata": "{\"tags\":\"That sunset tho!\"}",
"modified_at": "2017-11-05T02:36:15.362Z",
"recipient_id": "9bd21186-c0f2-4add-917c-b0b4ff36ca70",
"sender_id": "42e808d5-6ba6-4eb8-97be-d1c904ffb99d"
}
],
"limit": 1,
"page": 0,
"total": 1
}
For active development, the helpers docker_rails
, docker_rspec
, and attach_to_rails
are created for convenience.
As they imply, they run their respective commands in the docker container.
attach_to_rails
is to be used when you need to access a debugger (e.g. pry/byebug).
To use them, run source ./build/alias.sh
in the root directory.