PHP-based SDK for Battlerite API
- 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
- Php 7.1 or higher
composer require ptrtn/battlerite-sdk
Retrieving data can be as simple as one method call. If no search query is specified, API defaults are used instead.
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 using API defaults
$client = \PtrTn\Battlerite\Client::create('your-api-key');
$matches = $client->getMatches();
echo $matches[0]->map->type;
// QUICK2V2
$client = \PtrTn\Battlerite\Client::create('your-api-key');
$teams = $client->getTeams(
TeamsQuery::create()
->forPlayerIds(['322'])
->forSeason(5)
);
$client = \PtrTn\Battlerite\Client::create('your-api-key');
$match = $client->getMatch('AB9C81FABFD748C8A7EC545AA6AF97CC');
$client = \PtrTn\Battlerite\Client::create('your-api-key');
$match = $client->getPlayer('934791968557563904');
A custom search query can be used to retrieve the exact data needed.
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'))
);
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.
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)
);
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
);
- 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
Documentation for the Battlerite API can be found at http://battlerite-docs.readthedocs.io/en/latest/