/** * DataRequest constructor. * @param Client $client * @param string $type * @param $region */ public function __construct($client, $type, $region) { $url = 'https://%s.api.battle.net/sc2/data/%s?locale=%s&apikey=%s'; if (in_array($type, ['achievements', 'rewards'])) { $this->url = sprintf($url, $region, $type, $client->language(), $client->apiToken()); } }
/** * ProfileRequest constructor. * @param Client $client * @param string $type * @param int $id * @param string $name * @param string $region */ public function __construct($client, $type, $id, $name, $region) { $url = 'https://%s.api.battle.net/sc2/profile/%s/1/%s/%s?locale=%s&apikey=%s'; if (in_array($type, ['ladders', 'matches'])) { $this->url = sprintf($url, $region, $id, $name, $type, $client->language(), $client->apiToken()); } else { $this->url = sprintf($url, $region, $id, $name, null, $client->language(), $client->apiToken()); } }
/** * LadderRequest constructor. * @param Client $client * @param int $id * @param string $region */ public function __construct($client, $id, $region) { $url = 'https://%s.api.battle.net/sc2/ladder/%s?locale=%s&apikey=%s'; $this->url = sprintf($url, $region, $id, $client->language(), $client->apiToken()); }
<?php /** * @author neun * @since 2015-10-26 */ require_once 'vendor/autoload.php'; use StarCraftApiClient\Client; $apiToken = file_get_contents('conf.txt'); $client = new Client($apiToken); $client->addAllProfileRequests(2778901, 'Mamba', 'eu'); $client->addAllProfileRequests(1283855, 'PuPu', 'eu'); // ... $client->run(); // Iterate over all request objects and return the JSON response ... foreach ($client->getRequests() as $id => $request) { echo $request->response(); } // Access specific request object echo $client->getRequests('profile.1283855.matches')[0]->response(); echo $client->getRequests('profile.1283855.matches')[0]->info()['http_code']; // Directly access a specific profile sub-object (profile.1283855.matches) echo $client->get('profile.1283855.matches')->matches[0]->map; // Iterate over all profile-type result objects. foreach ($client->get('profile') as $playerId => $profile) { var_dump($profile['matches']); var_dump($profile['ladders']); // ... }