PHP code example of michaelgarrez / lol-api

1. Go to this page and download the library: Download michaelgarrez/lol-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelgarrez / lol-api example snippets


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

$apiClient->getMatchApi()->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->getSpectatorApi()->getCurrentGameByPlatformIdAndSummonerId('EUW1', 2);

use Symfony\Component\Cache\Adapter\RedisAdapter;

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

$redisAdapter = new RedisAdapter($client);

$apiClient->setCacheProvider($redisAdapter);

// This will call the API and return to you an ApiResult object
$result = $apiClient->getSummonerApi()->getSummonerBySummonerName('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()->getSummonerBySummonerName('MySummonerName');

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

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