lpphan/riot-api

League of Legends API 的简单包装。

0.1.1 2016-08-05 13:02 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:20:07 UTC


README

版本 0.1.1

简介

一个简单的 PHP 包装器,用于 League of Legends API

安装方法

使用 composer 安装包

composer require lpphan/riot-api

示例用法

use Lpphan\RiotApi;

// Load up the API
$api = new RiotApi($apiKey);  

// Load up the summoner api object.          				
$summoner = $api->summonerApi();    

// Get the information about this user, this will return an Lpphan\Response object					
$response  = $summoner->getSummonerByNames($arrayOfSummonerName);    

$info = $response->getBody();
print_r($info);

地区

您可以设置要查询的地区。默认为 'na',但可以更改。

use Lpphan\RiotApi;
use Lpphan\Regions;

// Load up the API
$api = new RiotApi($apiKey);
$api->setRegion(Regions::BR);

//or
$summoner = $api->summonerApi();
$api->setRegion(Regions::BR);
$summoner->getSummonerByNames($array);

缓存

默认情况下,缓存需要安装并运行在默认端口和本地主机上的 memcached

use Lpphan\RiotApi;

$api = new RiotApi($apiKey);         				
$summoner = $api->summonerApi();    
 
//Cache this response for 5 minutes
$response = $summoner->getSummonerByNames(['summonerName'])->remember(5);

//or use this
$api->remember($response,5);

可以通过实现自己的 Lpphan\CacheInterface 版本来更改缓存;

use Lpphan\RiotApi;

//set custom cache
$api = new RiotApi($apiKey,$cacheProvider);

//or use this
$api->setCache($cacheProvider);         				

异常处理

use Lpphan\RiotApi;

$api = new RiotApi($apiKey);
$summoner = $api->summonerApi();

try{
	$response = $summoner->getSummonerByNames(['summonerName']);
}catch (Lpphan\Exception\Http404Exception $e){
	//throw when a 404 http error is found
}catch (Lpphan\Exception\Http429Exception $e){
        //Rate limit exceeded
        //Should retry after
        $seconds = $e->retryAfter();
}catch (Lpphan\Exception\HttpException $e){
	//throw for all http error
}  				

//待办:添加文档