This repo contains API using which you can calculate score for a bowling game.
- Ruby 3.3.0
- Sinatra for API server
- Rspec for testing
- ruby (Make sure rbenv is installed. Please refer rbenv if not.)
rbenv install 3.3.0
- Clone the repo
git clone https://github.com/kishan-aghera/bowling_game_api.git
- Move into the bowling_game_api directory.
cd bowling_game_api
- Bundle the required gems
bundle install
- Start the sinatra server
ruby server.rb
- There are 3 APIs that are created:
- This will initialize an object of the BowlingGame class.
- This is used to add roll and update the score.
- We will need to pass
pins
key with the no. of pins fallen as integer like5
. So, pass parameters in body in JSON format like:
{
"pins": 5
}
- This should give response like shown below.
{
"message": "Roll successful.",
"current_score": [
{
"rolls": [
5
],
"score": 5
}
],
"total_score": 5,
"last_frame": "none"
}
- This will give output something like shown below.
{
"message": "Success",
"current_score": 5,
"total_score": 5,
"last_frame": "none"
}
- Run IRB from within the project's directory.
irb
- Require the
bowling_game
rb class.
require_relative "./bowling_game"
- Initialize the class.
game = BowlingGame.new
- There are various methods available that you can use. e.g.
i. To roll a pin let's say 5, use
game.roll(5)
ii. To get current score, use
game.current_score
This should return
5
iii. To get total score, use:
game.total_score
This should return
5
- Rspec is used for testing this API as well as the class.
- In order to run all the spec files at once, please run
rspec
- In order to run spec file for API, run
rspec spec/bowling_api_spec.rb
- In order to run spec file for the Bowling Game class, run
rspec spec/bowling_game_spec.rb