ZSSN Is a system created to help the human to survive an apocalypse zombie. Using only REST API requests, survivors can share resources with others non-infected humans.
Dependention note: Before installation make sure to have MongoDB (3.4) and Ruby (2.3) installed and up.
-
Clone the project.
$ https://github.com/cleicar/zssn_api.git
-
Bundle the Gems.
$ bundle install
-
Set the database connection at the config file
config/mongoid.yml
. -
Start the application
$ rails s
Application will be runing at localhost:3000.
GET /survivors`
status: 200 Ok
Content-Type: "application/json"
Body:
[
{
"_id": {
"$oid": "598c6da62a43161f3eb5bb66"
},
"age": "25",
"gender": "male",
"last_location": {
"latitude": "-16.680353",
"longitude": "-49.256302"
},
"name": "Survivor",
"resources": [
{
"_id": {
"$oid": "598c6da62a43161f3eb5bb67"
},
"points": null,
"quantity": 10,
"type": "Water"
},
{
"_id": {
"$oid": "598c6da62a43161f3eb5bb68"
},
"points": null,
"quantity": 6,
"type": "Food"
}
]
}
]
POST /survivors`
Parameters:
{
"survivor":
{
"name": "Survivor Test",
"age": "43",
"gender": "M",
"last_location": {"latitude": "89809809809", "longitude": "-88983982100"},
"resources": [
{
"type": "Water",
"quantity": 10
},
{
"type":"Food",
"quantity": 6
}]
}
}
status: 201 created
Content-Type: "application/json"
Body:
{
"_id": {
"$oid": "5990f7357b6ee2652e9e581a"
},
"age": "43",
"gender": "M",
"infection_count": 0,
"last_location": {
"latitude": "89809809809",
"longitude": "-88983982100"
},
"name": "Survivor Test"
}
Status | Error | Message |
---|---|---|
422 | Unprocessable Entity | |
409 | Conflict | survivor need to declare its own resources |
PATCH/PUT /survivors/:id
Parameters:
{
"survivor":
{
"latitude": "-16.6868824",
"longitude": "-49.2647885"
}
}
status: 204 no_content
Content-Type: "application/json"
Status | Error |
---|---|
404 | Not Found |
POST /survivors/:id/flag_infection
status: 200 ok
Content-Type: "application/json"
Body:
{
"message": "Attention! Survivor was reported as infected x time(s)!"
"message": "Warning! Survivor was reported as infected x time(s)"
}
Status | Error |
---|---|
404 | Not Found |
Survivors can trade items among themselves, respecting a price table.
POST /trade_resources
Parameters:
{
"trade": {
"survivor_1": {
"id": "5991814f2a43166a43c27b48",
"resources": [
{
"type": "Water",
"quantity": 1
},
{
"type": "Medication",
"quantity": 1
}
]
},
"survivor_2": {
"id": "5991814f2a43166a43c27b4b",
"resources": [
{
"type": "Ammunition",
"quantity": 6
}
]
}
}
}
status: 200 ok
Content-Type: "application/json"
Body:
{
"message": "Trade successfully completed"
}
Status | Error | Message |
---|---|---|
404 | Not Found | Survivor with id xxxxx does not exist |
409 | Conflict | Survivor X is infected |
409 | Conflict | Survivor X doesn't have enough resources |
409 | Conflict | Resources points is not balanced both sides |
GET /reports/infected_survivors
status: 200 ok
Content-Type: "application/json"
Body:
{
"data": "X%"
}
GET /reports/not_infected_survivors
status: 200 ok
Content-Type: "application/json"
Body:
{
"data": "X%"
}
GET /reports/resources_by_survivor
status: 200 ok
Content-Type: "application/json"
Body:
{
"averages": {
"water": 5,
"food": 7,
"medication": 1.5,
"ammunition": 0
}
}
GET /reports/lost_infected_points
status: 200 ok
Content-Type: "application/json"
Body:
{
"lost_points": 30
}
The project was build with TDD (Test Driven Development). To execute the tests just run the tests with RSpec.
-
Execute all tests
$ bundle exec rspec
To see the test cover percent open the file coverage/index.html
at your browser.
- Cleiviane (last survivor who knows how to code)