dncusmir/bsapi

a client for BrawlStars api

dev-master 2020-05-18 12:50 UTC

This package is auto-updated.

Last update: 2024-04-18 21:32:27 UTC


README

CI-CD License: MIT Total Downloads Stable release

A PHP client to use BrawStars Api implementing PSR-7, PSR-17 and PSR-18.

Instalation

Prerequisites

BrawStars Api requires PHP 7.3 or greater.

Via composer:

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

Usage

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.

Usage examples

Getting a player's name:
$playerTag = "#8GVLPUGRJ";

$player = $api->getPlayerInformation($playerTag);

echo $player['name'] . PHP_EOL;
Getting a player's brawlers and their trophies
foreach ($player['brawlers'] as $brawler) {
    echo $brawler['name'] . ' ' . $brawler['trophies'] . PHP_EOL;
}

Functions

Get player information for a specific tag
public function getPlayerInformation(string $playerTag): array
Get log of recent battles for a player
public function getPlayerBattleLog(string $playerTag): array
Get club information.
public function getClubInformation(string $clubTag): array
List club members.
public function getClubMembers(string $clubTag): array
Get player rankings for a country or global rankings.
public function getPlayerRankings(string $countryCode): array
Get club rankings for a country or global rankings.
public function getClubRankings(string $countryCode): array
Get brawler rankings for a country or global rankings.
public function getBrawlerRankings(string $countryCode, string $brawlerId): array
Get list of available brawlers.
public function getBrawlers(): array
Get information about a brawler.
public function getBrawlerInformation(string $brawlerId): array

Return format

The return format for each function matches the ones on BrawlStars Api documentation.

Exceptions

All functions throw exceptions: ClientException (wrong client configuration, timeout reached etc) and ResponseException (bad api key, wrong player tag, etc).