public function call($url, $method, $postFields = null, $username = null, $password = null, $contentType = null)
{
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0 && !empty($this->format)) {
$url = "{$this->api_url}{$url}.{$this->format}";
}
$this->http_url = $url;
$this->contentType = $contentType;
$this->postFields = $postFields;
$url = in_array($method, self::$paramsOnUrlMethod) ? $this->to_url() : $this->get_http_url();
is_object($this->ch) or $this->__construct();
switch ($method) {
case 'POST':
curl_setopt($this->ch, CURLOPT_POST, true);
if ($this->postFields != null) {
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->postFields);
}
break;
case 'DELETE':
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
case 'PUT':
curl_setopt($this->ch, CURLOPT_PUT, true);
if ($this->postFields != null) {
$this->file = tmpFile();
fwrite($this->file, $this->postFields);
fseek($this->file, 0);
curl_setopt($this->ch, CURLOPT_INFILE, $this->file);
curl_setopt($this->ch, CURLOPT_INFILESIZE, strlen($this->postFields));
}
break;
}
$this->setAuthorizeInfo($username, $password);
$this->contentType != null && curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Content-type:' . $this->contentType));
curl_setopt($this->ch, CURLOPT_URL, $url);
$response = curl_exec($this->ch);
$this->http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($this->ch));
$this->close();
return $response;
}