HazemNoor / game-finder

This Laravel application provides an API that displays information about a video game fetched from list of websites

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

This laravel application provides an API that displays information about a video game fetched from list of websites

Installation

  1. Fetch project
git clone git@github.com:HazemNoor/game-finder.git
cd game-finder
  1. Copy file .env.example into .env
cp .env.example .env
  1. Edit file .env adding values for these constants
TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=
RAWG_CLIENT_API_KEY=

Get these values from their websites

  1. You many need to update these values related to Docker in .env
SERVER_HTTP_PORT=80
SERVER_HTTPS_PORT=443

USER_ID=1000
GROUP_ID=1000
  1. Make sure to have docker-compose installed on your machine, then execute this command to build docker images
make build
  1. Run this command to execute composer install
make up
make install

Other commands

  • Run tests
make up
make test
  • If you need to log in to docker container, use these commands
make up
make login
  • Stop docker containers
make down

API

The provided API is

GET http://localhost/api/games

Query Parameter
search=Red Alert 2

Header
Accept: application/vnd.api+json

Example API call via CURL

curl --request GET \
  --url 'http://localhost/api/games?search=Red%20Alert%202' \
  --header 'Accept: application/vnd.api+json'

Sample successful response body

{
  "results": [
    {
      "name": "Command & Conquer: Red Alert 2",
      "image": "https:\/\/media.rawg.io\/media\/games\/673\/67304bfba37b6a18c50a60ab6ba6cebd.jpg"
    },
    {
      "name": "Command & Conquer: Red Alert",
      "image": "https:\/\/media.rawg.io\/media\/games\/e87\/e87bbd9feb37b226b1b6a4f11e9492a0.jpg"
    }
  ]
}

How clients work together

  • All Clients are registered to ClientFactory through GameFinderProvider, you can add new clients there
$factory->addClient($client);
  • Clients are Consecutively used in the same order they are registered in ClientFactory
  • If a Client fails or doesn't return results we continue to use the next Client, otherwise, we just use result from that Client
  • Results are returned in the same order that is returned from Clients
  • If any Error happens in any Client, an Exception ClientRuntimeException is reported for further analysis later

Testing

Testing is divided in two classes HazemNoor\GameFinder\Tests\ApiTest and HazemNoor\GameFinder\Tests\GameFinderTest You can run unit test using these commands

make up
make test

Coding Style

The coding style used is PSR-12 and is included with the testing command make test using PHP_CodeSniffer

Todo

  • Implement Circuit Breaker Algorithm to prevent failures from constantly recurring after a certain threshold of failures in Clients
  • Implement apiDoc for API Documentation
  • Add API Authentication

About

This Laravel application provides an API that displays information about a video game fetched from list of websites


Languages

Language:PHP 81.6%Language:Blade 16.3%Language:Shell 1.0%Language:Dockerfile 0.7%Language:Makefile 0.5%