36 if ($this->apiKey ===
'')
44 $url = $this->apiEndpoint . $method;
48 'socketTimeout' => $this->socketTimeout,
49 'streamTimeout' => $this->streamTimeout,
50 'waitResponse' => static::WAIT_RESPONSE,
53 $httpClient->setHeader(
'User-Agent', static::USER_AGENT);
54 $httpClient->setHeader(
'Content-type', static::CONTENT_TYPE);
55 $httpClient->setHeader(
'X-API-KEY', $this->apiKey);
56 $httpClient->setCharset(static::CHARSET);
63 $queryMethod = $httpMethod ?: $queryMethod;
72 $url .=
'?' . http_build_query($requestParams);
76 $result->setHttpRequest(
new Request([
77 'method' => $queryMethod,
79 'headers' => method_exists($httpClient,
'getRequestHeaders') ? $httpClient->getRequestHeaders()->toArray() : [],
80 'body' => $requestParams,
83 if ($httpClient->query($queryMethod, $url, $requestParams))
89 $result->setHttpResponse(
new Response([
90 'error' => Util::getHttpClientErrorString($httpClient)
92 $error = $httpClient->getError();
93 $response = [
'code' => current($error)];
96 $result->setHttpResponse(
new Response([
97 'statusCode' => $httpClient->getStatus(),
98 'headers' => $httpClient->getHeaders()->toArray(),
99 'body' => $httpClient->getResult(),
106 if (isset($response[
'title']))
108 $errorMessage = $response[
'title'];
111 if (isset($response[
'code']))
116 if (isset($response[
'detail']))
118 $errorMessage = $response[
'detail'];
121 $result->addError(
new Error($errorMessage));
125 $result->setData($response);