public static function doRequestWithHeaders($service = null, $action = null, $data_array = null, $method = "POST", $headers = []) { $url = Backendless::getUrl() . '/' . Backendless::getVersion(); if ($service !== null) { $url .= '/' . $service; } if ($action !== null) { $url .= '/' . $action; } $http_request = new HttpRequest(); $http_request->setTargetUrl($url)->setHeader('application-id', Backendless::getApplicationId())->setHeader('secret-key', Backendless::getSecretKey()); foreach ($headers as $name => $val) { $http_request->setHeader($name, $val); } foreach (self::$headers as $heder_n => $h_val) { $http_request->setHeader($heder_n, $h_val); } self::addUserTokenHeader($http_request); self::$headers = []; $http_request->request(json_encode($data_array), $method); self::handleError($http_request); return json_decode($http_request->getResponse(), true); }
public function sendEmail($subject, $body, $to, $attachments = null, $html) { if (!is_array($to)) { $to = [$to]; } $data = ["subject" => $subject, "to" => $to]; if ($html) { $data["bodyparts"] = ["htmlmessage" => $body]; } else { $data["bodyparts"] = ["textmessage" => $body]; } if ($attachments !== null) { $data["attachment"] = $attachments; } return RequestBuilder::doRequestByUrl(Backendless::getUrl() . "/" . Backendless::getVersion() . "/messaging/email", $data, 'POST'); }
public function copyFile($source_path_name, $target_path) { $source_path_name = trim($source_path_name); $source_path_name = trim($source_path_name, "\\\\/"); $target_path = trim($target_path); $target_path = trim($target_path, "\\\\/"); $url_part = Backendless::getUrl() . "/" . Backendless::getApplicationId() . "/" . Backendless::getVersion(); $request_body = ["sourcePath" => $source_path_name, "targetPath" => $target_path]; return RequestBuilder::doRequest('files', 'copy', $request_body, 'PUT'); }
public function reset($counter_name) { RequestBuilder::doRequestByUrl(Backendless::getUrl() . "/" . Backendless::getVersion() . "/counters/" . $counter_name . "/reset", '', 'PUT'); }
public function expireAt($key, $timestamp) { $timestamp = $timestamp * 1000; RequestBuilder::doRequestByUrl(Backendless::getUrl() . "/" . Backendless::getVersion() . "/cache/" . $key . "expireAt?timestamp=" . $timestamp, '', 'PUT'); }
public function dispatch($event_name, $event_args_array = null) { return RequestBuilder::doRequestByUrl(Backendless::getUrl() . "/" . Backendless::getVersion() . "/servercode/events/" . $event_name, $event_args_array, 'POST'); }