Version v1.0.0-rc.1
Welcome to the PandaScore 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 PandaScore' API.
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.
- 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.
- Objects everywhere! API calls return data in special objects.
The easiest way to get this library is to use Composer.
While having Composer installed it takes only composer require chypriote/pandascore-php
and composer install
to get the library ready to roll!
Below you can find table of implemented API resources. Endpoints without status are not planned to be implemented yet.
How to begin?
// Include all required files
require_once __DIR__ . "/vendor/autoload.php";
use PandaScoreAPI\PandaScoreAPI;
// Initialize the library
$api = new PandaScoreAPI([
// Your API key, you can get one at https://pandascore.co/settings
PandaScoreAPI::SET_TOKEN => 'YOUR_PANDASCORE_TOKEN',
// If you need to use a game specific API, you initialize it at launch
PandascoreAPI::USE_LEAGUE_OF_LEGENDS => true,
]);
// And now you are ready to rock!
$ch = $api->leagues->getLeague(61);
// Get only the datas from the games you need
$lolch = $api->lol->tournaments->listTournaments();
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.
Working with PandaScoreAPI can not be easier, just watch how to fetch a league information based on its id:
// ...initialization...
// this fetches the summoner data and returns SummonerDto object
$league = $api->getLeague(4213);
echo $league->id; // 4213
echo $league->name; // LVP SLO
echo $league->slug; // league-of-legends-lvp-slo
print_r($league->getData()); // Or array of all the data
/* Array
* (
* [id] => 4213
* [slug] => league-of-legends-lvp-slo
* [name] => LVP SLO
* )
*/
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 PandaScoreAPI::SET_CACHE_PROVIDER
to any class, thought it has to implement Objects\ICacheProvider
interface.
By using PandaScoreAPI::SET_CACHE_PROVIDER_PARAMS
option, you can pass any variables to the cache provider.
This clever feature will easily prevent exceeding your per key call limits & method limits.
In order to enable this feature, you have to set PandaScoreAPI::SET_CACHE_RATELIMIT
to true
.
Everything is completly automatic, so all you need to do is to enable this feature.
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 PandaScoreAPI::SET_CACHE_CALLS
to true
.
You should also provide PandaScoreAPI::SET_CACHE_CALLS_LENGTH
option or else default time interval of 60 seconds
will be used.
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.
Using extensions for ApiObjects is useful tool, allowing implementation of your own methods into the ApiObjects itself.
Extensions are enabled by using settings option PandaScoreAPI::SET_EXTENSIONS
when initializing the library.
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.
You can easily get API results even in CLI:
root@localhost:~/src/PandaScoreAPI# php PandaScoreAPICLI.php getLeague 61 --config ~/PandaScoreAPI_Config.json