getPostParams()); } $res = curl_exec($curl); curl_close($curl); $res = json_decode($res); // if ($res->http_code == '404') { // throw new Exception('User not found!', 404); // } // if ($res->http_code == '403') { // throw new Exception('Bad token!', 403); // } return $res; } public function baseRequest($path) { $this->url = 'https://api.hh.ru/' . $path; return $this; } public function addParams($params) { if ($params) { $this->params = $params; $i = 0; foreach ((array)$params as $key => $param) { $s = ($i === 0) ? '?' : '&'; $this->url .= $s . $key . '=' . $param; $i++; } } return $this; } private function getPostParams() { $params = ''; if ($this->params) { foreach ((array)$this->params as $key => $param) { $params .= $key . '=' . $param . '&'; } $params = mb_substr($params, 0, -1); } return $params; } public function get() { return $this->parseUrl($this->url); } public function post() { return $this->parseUrl($this->url, 'post'); } }