Skip to content

Latest commit

 

History

History
105 lines (80 loc) · 6.44 KB

README.md

File metadata and controls

105 lines (80 loc) · 6.44 KB

Giantbomb API

GitHub release Build Status Coverage Status

A library for easy interaction with Giantbomb API. Features are:

  • Caching support

Get your API Key at https://www.giantbomb.com/api

Requirements

  • PHP Redis extension. It can be installed using following command:
pecl install redis

Installation

composer require amalfra/giantbomb

This will create a vendor directory (if you dont already have one) and set up the autoloading classmap.

Usage

Once everything is installed, you should be able to load the composer autoloader in your code.

You can load the wrapper classes using namespace as:

require __DIR__ . '/vendor/autoload.php';

use \Amalfra\GiantBomb\Client as GiantBomb;

Now create a new object

$config = array(
	'token' => 'YOUR_KEY',
);

$gb_obj = new GiantBomb($config);

Now the available API methods can be called using the instance. All the result from API will be returned as an object. If any status code other than 200 is returned an exception would be thrown.

Currently Available Methods

Method Description
game(game_id, field_list) field_list should be comma seperated values
games(
    field_list: 'name,id',
    limit: 10,
    offset: 20,
    platforms: 2,
    sort: 'id:desc',
    filter: 'aliases:Desert Strike'
)
company(company_id, field_list) field_list should be comma seperated values
companies(
    field_list: 'name,id',
    limit: 10,
    offset: 20,
    sort: 'id:desc',
    filter: 'id:7'
)
genre(genre_id, field_list) field_list should be comma seperated values
genres(
    field_list: 'name,id',
    limit: 10,
    offset: 20
)
platform(platform_id, field_list) field_list should be comma seperated values
platforms(
    field_list: 'name,id',
    limit: 10,
    offset: 20,
    sort: 'id:desc',
    filter: 'id:3'
)
review(review_id, field_list) field_list should be comma seperated values
reviews(
    field_list: 'deck,id',
    limit: 10,
    offset: 20,
    sort: 'id:desc',
    filter: 'id:3'
)
game_rating(game_rating_id, field_list) field_list should be comma seperated values
game_ratings(
    field_list: 'name,id',
    limit: 10,
    offset: 20,
    sort: 'id:desc',
    filter: 'id:3'
)
character(character_id, field_list) field_list should be comma seperated values
characters(
    field_list: 'name,id',
    limit: 10,
    offset: 20,
    sort: 'id:desc',
    filter: 'id:3'
)
search(
    field_list: 'name,id',
    query: halo'',
    limit: 20,
    page: 2
    resources: 'game',
)

Cache

You can configure caching to prevent hitting API if same queries are made again. Currently supported caching methods are:

  • inmemory: cache will be stored in memory array. This won't be persisted after your script exits.
  • redis: cache will be stored in redis store which can be configured.

Cache can be configured using set_cache_provider method of GiantBomb instance. If it's not configured caching will be disabled and API will always be hit each time a method is called. set_cache_provider method accepts two parameter:

  1. [required] cache type eg: inmemory, redis etc
  2. [optional] an associative array in which additional configuration details required for setting up the cache method can be given eg: redis server host and port values

using inmemory cache method

This method does not need any additional configuration option than just activating by calling set_cache_provider method with inmemory as first parameter. eg:

$gb_obj->set_cache_provider('inmemory');

using redis cache method

This method can be activated by calling set_cache_provider method with redis as first parameter. You will also need to specify redis server host and port as second parameter. eg:

$gb_obj->set_cache_provider('redis', array('host' => 'localhost', 'port' => 6379));

Development

Questions, problems or suggestions? Please post them on the issue tracker.

You can contribute changes by forking the project and submitting a pull request. Feel free to contribute 😍

UNDER MIT LICENSE

The MIT License (MIT)

Copyright (c) 2013 Amal Francis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.