The world as we know it has fallen into an apocalyptic scenario. A laboratory-made virus is transforming human beings and animals into zombies, hungry for fresh flesh.
You, as a zombie resistance member (and the last survivor who knows how to code), was designated to develop a system to share resources between non-infected humans.
Dependention note: Before installation make sure to have sqlite3 (3.24) and Ruby (2.6.2) installed and up.
-
Clone the project.
$ git clone https://github.com/robertoeb/zssn-api.git
-
Bundle the Gems.
$ bundle install
-
Create and migrate the database.
$ rails db:create $ rails db:migrate
-
Start the application
$ rails s
Application will be runing at localhost:3000.
You can test a live version of the API using a URL http://zssn.ml:3000
GET /survivors`
status: 200 Ok
Content-Type: "application/json"
{
"survivors": [
{
"id": 1,
"name": "Rick Grimes",
"age": 38,
"gender": "M",
"latitude": -84.3879824,
"longitude": -84.3879824,
"infection_mark": 0
},
{
"id": 2,
"name": "Carl Grimes",
"age": 14,
"gender": "M",
"latitude": -84.3879824,
"longitude": -84.3879824,
"infection_mark": 0
}
]
}
POST /survivors`
Parameters:
{
"survivor":
{
"name": "Glenn Rhee",
"age": "27",
"gender": "M",
"latitude": "-84.3879824",
"longitude": "-84.3879824",
"resources": [
{
"item": "Water",
"amount": 10
},
{
"item":"Ammunition",
"amount": 60
},
{
"item":"Food",
"amount": 30
},
{
"item":"Medication",
"amount": 20
}
]
}
}
status: 201 created
Content-Type: "application/json"
{
"survivor": {
"id": 3,
"name": "Glenn Rhee",
"age": 27,
"gender": "M",
"latitude": -84.3879824,
"longitude": -84.3879824,
"infection_mark": 0
}
}
Status | Error | Message |
---|---|---|
422 | Unprocessable Entity | |
409 | Conflict | Survivors need to declare their resources |
PATCH/PUT /survivors/:id
Parameters:
{
"survivor":
{
"latitude": "33.7490",
"longitude": "84.3880"
}
}
status: 200 Ok
Content-Type: "application/json"
{
"id": 3,
"latitude": 33.749,
"longitude": 84.388,
"name": "Glenn Rhee",
"age": 27,
"gender": "M",
"infection_mark": 0
}
Status | Error | Message |
---|---|---|
404 | Not Found | |
422 | Unprocessable Entity |
POST /survivors/:id/report_infection
status: 200 ok
Content-Type: "application/json"
{
"message": "Survivor reported as infected 1 times"
"message": "He's a walker, do him a favor, shoot his head."
}
Status | Error | Message |
---|---|---|
404 | Not Found | Couldn't find Survivor with 'id'=:id |
Survivors can trade items among themselves, respecting a points table.
POST /trade
{
"trade": {
"survivor1": {
"id": "1",
"resources": [
{
"item": "Water",
"amount": 1
}
]
},
"survivor2": {
"id": "2",
"resources": [
{
"item": "Ammunition",
"amount": 4
}
]
}
}
}
status: 200 ok
Content-Type: "application/json"
Body:
{
"message": "Trade successfully completed"
}
Status | Error | Message |
---|---|---|
404 | Not Found | Couldn't find Survivor with 'id'=X |
409 | Conflict | SurvivorX It's infected! Run away or kill him! |
409 | Conflict | Invalid resources for SurvivorX |
409 | Conflict | Resources points is not balanced both sides |
GET /reports/infected_survivors
status: 200 ok
Content-Type: "application/json"
{
"percentage": "100%"
}
GET /reports/uninfected_survivors
status: 200 ok
Content-Type: "application/json"
Body:
{
"percentage": "0%"
}
GET /reports/resources_by_survivor
status: 200 ok
Content-Type: "application/json"
{
"averages": {
"water": 10,
"food": 30,
"medication": 20,
"ammunition": 60
}
}
GET /reports/lost_infected_points
status: 200 ok
Content-Type: "application/json"
Body:
{
"lost_points": 0
}
To execute the tests just run the tests with RSpec.
-
Execute all tests
$ rails -s
- Roberto E. B. Junior - I'M NEGAN