/** * @param string $url * @param array $options * * @return array */ protected function makeRequest($url, array $options = []) { if ($this->client === null) { $this->client = new HttpClient(); $adapter = new \Zend\Http\Client\Adapter\Curl(); $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false); $this->client->setAdapter($adapter); } $key = $this->getRequestKey($url, $options); if ($this->cache->hasItem($key) === true) { return $this->cache->getItem($key); // $options = array_replace_recursive($options, [ // 'headers' => [ // 'If-Modified-Since' => $this->cache->getMetadata($key)['mtime'], // ], // ]); } $options = array_replace_recursive($options, ['headers' => ['Accept' => 'application/json', 'User-Agent' => $this->getUserAgent()], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()]]); $request = new Request(); $request->setUri($url); foreach ($options['query'] as $param => $value) { $request->getQuery()->{$param} = $value; } $request->getHeaders()->addHeaders($options['headers']); $request->setMethod(Request::METHOD_GET); try { $response = $this->client->dispatch($request); } catch (ClientException $exception) { if ($exception->getCode() === 404) { return null; } throw new BattleNetException($exception->getResponse()->json()['detail'], $exception->getCode()); } //return json_decode($response->getBody(), true); return $this->handleSuccessfulResponse($response, $key); }