Giter Club home page Giter Club logo

bowling_game's Introduction

Restful Webservice to allow the users to player a bowling game Build Status

Table of Contents

Requirements

  • Python 3.6.5
  • Django framework
  • Django Rest Framework

Setup

  • Clone the repository.

  • Install Python 3.6.5 and above. You can use your favourite tool to install the software (HomeBrew, pyenv)

  • Set up virtualenv with the following command virtualenv -p `which python3` env

  • Install the python packages required by the project by executing pip install -r requirements.txt.

  • Run the migration scripts by executing the following commands from the home directory cd bowling_game && python manage.py migrate

  • Run the command python manage.py runserver to start the server.

API Endpoints

POST /game/register

Registers a bowling game for the contestant and assigns a unique 16 character alpha numeric string representing a unique game id.

A response body will include:

โ— a status code of 201 Created

โ— Response Body Properties

Name Type Description Read only
game_id string Unique game id true
created timestamp UTC timestamp true
{
    "game_id": "MYCjFlD8Rc9dzu5W",
    "created": "2018-07-19T22:05:41.647970Z"
}

A error response will be an error of error objects.

Name Type Description Read only
errors array array of errors true

where each error object consists of the following fields

Name Type Description Read only
error code number error code indicating the kind of error true
error message string user friendly message true

The sample response is given below:

{
    "errors": [
        {
          'error_code': 403,
          'error_message': 'Forbidden from registering a game.'
        }
    ]
}

POST /game/<game_id>/score/

Registers the score of the contestant for a given frame, and returns the total score in the response payload.

Response body after playing a frame is given below:

Name Type Description Read only
game string Unique game id passed as a path variable true
frame int number of frames played true
frame_score int sum of score of each attempt in a frame; if attempt resulted in a spare or a strike, the value returns null till the time it can be calculated true
total_score_for_frame int total game score; if the score can not be calculated at that time, then null is returned. This is especially in case of strikes, or spares true

All scores in an open frame are separated by -. For example, a score of 7-2 indicates that the player knocked down 7 pins in the first attempt, and 2 pins in the second attempt.

Score Description
X-X-X All strikes in all 3 attempts in the last frame
X-X-<0-9> two strikes and open frame in the last frame
X-<0-9>/ strike and a spare in the last frame)
X-<0-9>-<0-9> strike and two open scores in the last frame
X strike in any frame other than the last frame
<0-9>/X spare and a strike in the last frame
<0-9>/<0-9> spare and an open frame in the last frame
<0-9>/ spare for any attempt except in the last frame
<0-9>-<0-9> score for a open frame

The sample response below gives the score after an open frame.

{
    "game": "MYCjFlD8Rc9dzu5W",
    "frame": 6,
    "frame_score": 9,
    "total_score_for_frame": 105
}

The sample response below gives the score after a strike or a spare.

{
    "game": "MYCjFlD8Rc9dzu5W",
    "frame": 6,
    "frame_score": null,
    "total_score_for_frame": 105/<null> (score that has been calculated so far, or `null` if it can not be calculated until now)
}

The error response is body is an array of errors.

Name Type Description Read only
errors array array of error objects true

where each error object consists of the following fields

Name Type Description Read only
error code number error code indicating the kind of error true
error message string user friendly message true

Some of the sample responses are given below

This will return a 404 error if no record for the game was found in the database.

{
    "errors": [
        {
          "error_code": 404,
          "error_message" : "No game was found for the game id: <game_id>."
        }
    ]
}

This will return a 404 error if no record for the game was found in the database.

{
    "errors": [
        {
          "error_code": 400,
          "error_message" : "Score format: <score> is invalid."
        }
    ]
}

This will return a 404 error if no record for the game was found in the database.

{
    "errors": [
        {
          "error_code": 400,
          "error_message" : "Game:\'<game_id>\' has already been played."
        }
    ]
}

This will return a 404 error if no record for the game was found in the database.

{
    "errors": [
        {
          "error_code": 500,
          "error_message" : "Unable to save score: '<score>' for game: '<game_id>'."
        }
    ]
}

GET /game/<game_id>/score

Returns the score of the game at any given time.

The response body consists of

Name Type Description Read only
game_id string Unique game id passed as a path variable true
total_score int Total score till the present time true

The sample response is given below.

{
    "total_score": 182,
    "game_id": "<game_id>"
}

The error response is body is an array of errors.

Name Type Description Read only
errors array array of error objects true

where each error object consists of the following fields

Name Type Description Read only
error code number error code indicating the kind of error true
error message string user friendly message true

Some of the sample responses are given below

{
    "errors": [
        {
            "error_code": 404,
            "error_message": "No game was found for the game id: <game_id>."
        }
    ]
}

bowling_game's People

Contributors

krishnanand avatar

Watchers

James Cloos 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.