Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kishan-aghera/bowling_game_api
https://github.com/kishan-aghera/bowling_game_api
api rspec sinatra
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kishan-aghera/bowling_game_api
- Owner: kishan-aghera
- License: mit
- Created: 2024-04-07T09:33:57.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-08T11:20:22.000Z (7 months ago)
- Last Synced: 2024-10-09T10:44:54.887Z (about 1 month ago)
- Topics: api, rspec, sinatra
- Language: Ruby
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bowling Game API
## Table Of Contents
* [About the Project](#about-the-project)
* [Built With](#built-with)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Usage](#usage)
* [Testing](#testing)## About The Project
This repo contains API using which you can calculate score for a bowling game.
## Built With
- Ruby 3.3.0
- Sinatra for API server
- Rspec for testing## Getting Started
### Prerequisites
* ruby (Make sure rbenv is installed. Please refer [rbenv](https://github.com/rbenv/rbenv?tab=readme-ov-file) if not.)
```sh
rbenv install 3.3.0
```### Installation
1. Clone the repo
```sh
git clone https://github.com/kishan-aghera/bowling_game_api.git
```2. Move into the bowling_game_api directory.
```sh
cd bowling_game_api
```3. Bundle the required gems
```sh
bundle install
```4. Start the sinatra server
```sh
ruby server.rb
```## Usage
### Using Postman/Thunder Client:
- There are 3 APIs that are created:
#### POST /start
- This will initialize an object of the BowlingGame class.
#### POST /roll
- 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 like `5`. So, pass parameters in body in JSON format like:```json
{
"pins": 5
}
```- This should give response like shown below.
```json
{
"message": "Roll successful.",
"current_score": [
{
"rolls": [
5
],
"score": 5
}
],
"total_score": 5,
"last_frame": "none"
}
```#### GET /current_score
- This will give output something like shown below.
```json
{
"message": "Success",
"current_score": 5,
"total_score": 5,
"last_frame": "none"
}
```### Using IRB:
1. Run IRB from within the project's directory.
```sh
irb
```2. Require the `bowling_game` rb class.
```ruby
require_relative "./bowling_game"
```3. Initialize the class.
```ruby
game = BowlingGame.new
```
4. There are various methods available that you can use. e.g.i. To roll a pin let's say 5, use
```ruby
game.roll(5)
```ii. To get current score, use
```ruby
game.current_score
```This should return
```ruby
5
```iii. To get total score, use:
```ruby
game.total_score
```This should return
```ruby
5
```## Testing
- Rspec is used for testing this API as well as the class.
- In order to run all the spec files at once, please run```sh
rspec
```- In order to run spec file for API, run
```sh
rspec spec/bowling_api_spec.rb
```- In order to run spec file for the Bowling Game class, run
```sh
rspec spec/bowling_game_spec.rb
```