A PHP client to use BrawStars Api implementing PSR-7, PSR-17 and PSR-18.
BrawStars Api requires PHP 7.3 or greater.
composer require dncusmir/bsapi
It also needs actual implementation for PSR-7 and PSR-18. For example Guzzle 6 HTTP Adapter for the http client and laminas-diactoros for the http factory.
composer require php-http/guzzle6-adapter
composer require laminas/laminas-diactoros
First make sure to get your api key at (https://developer.brawlstars.com). Using the client and factory from before:
use Dncusmir\BsApi\BsApi;
use Laminas\Diactoros\RequestFactory;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
// get your client and factory: can use any compatible psr-7 / psr-17 packages
$config = [
'timeout' => 25,
];
$httpClient = GuzzleAdapter::createWithConfig($config);
$httpRequestFactory = new RequestFactory();
// create your api object to use for api calls
$apiKey = 'your api key';
$api = new BsApi($apiKey, $httpClient, $httpRequestFactory);
Now you can make api calls to the BrawStars Api.
$playerTag = "#8GVLPUGRJ";
$player = $api->getPlayerInformation($playerTag);
echo $player['name'] . PHP_EOL;
foreach ($player['brawlers'] as $brawler) {
echo $brawler['name'] . ' ' . $brawler['trophies'] . PHP_EOL;
}
public function getPlayerInformation(string $playerTag): array
public function getPlayerBattleLog(string $playerTag): array
public function getClubInformation(string $clubTag): array
public function getClubMembers(string $clubTag): array
public function getPlayerRankings(string $countryCode): array
public function getClubRankings(string $countryCode): array
public function getBrawlerRankings(string $countryCode, string $brawlerId): array
public function getBrawlers(): array
public function getBrawlerInformation(string $brawlerId): array
The return format for each function matches the ones on BrawlStars Api documentation.
All functions throw exceptions: ClientException
(wrong client configuration, timeout reached etc) and ResponseException
(bad api key, wrong player tag, etc).