-
-
Notifications
You must be signed in to change notification settings - Fork 25
LeagueAPI: How to begin
Daniel Dolejška edited this page Dec 13, 2018
·
10 revisions
Version v3.0.0-rc.1
How to begin? It's easy.
// Include all required files
require_once __DIR__ . "/vendor/autoload.php";
use RiotAPI\LeagueAPI\LeagueAPI;
use RiotAPI\LeagueAPI\Definitions\Region;
// Initialize the library
$api = new LeagueAPI([
// Your API key, you can get one at https://developer.riotgames.com
LeagueAPI::SET_KEY => 'YOUR_RIOT_API_KEY',
// Target region (you can change it during lifetime of the library instance)
LeagueAPI::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 |
---|---|---|
LeagueAPI::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. |
LeagueAPI::SET_KEY |
string |
Required. Option to specify your API key. |
LeagueAPI::SET_TOURNAMENT_KEY |
string |
Option to specify your tournament API key. |
LeagueAPI::SET_VERIFY_SSL |
bool default true
|
Use this option to disable SSL verification. Useful when testing on localhost. Shoul not be used in production. |
LeagueAPI::SET_KEY_INCLUDE_TYPE |
LeagueAPI::KEY_AS_QUERY_PARAM , LeagueAPI::KEY_AS_HEADER
|
This option determines how is API key going to be included in the requests (by default LeagueAPI::KEY_AS_HEADER ). |
LeagueAPI::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). |
LeagueAPI::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 |
LeagueAPI::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 LeagueAPI::SET_CACHE_CALLS_LENGTH to specify for how long should fetched data be stored in cache). See [[call caching |
LeagueAPI::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 |
LeagueAPI::SET_CACHE_PROVIDER |
LeagueAPI::CACHE_PROVIDER_FILE , LeagueAPI::CACHE_PROVIDER_MEMCACHED , ICacheProvider
|
Using this option you can select from our cache providers or even provide your own. See [[cache providers |
LeagueAPI::SET_CACHE_PROVIDER_PARAMS |
array |
These are parameters, that will be passed to the CacheProvider on it's initialization. See [[cache providers |
LeagueAPI::SET_EXTENSIONS |
array |
This option contains extensions for any ApiObject. See [[extensions |
LeagueAPI::SET_DATADRAGON_INIT |
bool default false
|
Option to specify whether or not should library initialize DataDragonAPI itself. Initialized DataDragonAPI is required for StaticData calls. |
LeagueAPI::SET_DATADRAGON_PARAMS |
array default []
|
This option specifies parameters passed to DataDragonAPI when initialized by LeagueAPI (happens when LeagueAPI::SET_DATADRAGON_INIT is true ). |
LeagueAPI::SET_STATICDATA_LINKING |
bool default false
|
Option to specify whether or not should StaticData linking be enabled. See [[StaticData linking |
LeagueAPI::SET_STATICDATA_LOCALE |
string |
This option sets language in which should StaticData be fetched. See [[StaticData linking |
LeagueAPI::SET_STATICDATA_VERSION |
string |
This option sets game version from which should StaticData be fetched. See [[StaticData linking |
LeagueAPI::SET_CALLBACKS_BEFORE |
callable |callable[]
|
Functions set in this option will be called before request is made. See [[callback functions |
LeagueAPI::SET_CALLBACKS_AFTER |
callable |callable[]
|
Functions set in this option will be called after request is made. See [[callback functions |
Working with LeagueAPI 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.