gem install foreman
bundle install
cp .env.template .env # we are using a foreman env file, 12factor style
vim .env # add google places API key to env file
foreman run rails s
A user of the API is able to do the following
- CRUD users, hotels, cities, bookings
- See which hotels are nearby and using that information to create bookings
All endpoints need to be prefixed with /api/v0
, e.g. /bookings
becomes
/api/v0/bookings
.
Bookings can be created for one user, one hotel and one date. One user cannot have multiple bookings on the same day.
Retrieve a list of all bookings for all users.
[{
"id": 1,
"hotel": "hotel_name",
"city": "city_name",
"user": "user_name"
}, ... ]
Create a new booking.
Retrieve a booking with a certain id.
Patch a booking with a certain id.
Update a booking with a certain id.
Delete a booking with a certain id.
Hotels belong to a city and have a name.
Retrieve a list of all hotels.
[{
"id": 1,
"name": "The Westin Grand Berlin",
"created_at": "2016-01-20T22:01:26.819Z",
"updated_at": "2016-01-20T22:01:26.819Z",
"city_id": 1
}, ... ]
Create a new booking.
Retrieve a hotel with a certain id
Patch a hotel with a certain id
Update a hotel with a certain id
Delete a hotel with a certain id
Cities have names and contain hotels.
[{
"id": 1,
"name": "Berlin",
"created_at": "2016-01-20T21:59:16.696Z",
"updated_at": "2016-01-20T21:59:16.696Z"
}, ... ]
Retrieve a list of all hotels.
Create a new booking.
Retrieve a hotel with a certain id
Patch a hotel with a certain id
Update a hotel with a certain id
Delete a hotel with a certain id
Users have names and can have multiple bookings.
[{
"id": 1,
"name": "name",
"created_at": "2016-01-20T16:55:32.483Z",
"updated_at": "2016-01-20T16:55:32.483Z"
}, ... ]
Retrieve a list of all users.
Create a new user.
Retrieve a user with a certain id
Patch a user with a certain id
Update a user with a certain id
Delete a user with a certain id
Retrieve all bookings for a user.
{
"id":1,
"name": "name",
"bookings": [
...
]
}
Retrieve all hotels that are nearby. What is nearby gets decided by using a geo ip location server. That means that the suggestions vary by the location of the caller of this api endpoint.
This contains some trivial amount of magic. Everytime new hotels are encountered when requesting this endpoint, the controller adds a record of the hotel and the containing city, provided that they haven't been created before.
This information can then be used to create a booking using the /bookings
API
endpoint.
For someone living in Berlin, this can look as follows:
[{
"name": "The Westin Grand Berlin",
"id": 1,
"city": "Berlin",
"city_id": 1
}, ... ]
A test suite containing unit and integration tests can be run using
foreman run rails test