giantbomb / giantbomb-php-api
一个用于与 GiantBomb API 交互的 PHP 库
1.3.1
2013-12-27 21:48 UTC
Requires
- php: >=5.3.3
- doctrine/cache: 1.3.*
- guzzle/guzzle: ~3.7
Requires (Dev)
README
要求
安装
在项目根目录中,运行以下命令
composer require giantbomb/giantbomb-php-api dev-master
这将创建一个 vendor
目录(如果您还没有的话),并设置自动加载的类映射。
使用方法
一旦安装完成,您应该可以在代码中加载 composer 自动加载器,然后继续操作!
这里有一个非常简单的例子
require __DIR__ . '/vendor/autoload.php'; use \GiantBomb\Client\GiantBombClient; $config = array( 'apiKey' => 'your-api-key', 'cache' => array( 'type' => 'redis', // Or memcached 'servers' => array( array( 'host' => 'localhost', 'port' => 6397, 'timeout' => 0 ) ), // weight is also a parameter for memcached 'persistent' => true ) ); /** Memcached also has the "options" parameter for specifiying Memcached options (via constants) Redis also has the "password" parameter for auth, and "dbindex" for specifying your db */ $client = GiantBombClient::factory( $config ); $requestArgs = array( 'limit' => 100, // Max of 100, 'offset' => 0, // Default is 0 // 'field_list' => 'name', // Default is not set // 'sort' => 'name|asc', // Default is not set // 'filter' => 'name:portal 2', // Default is not set ); // Depending on the query, there are different options afailable. Check out the [service description][3] for more information. $response = $client->getGames( $requestArgs ); if( $response->getStatusCode() === 1 ) { printf( "There are %d total results. Currently showing %d, starting at %d.\n<br /><br />", $response->getNumberOfTotalResults(), $response->getNumberOfPageResults(), $response->getOffset() ); $games = $response->getResults(); // HUGE dump. Careful //var_dump( $games ); // Get more info on a single game $game = $games->get( 0 )->getDetail()->getResults(); // All functions are magic functions based on the camel case of the key from the API result. This goes for anything returned from the API printf( "Game: %s<br />", $game->getName() ); } else { printf( "There was an error: %s", $response->getError() ); }
如果您有任何问题,请随时创建一个问题,我会帮助您解决!
贡献
如果您想帮忙,只需提交一个 pull request!