League of Legends PHP API wrapper
Dead simple wrapper of Riot Games API (LoL), (*1)
Requirements
- PHP 7.1
- works better with ext-curl installed
Installation
composer require proveyourskillz/lol-api
, (*2)
Creating API instance
$api = new PYS\LolApi\Api(API_KEY);
Laravel/Lumen service provider and Facade
Laravel/Lumen 5.5
ServiceProvider and Facade are registered automatically through package discovery, (*3)
Laravel 5.4
In config/app.php
add PYS\LolApi\Laravel\ServiceProvider
as provider, (*4)
Lumen 5.4
Register ServiceProvider according documentation, (*5)
Optionally you can add facade to aliases 'LolApi' => PYS\LolApi\Laravel\Facade::class
, (*6)
After installation, you can use API through facade or inject as dependency, (*7)
Usage
You can find examples of usage in examples
dir, (*8)
Region
You can pass region to request as 2-3 characters code but better use Region
class constants, (*9)
use PYS\LolApi\ApiRequest\Region;
$summoner = $api->summoner(Region::EUW, $summonerId);
Summoner
There are several ways to get Summoner: by account id, summoner id or by name, (*10)
// You can get summoner in several ways by passing type in third argument
// Default version: summoner, you can ommit it
$summonerById = $api->summoner($region, $summonerId);
$summonerByAccount = $api->summoner($region, $accountId, 'account');
$summonerByName = $api->summoner($region, $name, 'name');
For more information see Summoner API reference, (*11)
Match List
Recent, (*12)
$matches = $api->matchList($region, $accountId);
Recent via Summoner, (*13)
$matches = $api->summoner($region, $summonerId)->recentMatches();
Using query (e.g. one last match), (*14)
$matches = $api->matchList(
$region,
$accountId,
[
'beginIndex' => 0,
'endIndex' => 1,
]
);
Match
Match by Id, (*15)
$match = $api->match($region, $matchId);
Match within Tournament, (*16)
$match = $api->match($region, $matchId, $tournamentId);
For more information see Match API reference, (*17)
Leagues
Leagues and Positions of summoner by Summoner Id, (*18)
$leaguesPositions = $api->leaguePosition($region, $summonerId);
Leagues and Positions of summoner via Summoner object, (*19)
$leaguesPositions = $api
->summoner($region, $summonerId)
->leaguesPositions();
Leagues by Summoner Id, (*20)
$leagues = $api->league($region, $summonerId);
Reusable requests and queries
Examples from above (e.g., match list request with query) are shows usage of syntax sugar methods and can be rewritten as, (*21)
use PYS\LolApi\ApiRequest\MatchListRequest;
use PYS\LolApi\ApiRequest\Query\MatchListQuery;
$api = new PYS\LolApi\Api($API_KEY);
$query = new MatchListQuery;
$request = new MatchListRequest($region, $accountId);
$request->setQuery($query->lastMatches(1));
$matchList = $api->make($request);
Query objects have fluent setters for easy setup some properties like dates etc., (*22)
// Setup query object to get last 5 matches in 24 hours
$query = new MatchListQuery;
$query
->fromDate(new DateTime('-24 hours'))
->lastMatches(5);
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
History
Alpha version, (*23)
Credits
License
MIT, (*24)