Skip to content
/ lol-api Public
forked from tristanbes/lol-api

Simple PHP wrapper for League of Legends API

Notifications You must be signed in to change notification settings

kiperz/lol-api

 
 

Repository files navigation

League of Legends API wrapper in PHP

Scrutinizer Code Quality Code Coverage Build Status Build Status SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

Introduction

Simple PHP wrapper for League of legends API.

This library implements two custom exceptions to catch your API rate limits (ServiceRateLimitException && UserRateLimitException).

It also implements Doctrine cache to cache the API results into your favorite cache driver.

Migration from 0.* to 1.*

Three main features breaking BC caused a bump to the 1.* version:

  • Cache implementation
  • AbstractRateLimitException
  • Return of an ApiResult object instead of an array

Only the third one can actually break BC. You should now use the getResult() method on the ApiResult object returned.

How to use

Basic use

You first have to select the API you want to fetch from and then the specific method. Each call will return an ApiResult object containing the URL called, the Guzzle Response object and an array containing the API result.

To get the result you can call the method getResult() on the ApiResult object.

$apiClient = new \LoLApi\ApiClient(\LoLApi\ApiClient::REGION_EUW, 'my-key');

$apiClient->getMatchListApi()->getMatchListBySummonerId(2);
$apiClient->getMatchApi()->getMatchByMatchId(2, true);
$apiClient->getSummonerApi()->getSummonerBySummonerName('MySummonerName');
$apiClient->getSummonerApi()->getSummonerBySummonerId(2);
$apiClient->getMasteriesApi()->getMasteriesBySummonerId(2);
$apiClient->getRunesApi()->getRunesBySummonerId(2);
$apiClient->getSummonerApi()->getSummonerNameBySummonerId(2);
$apiClient->getChampionApi()->getChampionById(20);
$apiClient->getFeaturedGamesApi()->getFeaturedGames();
$apiClient->getStatsApi()->getRankedStatsBySummonerId(2);
$apiClient->getGameApi()->getRecentGamesBySummonerId(2);
$apiClient->getCurrentGameApi()->getCurrentGameByPlatformIdAndSummonerId('EUW1', 2);

Use cache

By default Doctrine's VoidCache provider is implemented. You can specify another Cache provider (implementing doctrine CacheProvider abstract class) to the ApiClient.

Example with Predis :

$client = new \Predis\Client([
    'scheme' => 'tcp',
    'host'   => '127.0.0.1',
    'port'   => 6379,
]);

$apiClient->setCacheProvider(new \Doctrine\Common\Cache\PredisCache($client));

// This will call the API and return to you an ApiResult object
$result = $apiClient->getSummonerApi()->getSummonersBySummonerNames('MySummonerName');

// Let's cache this result for 60 seconds into Redis
$apiClient->cacheApiResult($result, 60);

// This will fetch the data from Redis and return to you an ApiResult object
$result = $apiClient->getSummonerApi()->getSummonersBySummonerNames('MySummonerName');

The default ttl value cacheApiResult() method is 60 seconds.

Rate limit

When you reach the rate limit (User or Service) the library will throw you an implementation of the AbstractRateLimitException. You can get the type of rate limit and the time to wait before a new call (Riot is very strict on the rate limit respect).

Example with a sleep :

$apiClient = new \LoLApi\ApiClient(\LoLApi\ApiClient::REGION_EUW, 'my-key');

for ($i = 0; $i < 100; $i++) {
    try {
        $apiClient->getMatchListApi()->getMatchListBySummonerId(2);
    } catch (AbstractRateLimitException $e) {
        sleep($e->getRetryAfter());
    }
}

API implemented

API Version
Summoner API v3
MatchList API v2.2
Match API v2.2
Champion API v3
Featured games API v*.*
Stats API v1.3
Team API removed
Game API v1.3
Current game API v*.*
Static Data API v3
League API v2.5
Status API v*.*
Champion Mastery API v*.*
Masteries API v3
Runes API v3

Contributing

Please create issues if you have any problem with this library integration.

If you want to contribute, create a PR, you must respect PSR-2 and your code must be tested.

Thank you !

About

Simple PHP wrapper for League of Legends API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%