8000 GitHub - evandrodutra/contracts: Contracts API is a simple Rails API designed to manage vendor contracts and its lifetime.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

evandrodutra/contracts

Repository files navigation

Contracts API

CircleCI Maintainability

Contracts API is a simple Rails API designed to manage vendor contracts and its lifetime.

Requirements

  • Ruby 2.4.1
  • PostgreSQL

Getting Started

Clone the repository, install gems and setup the database running the following commands:

git clone git@github.com:evandrodutra/contracts.git
cd contracts
bundle install
bundle exec bin/setup
bundle exec rails s

Development

Running Tests

To run the test environment execute rspec:

bundle exec rspec

API Definitions

All requests must use Content-Type: application/json header.

Authentication

For a private endpoint you must specify the Authorization header using the JWT token generated for your account, example:

curl -X GET -i -H "Authorization: Bearer MY_JWT_TOKEN" -H "Content-Type: application/json" "http://localhost:3000/contracts/:id"

POST data body

All POST actions that sends a content body must use the JSON-API format, example:

{
  "data": {
    "attributes": {
      "full_name": "Douglas Adams",
      "email": "dm@example.com",
      "password": "humans"
    }
  }
}

Response format

When the response has a content body instead of only the HTTP status, the returned data follows the JSON-API format, example:

{
  "data": {
    "id": "db22fed2-0c07-4737-be36-f082146fc8d4",
    "type": "users",
    "attributes": {
      "full-name": "Douglas Adams",
      "email": "dm@example.com",
      "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZGIyMmZlZDItMGMwNy00NzM3LWJlMzYtZjA4Mj"
    }
  }
}

Response error format

When the response contains entity errors the response body returns its description and status, example:

{
  "errors": [
    {
      "status": 422,
      "detail": "Full name should not be empty",
      "source": {
        "pointer": "/data/attributes/full_name"
      }
    },
    {
      "status": 422,
      "detail": "Email is already taken",
      "source": {
        "pointer": "/data/attributes/email"
      }
    }
  ]
}

API Usage

POST /users (Public)

Crates a user and returns its JWT token.

POST /users
Content-Type: "application/json"

{
  "data": {
    "attributes": {
      "full_name": "Douglas Adams",
      "email": "dm@example.com",
      "password": "humans"
    }
  }
}
Attribute Description
full_name user name
email valid email
password user password
Returns:
201 Created
Content-Type: "application/vnd.api+json"

{
  "data": {
    "id": "f3a17518-3c85-441b-bb99-448fd7da0a00",
    "type": "users",
    "attributes": {
      "full-name": "Douglas Adams",
      "email": "dm@example.com",
      "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZjNhMTc1MTgtM2M4NS00NDFiLWJiOTktNDQ4ZmQ3ZGEwYTAwIn0.8ilUS6nx8OlM1KLHvHV6_PE1pCoiaeq_TQczvLl6rzg",
      "created-at": "2018-01-15T12:54:31.818Z",
      "updated-at": "2018-01-15T12:54:31.818Z"
    }
  }
}

POST /contracts (Private)

Crates a contract for a given user-token and returns its data:

POST /contracts
Content-Type: "application/json"
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZjNhMTc1MTgtM2M4NS00NDFiLWJiOTktNDQ4ZmQ3ZGEwYTAwIn0.8ilUS6nx8OlM1KLHvHV6_PE1pCoiaeq_TQczvLl6rzg"

{
  "data": {
    "attributes": {
      "vendor": "DB",
      "starts_on": "30-01-2018",
      "ends_on": "30-12-2018",
      "price": "328.79"
    }
  }
}
Attribute Description
vendor vendor name
starts_on contract start date
ends_on contract end date
price contract price
Returns:
201 Created
Content-Type: "application/vnd.api+json"

{
  "data": {
    "id": "2c31b4fb-ac16-4fce-8634-16f3dd2a093c",
    "type": "contracts",
    "attributes": {
      "vendor": "DB",
      "starts-on": "2018-01-30 00:00:00",
      "ends-on": "2018-12-30 00:00:00",
      "price": "328.79",
      "created-at": "2018-01-15T13:02:43.346Z",
      "updated-at": "2018-01-15T13:02:43.346Z"
    }
  }
}

GET /contracts/:id (Private)

Returns the contract for a given user-token and returns its data:

GET /contracts/2c31b4fb-ac16-4fce-8634-16f3dd2a093c
Content-Type: "application/json"
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZjNhMTc1MTgtM2M4NS00NDFiLWJiOTktNDQ4ZmQ3ZGEwYTAwIn0.8ilUS6nx8OlM1KLHvHV6_PE1pCoiaeq_TQczvLl6rzg"
Attribute Description
id contract id
Returns:
200 OK
Content-Type: "application/vnd.api+json"

{
  "data": {
    "id": "2c31b4fb-ac16-4fce-8634-16f3dd2a093c",
    "type": "contracts",
    "attributes": {
      "vendor": "DB",
      "starts-on": "2018-01-30 00:00:00",
      "ends-on": "2018-12-30 00:00:00",
      "price": "328.79",
      "created-at": "2018-01-15T13:02:43.346Z",
      "updated-at": 
5D3B
"2018-01-15T13:02:43.346Z"
    }
  }
}

DELETE /contracts/:id (Private)

Deletes a contract for a given user-token:

DELETE /contracts/2c31b4fb-ac16-4fce-8634-16f3dd2a093c
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZjNhMTc1MTgtM2M4NS00NDFiLWJiOTktNDQ4ZmQ3ZGEwYTAwIn0.8ilUS6nx8OlM1KLHvHV6_PE1pCoiaeq_TQczvLl6rzg"
Attribute Description
id contract id
Returns:
204 No content

About

Contracts API is a simple Rails API designed to manage vendor contracts and its lifetime.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0