1 - Clone the project with :
$ git clone https://github.com/AdilOmary/rps-game
2 - Change directory to rps-game
:
$ cd rps-game
3 - Download dependencies:
$ bundle install
4 - Setup the database:
$ rails db:create
$ rails db:migrate
5 - Start the server with the following command :
$ rails s
POST/games
: You can play the game and save it in the Database. You will get a response with the player's move, the bot's move and the result.GET/games
: Retrieve all the past games from the database.
- Download the app on https://www.postman.com/
- Go to "My workspace" then click "Create a request"
- Go to the body panel, then "raw" and select "JSON" format
- Set the URL to
http://localhost:3000/games
If you want to play the game, you can POST
the player's name
and move
to the API.
- Select
POST
on the dropdown button - Type the following request :
{
"name": "Ponky",
"move": "rock"
}
The response will be sent back to the POSTMAN client, with the Bot's move and the result.
To get the past games history, send a GET
request to the URL, you can specify limit
and offset
options for pagination:
- Select
GET
on the dropdown button - Add the options to the url (type
?
followed by the key value pairs separated by&
), e.g:http://localhost:3000/games?limit=2&offset=4
will get the first 2 items starting from the 4th one. - Click "send", you will receive a response with an array of the requiered records.
- Refactor the functions and make it less long.
- Serializer the json_response.
- Improve the errors's handling.