lpphan/riot-api

A simple wrapper for the League of Legends API.

0.1.1 2016-08-05 13:02 UTC

This package is not auto-updated.

Last update: 2024-03-16 16:14:39 UTC


README

Version 0.1.1

Introduction

A simple PHP wrapper for League of legends API.

How to Install

Require the package with composer:

composer require lpphan/riot-api

Example usage

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);

Regions

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);

Cache

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);         				

Exceptions handling

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