/** * function config to make request * * @param $params * @param $function * @param $type (only allow get post put delete head and options) * @return bool */ public function makeRequest($function, $params = [], $type = 'post') { if (!in_array($type, ['get', 'post', 'put', 'delete', 'head', 'options'])) { return false; } $url = $this->_baseApiUrl . $function; $this->_client = Client::$type($url); $header = ['Content-Type' => 'application/json']; $baseParams = ['ApiKey' => $this->_key, 'ApiSecretKey' => $this->_secretKey, 'ClientID' => $this->_clientId, 'Password' => $this->_password]; $configParam = array_merge($baseParams, $params); return $this->_client->addHeaders($header)->body(json_encode($configParam))->send(); }
/** * Установка заголовков для корректной работы с Rutube * @param string $token * @return mixed */ public function setHeaders($token = null) { $headers = array('Accept' => 'application/json', 'User-Agent' => 'Rutube_PHPClient'); if ($token !== null) { $headers['Authorization'] = 'Token ' . $token; } $this->request->addHeaders($headers); return $this; }