codenametim/riot-api
Composer 安装命令:
composer require codenametim/riot-api
包简介
Riot League of Legends & DataDragon API wrapper for PHP7. Reference to Daniel Dolejska (just a fork)
README 文档
README
Version v3.0.0-rc.1
RiotAPI v3 CHANGES WARNING!
Update v3.0.0-rc.1 came with big changes to the library!
If you've been using this library and just updated - READ THIS.
OLD DEPRECATED USAGE:
use RiotAPI\RiotAPI;
use RiotAPI\Exceptions\GeneralException;
use RiotAPI\Objects\ChampionInfo;
try
{
$api = new RiotAPI([...]);
}
catch (GeneralException $e)
{
// ...
}
use DataDragonAPI\DataDragonAPI;
use DataDragonAPI\Exception\GeneralException;
use DataDragonAPI\Definition\Map;
DataDragonAPI::initByCdn([...]);
// ...
NEW USAGE:
Main API class RiotAPI has been renamed to LeagueAPI and has been moved to RiotAPI\LeagueAPI namespace.
Also all related objects (Objects, Definitions, ...) has been moved to RiotAPI\LeagueAPI (RiotAPI\LeagueAPI\Objects, RiotAPI\LeagueAPI\Definitions respectively...).
use RiotAPI\LeagueAPI\LeagueAPI;
use RiotAPI\LeagueAPI\Exceptions\GeneralException;
use RiotAPI\LeagueAPI\Objects\ChampionInfo;
try
{
$api = new LeagueAPI([...]);
}
catch (GeneralException $e)
{
// ...
}
DataDragonAPI class has been moved to RiotAPI\DataDragonAPI namespace.
Also all related objects (Definition and Exception) has been moved to RiotAPI\DataDragonAPI (RiotAPI\DataDragonAPI\Definitions and RiotAPI\DataDragonAPI\Exceptions respectively...).
use RiotAPI\DataDragonAPI\DataDragonAPI;
use RiotAPI\DataDragonAPI\Exceptions\GeneralException;
use RiotAPI\DataDragonAPI\Definitions\Map;
DataDragonAPI::initByCdn([...]);
// ...
Table of Contents
Introduction
Welcome to the RiotAPI PHP7 library repo! The goal of this library is to create easy-to-use library for anyone who might need one. This is fully object oriented API wrapper for League of Legends' API. A small DataDragon API is also included.
Here are some handy features:
- Rate limit caching and limit exceeding prevention - fully automatic.
- Call caching - this enables the library to re-use already fetched data within short timespan - saving time and API rate limit.
- StaticData endpoints - you can work with StaticData endpoints as if they were never deprecated.
- StaticData linking - library can automatically link StaticData related to your request right into the returned object.
- Custom callbacks - you can set custom function which will be called before or after the request is processed.
- Object extensions - you can implement own methods to the fetched API objects itself and enable yourself to use them later to ease of your work.
- CLI supported! You can use the library easily even in PHP CLI mode.
- Interim mode support, you are going to be able to use the API the same way whether your key is in
interim modeor not (meaning you won't need to change anything when you jump to production). - Objects everywhere! API calls return data in special objects.
Please, refer mainly to the wiki pages.
Downloading
The easiest way to get this library is to use Composer.
While having Composer installed it takes only composer require dolejska-daniel/riot-api and composer install to get the library ready to roll!
League of Legends API
Resource versions
Below you can find table of implemented API resources and the version in which they are currently implemented. Please refer to wiki pages for more information about endpoints and resources.
| Resource | Status |
|---|---|
| Champion | |
| Champion Mastery | |
| League | |
| Masteries | |
| Match | |
| Runes | |
| Spectator | |
| Static Data | |
| Stats | |
| Status | |
| Summoner | |
| Third Party Code | |
| Tournament | |
| Tournament Stub |
Initializing the library
How to begin?
// 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 - mainly to enable special features or to amend behaviour of the library. Please see the wiki pages for complete list of library's settings.
Usage example
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; // KnNZNuEVZ5rZry3I...
echo $summoner->puuid; // rNmb6Rq8CQUqOHzM...
echo $summoner->name; // I am TheKronnY
echo $summoner->summonerLevel; // 69
print_r($summoner->getData()); // Or array of all the data
/* Array
* (
* [id] => KnNZNuEVZ5rZry3IyWwYSVuikRe0y3qTWSkr1wxcmV5CLJ8
* [accountId] => tGSPHbasiCOgRM_MuovMKfXw7oh6pfXmGiPDnXcxJDohrQ
* [puuid] => rNmb6Rq8CQUqOHzMsFihMCUy4Pd201vDaRW9djAoJ9se7myXrDprvng9neCanq7yGNmz7B3Wri4Elw
* [name] => I am TheKronnY
* [profileIconId] => 3180
* [revisionDate] => 1543438015000
* [summonerLevel] => 69
* )
*/
..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"
* )
*/
Cache providers
Cache providers are responsible for keeping data of rate limiting and call caching within instances of the library. This feature is automatically enabled, when any of previously mentioned features is used.
When using this feature, you can set LeagueAPI::SET_CACHE_PROVIDER to any class, thought it has to implement Objects\ICacheProvider interface.
By using LeagueAPI::SET_CACHE_PROVIDER_PARAMS option, you can pass any variables to the cache provider.
For more, please see the wiki pages.
Rate limiting
This clever feature will easily prevent exceeding your per key call limits & method limits.
In order to enable this feature, you have to set LeagueAPI::SET_CACHE_RATELIMIT to true.
Everything is completly automatic, so all you need to do is to enable this feature.
For more, please see the wiki pages.
Call caching
This feature can prevent unnecessary calls to API within short timespan by temporarily saving fetched data from API and using them as the result data.
In order to enable this feature, you have to set LeagueAPI::SET_CACHE_CALLS to true.
You should also provide LeagueAPI::SET_CACHE_CALLS_LENGTH option or else default time interval of 60 seconds will be used.
For more, please see the wiki pages.
Asynchronous requests
This feature allows request grouping and their asynchronous sending using Guzzle. After request is sent and its response received, user provided callbacks are invoked with received data.
For more, please see the wiki pages.
StaticData endpoints
These endpoints provide you with easy way to transform StaticData into object instances and easily work with them. They are also supported in numerous DataDragonAPI functions (displaying images).
For more, please see the wiki pages.
StaticData linking
This feature allows you to automatically link StaticData related to your request.
This action is time consuming (works well when caching call data for StaticData resource), but calls to fetch StaticData are not counted to your API key's rate limit.
For more, please see the wiki pages.
Extensions
Using extensions for ApiObjects is useful tool, allowing implementation of your own methods into the ApiObjects itself.
Extensions are enabled by using settings option LeagueAPI::SET_EXTENSIONS when initializing the library.
For more, please see the wiki pages.
Callback functions
Allows you to provide custom functions to be called before and after the actual API request is sent.
Before callbacks have ability to cancel upcomming request - when false is returned by any callback function, exception Exceptions\RequestException is raised and request is cancelled.
For more, please see the wiki pages.
CLI support.
You can easily get API results even in CLI:
root@localhost:~/src/LeagueAPI# php7.0 LeagueAPICLI.php getChampion 61 --config ~/LeagueAPI_Config.json
For more information about CLI support, please see the wiki pages.
DataDragon API
How easy is it to work with static images? For instance, to get loading screen art of Orianna?
Source:
echo DataDragonAPI::getChampionLoading('Orianna');
echo DataDragonAPI::getChampionLoading('Orianna', 7);
Output:
<img alt="Orianna" class="dd-icon dd-loading" src="http://ddragon.leagueoflegends.com/cdn/img/champion/loading/Orianna_0.jpg">
<img alt="Orianna" class="dd-icon dd-loading" src="http://ddragon.leagueoflegends.com/cdn/img/champion/loading/Orianna_7.jpg">
Render:

...a bit of nostalgia?
Source:
DataDragonAPI::iniByVersion('0.151.2');
echo DataDragonAPI::getItemIcon(3132);
echo DataDragonAPI::getItemIcon(3126);
echo DataDragonAPI::getItemIcon(3138);
Output:
<img alt="3132" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3132.png">
<img alt="3126" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3126.png">
<img alt="3138" class="dd-icon dd-item" src="http://ddragon.leagueoflegends.com/cdn/0.151.2/img/item/3138.png">
Render:

...or to display icon of champion and its spells based on its object from API?
Source:
// ...
$orianna = $api->getStaticChampion(61, true);
echo DataDragonAPI::getChampionSplashO($orianna);
foreach($orianna->spells as $spell)
echo DataDragonAPI::getChampionSpellIconO($spell);
Output:
<img alt="Orianna" class="dd-icon dd-icon-champ" src="https://ddragon.leagueoflegends.com/cdn/8.24.1/img/champion/Orianna.png">
<img alt="OrianaIzunaCommand" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaIzunaCommand.png">
<img alt="OrianaDissonanceCommand" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaDissonanceCommand.png">
<img alt="OrianaRedactCommand" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaRedactCommand.png">
<img alt="OrianaDetonateCommand" class="dd-icon dd-spell" src="http://ddragon.leagueoflegends.com/cdn/8.24.1/img/spell/OrianaDetonateCommand.png">
Render:

For more, please see the wiki pages.
codenametim/riot-api 适用场景与选型建议
codenametim/riot-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「wrapper」 「league of legends」 「Riot」 「PHP7」 「data dragon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codenametim/riot-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codenametim/riot-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codenametim/riot-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An attribute based container for league/container
Handle the output of complex data structures ready for API output.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A fast and intuitive dependency injection container.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-05-09