Пример #1
0
 /**
  * @param string $url
  * @param array  $queryParameters
  * @param bool   $global
  * @param bool   $status
  *
  * @return BaseApi
  * @throws \LoLApi\Exception\AbstractRateLimitException
  */
 protected function callApiUrl($url, array $queryParameters = [], $global = false, $status = false)
 {
     $baseUrl = $global ? $this->apiClient->getGlobalUrl() : ($status ? $this->apiClient->getStatusUrl() : '');
     $url = $baseUrl . str_replace('{region}', $this->apiClient->getRegion(), $url);
     $queryParameters = array_merge(['api_key' => $this->apiClient->getApiKey()], $queryParameters);
     $fullUrl = $this->buildUri($url, $queryParameters);
     if ($this->apiClient->getCacheProvider()->contains($fullUrl)) {
         return $this->buildApiResult($fullUrl, json_decode($this->apiClient->getCacheProvider()->fetch($fullUrl), true), true);
     }
     try {
         $response = $this->apiClient->getHttpClient()->get($url, ['query' => $queryParameters]);
         return $this->buildApiResult($fullUrl, json_decode((string) $response->getBody(), true), false, $response);
     } catch (ClientException $e) {
         throw (new ClientExceptionHandler())->handleClientException($e);
     }
 }
Пример #2
0
 /**
  * @covers LoLApi\ApiClient::getRegion
  * @covers LoLApi\ApiClient::getApiKey
  * @covers LoLApi\ApiClient::getHttpClient
  * @covers LoLApi\ApiClient::getGlobalUrl
  * @covers LoLApi\ApiClient::getStatusUrl
  */
 public function testOtherGetters()
 {
     $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test');
     $this->assertEquals(self::REGION, $apiClient->getRegion());
     $this->assertEquals(self::API_KEY, $apiClient->getApiKey());
     $this->assertInstanceOf('GuzzleHttp\\Client', $apiClient->getHttpClient());
     $this->assertSame('https://global.api.pvp.net', $apiClient->getGlobalUrl());
     $this->assertSame('http://status.leagueoflegends.com', $apiClient->getStatusUrl());
 }