Skip to content

LeagueAPI: How to begin

Daniel Dolejška edited this page Aug 2, 2017 · 10 revisions

How to begin? It's easy.

//  Include all required files
require_once __DIR__  . "/vendor/autoload.php";

use RiotAPI\RiotAPI;
use RiotAPI\Definitions\Region;

//  Initialize the library
$api = new RiotAPI([
	//  Your API key, you can get one at https://developer.riotgames.com/
	RiotAPI::SET_KEY    => 'YOUR_RIOT_API_KEY',
	//  Target region (you can change it during lifetime of the library instance)
	RiotAPI::SET_REGION => Region::EUROPE_EAST,
]);

//  And now you are ready to rock!
$ch = $api->getStaticChampion(61); // Orianna <3

And there is a lot more what you can set when initializing the library, here is a complete list:

Library settings key Value Description
RiotAPI::SET_REGION Region::EUROPE_EAST, Region::EUROPE_WEST, Region::NORTH_AMERICA, string Required. Used to specify, to which endpoint calls are going to be made.
RiotAPI::SET_KEY string Required. Option to specify your API key.
RiotAPI::SET_TOURNAMENT_KEY string Option to specify your tournament API key.
RiotAPI::SET_VERIFY_SSL bool default true Use this option to disable SSL verification. Useful when testing on localhost. Shoul not be used in production.
RiotAPI::SET_KEY_INCLUDE_TYPE RiotAPI::KEY_AS_QUERY_PARAM, RiotAPI::KEY_AS_HEADER This option determines how is API key going to be included in the requests (by default RiotAPI::KEY_AS_HEADER).
RiotAPI::SET_INTERIM bool default false By specifying this, you tell the library to be in interim mode and use interim-only endpoints (eg. tournament calls will be sent to stub endpoints).
RiotAPI::SET_CACHE_RATELIMIT bool default false This option tells the library to take care of not exceeding your API key's rate limit by counting the requests. See [[rate limiting
RiotAPI::SET_CACHE_CALLS bool default false This option tells the library to cache fetched data from API and to try to re-use already fetched data (you should also set option RiotAPI::SET_CACHE_CALLS_LENGTH to specify for how long should fetched data be stored in cache). See [[call caching
RiotAPI::SET_CACHE_CALLS_LENGTH int|array default 60 Option to specify how log should fetched data from API be saved in cache. See [[call caching
RiotAPI::SET_CACHE_PROVIDER RiotAPI::CACHE_PROVIDER_FILE, RiotAPI::CACHE_PROVIDER_MEMCACHED, ICacheProvider Using this option you can select from our cache providers or even provide your own. See [[cache providers
RiotAPI::SET_CACHE_PROVIDER_PARAMS array These are parameters, that will be passed to the CacheProvider on it's initialization. See [[cache providers
RiotAPI::SET_EXTENSIONS array This option contains extensions for any ApiObject. See [[extensions
RiotAPI::SET_STATICDATA_LINKING bool default false Option to specify whether or not should StaticData linking be enabled. See [[StaticData linking
RiotAPI::SET_STATICDATA_LOCALE string This option sets language in which should StaticData be fetched. See [[StaticData linking
RiotAPI::SET_STATICDATA_VERSION string This option sets game version from which should StaticData be fetched. See [[StaticData linking
RiotAPI::SET_CALLBACKS_BEFORE callable|callable[] Functions set in this option will be called before request is made. See [[callback functions
RiotAPI::SET_CALLBACKS_AFTER callable|callable[] Functions set in this option will be called after request is made. See [[callback functions

Usage example

Working with RiotAPI can not be easier, just watch how to fetch summoner information based on summoner's name:

//  ...initialization...

//  this fetches the summoner data and returns SummonerDto object
$summoner = $api->getSummonerByName('I am TheKronnY');

echo $summoner->id;             //  30904166
echo $summoner->name;           //  I am TheKronnY
echo $summoner->summonerLevel;  //  30

print_r($summoner->getData());  //  Or array of all the data
/* Array
 * (
 *    [id] => 30904166
 *    [name] => I am TheKronnY
 *    [profileIconId] => 540
 *    [summonerLevel] => 30
 *    [revisionDate] => 1484850969000
 * )
 */

..or how to fetch a static champion data?

//  ...initialization...

//  this fetches the champion data and returns StaticChampionDto object
$champion = $api->getStaticChampion(61);

echo $champion->name;  //  Orianna
echo $champion->title; //  the Lady of Clockwork

print_r($champion->getData());  //  Or array of all the data
/* Array
 * (
 *    [id] => 61
 *    [name] => "Orianna"
 *    [key] => "Orianna"
 *    [title] => "the Lady of Clockwork"
 * )
 */

You can get more details about these functions in resources and endpoints section. Also, you can check out more usage examples on this page.