41 public function __construct($url =
'', $user_id =
'', $token =
'') {
43 if (!empty($user_id)) {
44 $this->
start($user_id, $token);
55 public function start($user_id, $token) {
56 return $this->
post(
'startSession', array($user_id, $token));
65 if (!empty($this->session)) {
66 $this->
post(
'closeSession');
78 public function get($path =
'', $params = array()) {
79 return $this->send($path, $params,
'GET');
90 public function put($path =
'', $params = array()) {
91 return $this->send($path, $params,
'PUT');
102 public function post($path =
'', $params = array()) {
103 return $this->send($path, $params,
'POST');
114 public function delete($path =
'', $params = array()) {
115 return $this->send($path, $params,
'DELETE');
127 private function send($path =
'', $params = array(), $method =
'GET') {
128 $url = $this->url.$path;
133 curl_setopt($ch, CURLOPT_HTTPGET,
true);
134 if (!empty($params)) {
135 $url .= (strpos($url,
'?') !==
false ?
'&' :
'?').http_build_query($params);
139 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'PUT');
140 if (!empty($params[
'params'][
'@file'])) {
142 curl_setopt($ch, CURLOPT_INFILE, $params[
'params'][
'@file']);
143 curl_setopt($ch, CURLOPT_INFILESIZE, filesize($params[
'params'][
'@file']));
144 unset($params[
'params'][
'@file']);
146 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
149 curl_setopt($ch, CURLOPT_POST,
true);
150 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
153 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'DELETE');
154 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
158 if (!empty($this->session)) {
159 curl_setopt($ch, CURLOPT_COOKIE, EGOTEC.
"={$this->session}");
162 curl_setopt($ch, CURLOPT_URL, $url);
163 curl_setopt($ch, CURLOPT_HEADER,
true);
164 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
165 curl_setopt($ch, CURLOPT_TIMEOUT, self::TIMEOUT);
167 if (!empty($GLOBALS[
'egotec_conf'][
'proxy'])) {
168 curl_setopt($ch, CURLOPT_PROXY, $GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_host']);
169 curl_setopt($ch, CURLOPT_PROXYPORT, $GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_port']);
170 if (!empty($GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_ssl'])) {
171 curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL,
true);
173 if (!empty($GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_login'])) {
174 curl_setopt($ch, CURLOPT_PROXYAUTH, implode(
':', array(
175 $GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_login'],
176 (
string) $GLOBALS[
'egotec_conf'][
'proxy'][
'proxy_password']
181 $result = curl_exec($ch);
183 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
184 $header = substr($result, 0, $header_size);
185 $result = substr($result, $header_size);
188 if (!empty($header) && preg_match(
'/Set-Cookie: ?'.preg_quote(EGOTEC,
'/').
'=(.*?);/msi', $header, $match)) {
189 $this->session = $match[1];
193 return json_decode($result,
true);
__construct($url='', $user_id='', $token='')
put($path='', $params=array())
post($path='', $params=array())