private function askAsana($url, $data = null, $method = ASANA_METHOD_GET)
{
$headerData = array();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Don't print the result
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
// Don't verify SSL connection
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
// "" ""
if (!empty($this->apiKey)) {
// Send with API key.
curl_setopt($curl, CURLOPT_USERPWD, $this->apiKey);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// Don't send as json when attaching files to tasks.
if (is_string($data) || empty($data['file'])) {
array_push($headerData, 'Content-Type: application/json');
// Send as JSON
}
} elseif (!empty($this->accessToken) || !empty($this->personalAccessToken)) {
if (!empty($this->accessToken)) {
$accessToken = $this->accessToken;
} else {
$accessToken = $this->personalAccessToken;
}
// Send with auth token.
array_push($headerData, 'Authorization: Bearer ' . $accessToken);
// Don't send as json when attaching files to tasks.
if (is_string($data) || empty($data['file'])) {
array_push($headerData, 'Content-Type: application/json');
}
}
if ($this->advDebug) {
curl_setopt($curl, CURLOPT_HEADER, true);
// Display headers
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
// Display output headers
curl_setopt($curl, CURLOPT_VERBOSE, true);
// Display communication with server
}
if ($method == ASANA_METHOD_POST) {
curl_setopt($curl, CURLOPT_POST, true);
} elseif ($method == ASANA_METHOD_PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
} elseif ($method == ASANA_METHOD_DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
if (!is_null($data) && ($method == ASANA_METHOD_POST || $method == ASANA_METHOD_PUT)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
if ($this->fastAPI) {
array_push($headerData, 'Asana-Fast-Api: true');
}
if (sizeof($headerData) > 0) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerData);
}
try {
$this->response = curl_exec($curl);
$this->responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($this->debug || $this->advDebug) {
$info = curl_getinfo($curl);
echo '<pre>';
print_r($info);
echo '</pre>';
if ($info['http_code'] == 0) {
echo '<br>cURL error num: ' . curl_errno($curl);
echo '<br>cURL error: ' . curl_error($curl);
}
echo '<br>Sent info:<br><pre>';
print_r($data);
echo '</pre>';
}
} catch (Exception $ex) {
if ($this->debug || $this->advDebug) {
echo '<br>cURL error num: ' . curl_errno($curl);
echo '<br>cURL error: ' . curl_error($curl);
}
echo 'Error on cURL';
$this->response = null;
}
curl_close($curl);
return $this->response;
}