Skip to content

helderam/teste_api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZSSN (Zombie Survival Social Network)

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.

Table of Contents

Installation

Dependention note: Before installation make sure to have MongoDB (3.4) and Ruby (2.3) installed and up.

  1. Clone the project.

    $ https://github.com/cleicar/zssn_api.git
  2. Bundle the Gems.

    $ bundle install
  3. Set the database connection at the config file config/mongoid.yml.

  4. Start the application

    $ rails s

Application will be runing at localhost:3000.

API Documentation

List Survivors

Request
GET  /survivors`
Response
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"
            }
        ]
    }
]

Add Survivors

Request
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
            
        }]
    }
}
Response
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"
}
Errors
Status Error Message
422 Unprocessable Entity
409 Conflict survivor need to declare its own resources

Update Survivor Location

Request
PATCH/PUT /survivors/:id
Parameters:
{
    "survivor": 
    {
        "latitude": "-16.6868824", 
        "longitude": "-49.2647885"
    }
}
Response
status: 204 no_content
Content-Type: "application/json"
Errors
Status Error
404 Not Found

Flag Survivor as Infected

Request
POST   /survivors/:id/flag_infection
Response
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)"
}
Errors
Status Error
404 Not Found

Trade Resources

Survivors can trade items among themselves, respecting a price table.

Request
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
        }
      ]
    }
  }
}
Response
status: 200 ok
Content-Type: "application/json"
Body:
{
    "message": "Trade successfully completed"
}
Errors
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

Reports

Percentage of infected survivors

Request
GET   /reports/infected_survivors
Response
status: 200 ok
Content-Type: "application/json"
Body:
{
    "data": "X%"
}

Percentage of non-infected survivors

Request
GET   /reports/not_infected_survivors
Response
status: 200 ok
Content-Type: "application/json"
Body:
{
    "data": "X%"
}

Average Resources By Survivor

Request
GET   /reports/resources_by_survivor
Response
status: 200 ok
Content-Type: "application/json"
Body:
{
    "averages": {
        "water": 5,
        "food": 7,
        "medication": 1.5,
        "ammunition": 0
    }
}

Points lost because of infected survivors

Request
GET   /reports/lost_infected_points
Response
status: 200 ok
Content-Type: "application/json"
Body:
{
    "lost_points": 30
}

Testing with RSpec

The project was build with TDD (Test Driven Development). To execute the tests just run the tests with RSpec.

  1. Execute all tests

    $ bundle exec rspec

To see the test cover percent open the file coverage/index.html at your browser.

Credits

  • Cleiviane (last survivor who knows how to code)

About

ZSSN - Zombie Survival Social Network Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.5%
  • HTML 0.5%