Пример #1
0
 /**
  * @param string $url
  * @param array  $options
  *
  * @return array
  */
 protected function makeRequest($url, array $options = [])
 {
     if ($this->client === null) {
         $this->client = new GuzzleClient();
     }
     $item = null;
     if ($this->cache !== null) {
         $item = $this->cache->getItem($this->getRequestKey($url, $options));
         $data = $item->get();
         if ($item->isHit() === true) {
             $options = array_replace_recursive($options, ['headers' => ['If-Modified-Since' => $data['modified']]]);
         }
     }
     $options = array_replace_recursive($options, ['headers' => ['Accept' => 'application/json', 'Accept-Encoding' => 'gzip', 'User-Agent' => $this->getUserAgent()], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()], 'timeout' => 60]);
     try {
         $response = $this->client->get($url, $options);
     } catch (ClientException $exception) {
         switch ($exception->getCode()) {
             case 404:
                 return;
             default:
                 $data = json_decode($exception->getResponse()->getBody(), true);
                 throw new BattleNetException($data['detail'], $exception->getCode());
         }
     }
     return $this->handleSuccessfulResponse($response, $item);
 }
Пример #2
0
 /**
  * @param string $url
  * @param array  $options
  *
  * @return array
  */
 protected function makeRequest($url, array $options = [])
 {
     if ($this->client === null) {
         $this->client = new GuzzleClient();
     }
     $item = $this->cache->getItem($this->getRequestKey($url, $options));
     $data = $item->get();
     if ($item->isMiss() === false) {
         $options = array_replace_recursive($options, ['headers' => ['If-Modified-Since' => $data['modified']]]);
     }
     $options = array_replace_recursive($options, ['headers' => ['Accept' => 'application/json', 'User-Agent' => $this->getUserAgent()], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()]]);
     try {
         $response = $this->client->get($url, $options);
     } catch (ClientException $exception) {
         if ($exception->getCode() === 404) {
             return null;
         }
         throw new BattleNetException($exception->getResponse()->json()['detail'], $exception->getCode());
     }
     return $this->handleSuccessfulResponse($response, $item, $data);
 }