11 private const SERVICE_NAME =
'google';
23 $this->client = $client;
24 if (RequestLogger::isEnabled())
26 $this->logger =
new RequestLogger($userId, self::SERVICE_NAME);
45 public function query(
string $method,
string $url, $body =
null): void
47 $this->client->query($method, $url, $body);
51 $this->logger->write([
52 'requestParams' => $body,
55 'statusCode' => $this->client->getStatus(),
56 'response' => $this->prepareResponseForDebug($this->client->getResult()),
57 'error' => $this->prepareErrorForDebug($this->client->getResult()),
67 return $this->client->getStatus();
75 return $this->client->getResult();
84 public function post(
string $url, $body =
null): void
95 public function get(
string $url, $body =
null): void
106 public function delete(
string $url, $body =
null): void
116 public function put(
string $url, $body =
null): void
125 private function prepareResponseForDebug($response): string
127 if ($this->client->getStatus() >= 300)
134 $response = \Bitrix\Main\Web\Json::decode($response);
136 catch (\Exception $e){}
138 if (!$response || !is_array($response))
145 foreach ($response as $key => $value)
147 if (is_string($value))
149 $result .=
"{$key}:{$value}; ";
151 elseif (is_array($value))
153 $result .=
"{$key}:";
154 foreach ($value as $valueKey => $valueValue)
156 $result .=
"{$valueKey}:{$valueValue}, ";
168 private function prepareErrorForDebug($response): string
172 $response = \Bitrix\Main\Web\Json::decode($response);
174 catch (\Exception $e){}
177 (!$response || !is_array($response))
178 || ($this->client->getStatus() < 400)
184 return $response[
'error'][
'code'] .
" " . $response[
'error'][
'message'] .
"; ";