Scooter-Sharing-Aggregator

Web-service with RESTful API that allows user to aggregate information about scooters among different scooter sharing apps. It also allows to book and unbook preferred scooter.

Local test run

Aggregator:

prerequisites:

  • nginx (example of config in config/nginx.config)
  • mongodb
  • update MONGO_CONNECTION_STR in Makefile to correspond to your mongo uri
  • pip install -r requirements.txt

User-to-Aggregator API

GET /api

Response

  • 200 OK


Response body example

{
  "_links": {
    "clients": { "href": "/clients" },
    "scooters": { "href": "/scooters" }
  }
}

POST /clients
Register new client.

Response

  • 201 - Created.


Response body example

{
   "uuid": 100200300,
   "_links": {
     "self": { "href": "/clients" }
   }
}

GET /scooters
Gets all available scooters.

Response

  • 200 OK


Response body example

{
  "scooters": [
    {
      "scooter_id": 1,
      "lon": 1,
      "lat": 0,
      "price": 5
    }
  ],
  "_links": {
    "self": { "href": "/scooters" },
    "nearest": { "href": "/scooters/nearest" },
    "book": { "href": "/scooters/{id}/reservations" },
    "unbook": { "href": "/scooters/{id}/reservations" }
  }
}

GET /scooters/nearest
Gets nearest available scooters.

Params:

  • lon, lat - user coordinates
  • max_price[optional] - max possible price for scooter driving per hour
  • limit[optional] - max possible amount of the nearest scooters in response

Response

  • 200 - OK


Response body example

{
  "scooters": [
    {
      "scooter_id": 1,
      "lon": 1,
      "lat": 0,
      "price": 5
    }
  ],
  "_links": {
    "self": { "href": "/scooters/nearest" },
    "book": { "href": "/scooters/{id}/reservations" },
    "unbook": { "href": "/scooters/{id}/reservations" }
  }
}

POST /scooters/{id}/reservations
Ask to book the scooter in the 3d party app.

Params

  • uuid - client id

Response

  • 204 - No Content - Success.
  • 409 - Conflict - If the scooter has already been locked.


Response body example

{  "message": "This scooter has already been locked." }

DELETE /scooters/{id}/reservations
Ask to unbook the scooter in the 3d party app.

Params

  • uuid - client id

Response

  • 204 - No Content - Success.

Supported HTTP Status Codes:


200 OK Successful request.
201 Created
204 No Content The server has fulfilled the request but does not need to return an entity-body.
400 Bad Request Wrong URI or JSON representation of data.
404 Not found The requested resource could not be found.
409 Conflict Same or very similar resource already exists.
500 Internal Server Error Unexpected condition was encountered on server and request can't be handled.

Aggregator-Scooter-Service API

GET /vehicles
Gets all available scooters in the app.

Response

  • 200 - OK


Response body example

{
  "vehicles": [
    {
      "scooter_id": 1009,
      "lon": 50,
      "lat": 40,
      "price": 1
    },
    {
      "scooter_id": 1008,
      "lon": 22,
      "lat": 12,
      "price": 1
    }
  ]
}

POST /vehicles/{id}/reservations

Parameters

  • uuid - client id

DELETE /vehicles/{id}/reservations

Parameters

  • uuid - client id