function __construct($params) { if (!isset($params['questId'])) { throw new BattleNetAPI_Exception('The "/wow/quest/" endpoint requires the parameter "questId".'); } $this->url = BattleNetAPI::getHost() . '/wow/quest/' . $params['questId']; }
function __construct($params) { if (!isset($params['realm'])) { throw new BattleNetAPI_Exception('The "/wow/auction/data/" endpoint requires the parameter "realm".'); } $this->url = BattleNetAPI::getHost() . '/wow/auction/data/' . rawurlencode($params['realm']); }
function __construct($params) { if (isset($params['zoneId'])) { $this->url = BattleNetAPI::getHost() . '/wow/zone/' . $params['zoneId']; } else { $this->url = BattleNetAPI::getHost() . '/wow/zone/'; } }
function __construct($params) { if (!isset($params['bracket'])) { throw new BattleNetAPI_Exception('The "/wow/leaderboard/" endpoint requires the parameter "bracket".'); } $validBrackets = array('2v2', '3v3', '5v5', 'rbg'); if (!in_array($params['bracket'], $validBrackets)) { throw new BattleNetAPI_Exception('The "/wow/leaderboard/" endpoint requires the parameter "bracket" be one of the following: "' . implode('", "', $validBrackets) . '".'); } $this->url = BattleNetAPI::getHost() . '/wow/leaderboard/' . $params['bracket']; }
function __construct($params) { if (!isset($params['itemId'])) { throw new BattleNetAPI_Exception('The "/wow/item/" endpoint requires the parameter "itemId".'); } if (isset($params['context'])) { $this->url = BattleNetAPI::getHost() . '/wow/item/' . $params['itemId'] . '/' . $params['context']; } else { $this->url = BattleNetAPI::getHost() . '/wow/item/' . $params['itemId']; } }
function __construct($params) { if (isset($params['realms'])) { if (is_array($params['realms'])) { $params['realms'] = implode(',', $params['realms']); } $this->url = BattleNetAPI::getHost() . '/wow/realm/status?realms=' . $params['realms']; } else { $this->url = BattleNetAPI::getHost() . '/wow/realm/status'; } }
function __construct($params) { if (!isset($params['realm'], $params['characterName'])) { throw new BattleNetAPI_Exception('The "/wow/character/" endpoint requires the parameters "realm" and "characterName".'); } $url = BattleNetAPI::getHost() . '/wow/character/' . rawurlencode($params['realm']) . '/' . rawurlencode($params['characterName']); $validFields = array('achievements', 'appearance', 'audit', 'feed', 'guild', 'hunterPets', 'items', 'mounts', 'pets', 'petSlots', 'progression', 'pvp', 'quests', 'reputation', 'statistics', 'stats', 'talents', 'titles'); if (isset($params['fields'])) { if (is_string($params['fields'])) { $params['fields'] = explode(',', $params['fields']); } $params['fields'] = array_intersect($params['fields'], $validFields); $url .= '?fields=' . implode(',', $params['fields']); } $this->url = $url; }
function __construct($params) { if (!isset($params['realm'], $params['guildName'])) { throw new BattleNetAPI_Exception('The "/wow/guild/" endpoint requires the parameters "realm" and "guildName".'); } $url = BattleNetAPI::getHost() . '/wow/guild/' . rawurlencode($params['realm']) . '/' . rawurlencode($params['guildName']); $validFields = array('members', 'achievements', 'news', 'challenge'); if (isset($params['fields'])) { if (is_string($params['fields'])) { $params['fields'] = explode(',', $params['fields']); } $params['fields'] = array_intersect($params['fields'], $validFields); $url .= '?fields=' . implode(',', $params['fields']); } $this->url = $url; }
function __construct($params) { if (!isset($params['speciesId'])) { throw new BattleNetAPI_Exception('The "/wow/pet/stats/" endpoint requires the parameter "speciesId".'); } $queryParams = array(); $queryString = ''; if (isset($params['level'])) { $queryParams['level'] = $params['level']; } if (isset($params['breedId'])) { $queryParams['breedId'] = $params['breedId']; } if (isset($params['qualityId'])) { $queryParams['qualityId'] = $params['qualityId']; } if (!empty($queryParams)) { $queryString = '?' . http_build_query($queryParams); } $this->url = BattleNetAPI::getHost() . '/wow/pet/stats/' . $params['speciesId'] . $queryString; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/mount/'; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/challenge/region'; }
/** * Uses cURL multi to simultaneously process our requests and run our * callback function after each request has completed. */ private static function processRequests() { if (self::$totalRequests > self::$curlOptions[CURLOPT_MAXCONNECTS]) { $maxConnections = self::$curlOptions[CURLOPT_MAXCONNECTS]; } else { $maxConnections = self::$totalRequests; } $multiHandler = curl_multi_init(); $options = self::$curlOptions; $now = time(); $secondSleep = FALSE; $hourSleep = FALSE; $isThrottledPerSecond = self::isThrottledPerSecond(); $isThrottledPerHour = self::isThrottledPerHour(); for ($i = 0; $i < $maxConnections; $i++) { $requestHandle = curl_init(); $requestUrl = self::formatRequestUrl(self::$requests[$i]->getUrl()); $options[CURLOPT_URL] = $requestUrl; self::$totalRequestsThisSecond++; self::$totalRequestsThisHour++; curl_setopt_array($requestHandle, $options); curl_multi_add_handle($multiHandler, $requestHandle); } do { while (($haveRequests = curl_multi_exec($multiHandler, $running)) == CURLM_CALL_MULTI_PERFORM) { } if ($haveRequests != CURLM_OK) { break; } while ($theRequest = curl_multi_info_read($multiHandler)) { $requestInfo = curl_getinfo($theRequest['handle']); $response = curl_multi_getcontent($theRequest['handle']); if (self::haveCallback()) { call_user_func_array(self::getCallback(), array($requestInfo['url'], $response, $requestInfo, $theRequest['handle'])); } if ($i < self::$totalRequests) { if ($isThrottledPerSecond) { if ($secondSleep) { $secondSleep = FALSE; sleep(1); $now = time(); self::$totalRequestsThisSecond = 0; } if (time() > $now) { $now = time(); self::$totalRequestsThisSecond = 0; } if (self::$totalRequestsThisSecond == self::$maxRequestsPerSecond) { $secondSleep = TRUE; self::$totalRequestsThisSecond = 0; } self::$totalRequestsThisSecond++; } if ($isThrottledPerHour) { if ($hourSleep) { $hourSleep = FALSE; sleep(3600); $now = time(); self::$totalRequestsThisHour = 0; } if (self::$totalRequestsThisHour == self::$maxRequestsPerHour) { $hourSleep = TRUE; self::$totalRequestsThisHour = 0; } self::$totalRequestsThisHour++; } $requestHandle = curl_init(); $options[CURLOPT_URL] = self::formatRequestUrl(self::$requests[$i++]->getUrl()); curl_setopt_array($requestHandle, $options); curl_multi_add_handle($multiHandler, $requestHandle); } curl_multi_remove_handle($multiHandler, $theRequest['handle']); } } while ($running); curl_multi_close($multiHandler); }
BattleNetAPI::setThrottlePerSecond(80); /** * Throttle the number of requests that can be made in a single hour. If the * number specified below is reached, the server will sleep for one hour and * reset the counter. * * !!!! IT IS NOT RECOMMENDED TO USE THROTTLING IN A PRODUCTION ENVIRONMENT !!!! * * Note that this does NOT limit the exact number of requests that are sent, as * there is no method of determining when cURL actually sent the request. It can * only be handled on the receiving end, once a request has given us a response * back. This number is only to better tune the number of requests that are * processed per hour and not necessarily how many requests are sent. * * The throttle per hour setting is only useful for internal applications, such * as when making several thousand requests consecutively to build an item * database. Without a database or some other form of logging for multiple users * it's not possible to keep count of how many requests were made in the past * hour. * Default: 35000 */ //BattlenetAPI::setThrottlePerHour( 35000 ); /** * Add all your Battle.net API requests. */ BattleNetAPI::addRequest('wow', 'item', array('itemId' => 19019)); /** * Send the requests. */ BattleNetAPI::send();
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/data/battlegroups/'; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/data/guild/perks'; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/data/character/achievements'; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/data/talents'; }
function __construct($params) { $this->url = BattleNetAPI::getHost() . '/wow/data/item/classes'; }