client = new Client(['base_uri' => self::BASE_URI]); $this->apiKey = $apiKey; } /** * @param $method * @param $uri * @param array $options * * @throws ApiException * * @return string */ public function call($method, $uri, $options = []) { $options['query']['key'] = $this->apiKey; $options['headers'] = [ 'Accept' => 'application/json', ]; try { $response = $this->client->request($method, $uri, $options); $content = $response->getBody()->getContents(); return $content; } catch (ConnectException $e) { throw new CallFailedException(ApiException::REBRICKABLE); } catch (ClientException $e) { if ($e->getCode() == 404) { throw new EmptyResponseException(ApiException::REBRICKABLE); } elseif ($e->getCode() == 401) { throw new AuthenticationFailedException(ApiException::REBRICKABLE); } throw new ApiException(ApiException::REBRICKABLE, $e, $e->getCode()); } } }