Git Product home page Git Product logo

bowling_game_api's Introduction

Bowling Game API

Table Of Contents

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 if not.)
rbenv install 3.3.0

Installation

  1. Clone the repo
git clone https://github.com/kishan-aghera/bowling_game_api.git 
  1. Move into the bowling_game_api directory.
cd bowling_game_api
  1. Bundle the required gems
bundle install
  1. Start the sinatra server
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:
{
  "pins": 5
}
  • This should give response like shown below.
{
  "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.
{
  "message": "Success",
  "current_score": 5,
  "total_score": 5,
  "last_frame": "none"
}

Using IRB:

  1. Run IRB from within the project's directory.
irb
  1. Require the bowling_game rb class.
require_relative "./bowling_game"
  1. Initialize the class.
game = BowlingGame.new
  1. 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

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
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

bowling_game_api's People

Contributors

kishan-aghera avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.