Version 0.1.1
A simple PHP wrapper for League of legends API.
Require the package with 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);
You can set the region that you wish to query. By default it is 'na' but it can be changed.
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);
By default, the cache requires memcached
to be installed and operating on default port and localhost.
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);
The cache can be changed by implement your own version of 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
}
//Todo : add doc