chazsimons / bragging-rights-be

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Imgur

A Comic Trivia Challenge (2 week sprint)

Chaz Simons, Sam Devine, Matthew Kimball, Ted Staros & Christian Valesares

CircleCI Ruby Rails

"Bragging Rights" is a trivia competition app designed to consume two external APIs to gather questions and location data of players, and pass the information to our front-end application. It's also responsible for scoring games, containing the score and location data received from the players.

Architecture

This app uses a service-oriented architecture, with seperate frontend and backend rails applications. This is the backend repository. Users of Bragging rights don't interact with this repository directly, but rather through the frontend app here. The backend application is responsible for making API calls to the APIs listed below, storing game data when users complete a quiz, and making that data available through several endpoints to be consumed by the frontend.

For a relatively small app like this, there aren't many advantages to choosing a SOA over a Rails monolith. However, gaining some exposure to SOA was one of our primary learning goals for this project, and we chose to implement it simply in pursuit of learning more about what it takes to build professional web applications in this style.

Schema

Imgur

Tools Used:

Setup

  • From the command line, install gems and set up your DB:
    • bundle
    • rails db:{create,migrate}
  • Run the test suite with bundle exec rspec.
  • Run your development server with rails s to see the app in action.

Endpoints

The backend API base path is:

https://fast-inlet-74665.herokuapp.com/api/v1/{query}

{query} should be replaced with one of the following endpoints.

1. Questions

   GET questions

Returns a collection of 5 comic-themed, multiple choice trivia questions, and their correct answers. The correct answer is included in the "answers" array, in a random (shuffled) position. The questions are limited to what is availabe in the OpenTDB API, so you may start to notice repeated questions on multiple calls. As of 01.12.22, only 50 questions can be returned. Example response:

   {
    "data": [
        {
            "id": "1",
            "type": "question",
            "attributes": {
                "id": "1",
                "question": "In Marvel Comics, Taurus is the founder and leader of which criminal organization?",
                "correct_answer": "Zodiac",
                "answers": [
                    "The Union",
                    "Scorpio",
                    "Zodiac",
                    "Tiger Mafia"
                ]
            }
        }
     ]
   }

2. High Scores

   GET scores

This endpoint will return 20 scores from the database, sorted from high to low. These results can optionally be filtered by location or user (but not both) using the parameters below.

Parameters and Usage

Please note that only one parameter may be passed to this endpoint, but none are required. Passing more than one parameter or invalid data will return an error.

  • city={city}
  • state={state}
  • country={country}
  • user_id={user_id}

The following examples are all valid calls:

   GET scores?city=Denver
   GET scores?state=Colorado
   GET scores?country=United+States
   GET scores?user_id=1  # assumes there is a user with id = 1 in the database

3. Record a Game

   POST scores 

Record new scores to the database. All of the following parameters are required:

  • user_id={user_id}
  • score={score}
  • ip_address={user_ip_address}

4. User Location

   GET locations?ip_address={user_ip_address}

Returns a user's city, state, and country to store game data and make comparing scores a breeze. The user's actual IP Address is a required query parameter. Without it, incorrect locations may be returned. Note: a null value for id will always be returned.

Example Response:

{
    "data": {
        "id": null,
        "type": "location",
        "attributes": {
            "city": "Denver",
            "state": "Colorado",
            "country": "United States"
        }
    }
}

APIs

We used 3 different APIs in this project. They are listed below:

  1. Open Trivia Database
  2. IP Geolocation API
  3. Twitter API

About


Languages

Language:HTML 77.0%Language:Ruby 23.0%