Giter Club home page Giter Club logo

teste_api's Introduction

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)

teste_api's People

Contributors

cleicar avatar

Stargazers

Helder Afonso de Morais avatar

Watchers

James Cloos avatar Helder Afonso de Morais avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.