return ($this->tls) ? 'https' : 'http';
}
- private function doHttpRequest($url, $data = array(), $headers = array()) {
+ private function doHttpRequest($url, $data = [], $headers = []) {
if (0 === strpos($url, '/')) {
$url = $this->getScheme() . '://' . $this->host . $url;
}
return $this->last_http_result;
}
- private function doHttpDelete($url, $data = array(), $headers = array()) {
+ private function doHttpDelete($url, $data = [], $headers = []) {
$this->http_method = 'DELETE';
$this->doHttpRequest($url, $data, $headers);
$this->http_method = null; // reset for next request
}
private function parseAuthenticityToken($str) {
- $m = array();
+ $m = [];
preg_match('/<meta (?:name="csrf-token" content="(.*?)"|content="(.*?)" name="csrf-token")/', $str, $m);
if (empty($m[1]) && !empty($m[2])) {
$token = $m[2];
public function logIn() {
$this->doHttpRequest('/users/sign_in');
- $params = array(
+ $params = [
'user[username]' => $this->user,
'user[password]' => $this->password,
'authenticity_token' => $this->csrf_token
- );
+ ];
$this->doHttpRequest('/users/sign_in', $params);
$this->doHttpRequest('/stream');
return (200 === $this->last_http_result->info['http_code']) ? true : false;
public function getAspects() {
$this->doHttpRequest('/bookmarklet');
- $m = array();
+ $m = [];
preg_match('/"aspects"\:(\[.+?\])/', $this->last_http_result->response, $m);
return (!empty($m[1])) ? json_decode($m[1]) : false;
}
public function getServices() {
$this->doHttpRequest('/bookmarklet');
- $m = array();
+ $m = [];
preg_match('/"configured_services"\:(\[.+?\])/', $this->last_http_result->response, $m);
return (!empty($m[1])) ? json_decode($m[1]) : false;
}
return $this->readJsonResponse($this->last_http_result->response);
}
- public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = array()) {
- $data = array(
+ public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = []) {
+ $data = [
'aspect_ids' => $aspect_ids,
- 'status_message' => array(
+ 'status_message' => [
'text' => $msg,
'provider_display_name' => $this->provider
- )
- );
+ ]
+ ];
if (!empty($additional_data)) {
$data += $additional_data;
}
- $headers = array(
+ $headers = [
'Content-Type: application/json',
'Accept: application/json',
'X-CSRF-Token: ' . $this->csrf_token
- );
+ ];
$this->http_method = 'POST';
$this->doHttpRequest('/status_messages', json_encode($data), $headers);
}
public function postPhoto($file) {
- $params = array(
+ $params = [
'photo[pending]' => 'true',
'qqfile' => basename($file)
- );
+ ];
$query_string = '?' . http_build_query($params);
- $headers = array(
+ $headers = [
'Accept: application/json',
'X-Requested-With: XMLHttpRequest',
'X-CSRF-Token: ' . $this->csrf_token,
'X-File-Name: ' . basename($file),
'Content-Type: application/octet-stream',
- );
+ ];
if ($size = @filesize($file)) {
$headers[] = "Content-Length: $size";
}
}
public function deletePost($id) {
- $headers = array('X-CSRF-Token: ' . $this->csrf_token);
- $this->doHttpDelete("/posts/$id", array(), $headers);
+ $headers = ['X-CSRF-Token: ' . $this->csrf_token];
+ $this->doHttpDelete("/posts/$id", [], $headers);
return (204 === $this->last_http_result->info['http_code']) ? true : false;
}
public function deleteComment($id) {
- $headers = array('X-CSRF-Token: ' . $this->csrf_token);
- $this->doHttpDelete("/comments/$id", array(), $headers);
+ $headers = ['X-CSRF-Token: ' . $this->csrf_token];
+ $this->doHttpDelete("/comments/$id", [], $headers);
return (204 === $this->last_http_result->info['http_code']) ? true : false;
}