Giter Site home page Giter Site logo

lol-api's Introduction

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->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 cache

By default Symfony NullAdapter cache is used. You can specify another Cache Adapter (implementing PSR6 Adapters) to the ApiClient.

Example with Predis :

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

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->getMatchApi()->getMatchListByAccountId(2);
    } catch (AbstractRateLimitException $e) {
        sleep($e->getRetryAfter());
    }
}

API implemented

API Version
Summoner API v3
Match API v3
Champion API v3
Spetactor API v3
Static Data API v3
League API v3
Status API v3
Champion Mastery API v3
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 !

lol-api's People

Contributors

babacooll avatar miukoba avatar strebl avatar tristanbes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lol-api's Issues

Tournament API

Hi,

I'm developing a website that need create Tournaments, but there is no any PHP library that we can create Tournaments from Riot API. Did you intend implement this functionality? Thanks.

Error [I tried to open]

I tried to open the API and an error occurred:

Fatal error: Uncaught Error: Class 'LoLApi\ApiClient' not found in /Applications/XAMPP/xamppfiles/htdocs/leagues/leagues.php:4 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/leagues/leagues.php on line 4

Built with lol-api

I think a section in the readme of projects build with your library would be great. Booth, for users and for you I think.
Wouldn't it be nice to know who uses your package?

What do you think?

Importing the API

I'm using xampp on Windows and It's pretty mess to use composer to import the API. I've been trying to look for autoload.php file but I couldn't find, so it will be great if you can create some documentation about installing/importing/using the API on a new web page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.