ptrtn / battlerite
A php-based client wrapping the battlerite API
Requires
- doctrine/cache: ^1.7
- guzzlehttp/guzzle: ^6.2
- webmozart/assert: ^1.2
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2025-05-11 07:52:51 UTC
README
PHP-based SDK for Battlerite API
Features
- Retrieve data for matches (by query)
- Retrieve detailed data for a specific match
- Retrieve data for players (by query)
- Retrieve detailed data for a specific player
- Retrieve team data for specific players and seasons
- Retrieve api status
Requirements
- Php 7.1 or higher
Installing
composer require ptrtn/battlerite-sdk
Usage
Retrieving data can be as simple as one method call. If no search query is specified, API defaults are used instead.
Api status
The following example returns API status, patch version and other data
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $status = $client->getStatus();
Retrieving match data
Retrieving match data using API defaults
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $matches = $client->getMatches(); echo $matches[0]->map->type; // QUICK2V2
Retrieving team data
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $teams = $client->getTeams( TeamsQuery::create() ->forPlayerIds(['322']) ->forSeason(5) );
Retrieving detailed match data
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $match = $client->getMatch('AB9C81FABFD748C8A7EC545AA6AF97CC');
Retrieving detailed player data
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $match = $client->getPlayer('934791968557563904');
Custom querying
A custom search query can be used to retrieve the exact data needed.
Matches
For matches the following query options are available:
- Offset
- Limit
- Start date
- End date
- Player ids
- Team names
- Game modes
- Ascending sorting
- Descending sorting
$client = \PtrTn\Battlerite\Client::create('your-api-key'); // Retrieve matches for a specific player for the last 24 hours $matches = $client->getMatches( MatchesQuery::create() ->forPlayerIds(['934791968557563904']) ->withStartDate(new DateTime('-1 day')) );
Players
For players the following query options are available:
- Player name
- Steam id
- Player id
$client = \PtrTn\Battlerite\Client::create('your-api-key'); // Retrieve a list of players for a specific player name $players = $client->getPlayers( PlayersQuery::create() ->forPlayerNames(['PlakkeStrasser']) );
Note: up to 6 players (1 per region) can be found for a specific player name.
Teams
For teams the following query options are available:
- Season
- Player id
$client = \PtrTn\Battlerite\Client::create('your-api-key'); $teams = $client->getTeams( TeamsQuery::create() ->forPlayerIds(['322']) ->forSeason(5) );
Caching
When sending a lot of requests, the default rate limit of 10 requests per minute will pose an issue. In order to prevent this, caching can be enabled for the player details and match details endpoints.
// Create client using default filesystem cache $client = ClientWithCache::create('your-api-key');
Optionally an alternative cache lifetime or caching system implementing the Doctrine\Common\Cache\Cache
interface can be configured.
// Create a client using custom configured cache $client = ClientWithCache::createWithCache( 'your-api-key', new RedisCache(), 300 );
How do I get an API key?
- In order to get an API key you should create a developer account and an app
- Once created, log in and browse to https://developer.battlerite.com/apps/your-app
- Scroll down to DEVELOPMENT API KEY THIS APP USES, it should look like:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9G9lIiwiYWRtaW4iOnRydWV9G9lIi.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
Api documentation
Documentation for the Battlerite API can be found at http://battlerite-docs.readthedocs.io/en/latest/