• Модуль: seo
  • Путь к файлу: ~/bitrix/modules/seo/lib/engine/yandexdirect.php
  • Класс: BitrixSeoEngineYandexDirect
  • Вызов: YandexDirect::query
protected function query($scope, $method = "GET", $param = NULL, $skipRefreshAuth = false)
{
	if ($param === NULL)
	{
		$param = array();
	}
	
	if ($this->engineSettings['AUTH'])
	{
		$http = new HttpClient();
		$http->setRedirect(false);
		$http->setHeader("Content-Type", "application/json; charset=utf-8");
		
		$postData = array(
			"method" => $method,
			"locale" => $this->locale,
			"token" => $this->engineSettings['AUTH']['access_token'],
		);
		
		if (!empty($param))
		{
			$postData["param"] = $param;
		}
		
		$postData = YandexJson::encode($postData, JSON_UNESCAPED_UNICODE);
		
		$ts = microtime(true);
		$http->post(static::API_URL, $postData);
		
		LogTable::add(array(
			'ENGINE_ID' => $this->getId(),
			'REQUEST_URI' => static::API_URL,
			'REQUEST_DATA' => TextEncoding::convertEncoding($postData, 'UTF-8', SITE_CHARSET),
			'RESPONSE_TIME' => microtime(true) - $ts,
			'RESPONSE_STATUS' => $http->getStatus(),
			'RESPONSE_DATA' => TextEncoding::convertEncoding($http->getResult(), 'UTF-8', SITE_CHARSET),
		));
		
		if ($http->getStatus() == 401 && !$skipRefreshAuth)
		{
			if ($this->checkAuthExpired())
			{
				$this->query($scope, $method, $param, true);
			}
		}
		
		return $http;
	}
	else
	{
		throw new SystemException("No Yandex auth data");
	}
}