protected function _request($api, $path, $method, $params = array(), $version = null, $httpMethod = 'get')
{
if (!is_array($params)) {
$params = array($params);
}
$params['api'] = $this->_getApiName($api);
$params['version'] = (int) $version > 0 ? (int) $version : $this->_version;
$params['method'] = $method;
// create a new cURL resource
$ch = curl_init();
if ($httpMethod !== 'post') {
$url = $this->_getBaseUrl() . $path . '?' . http_build_query($params);
$this->log($url, 'Requested Url');
curl_setopt($ch, CURLOPT_URL, $url);
} else {
$url = $this->_getBaseUrl() . $path;
$this->log($url, 'Requested Url');
$this->log($params, 'Post Variable');
// set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, self::CONNECT_TIMEOUT);
// Verify SSL or not
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->_verifySSL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_verifySSL);
// grab URL and pass it to the browser
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$this->log($info['http_code'], 'Response code');
if (200 == $info['http_code']) {
if (preg_match('#(plain|text)#', $info['content_type'])) {
return $this->_parseRequest($result);
}
return $result;
}
if ($info['total_time'] >= self::CONNECT_TIMEOUT / 1000) {
throw new Synology_Exception('Connection Timeout');
}
$this->log($result, 'Result');
throw new Synology_Exception('Connection Error');
}