/** * Sends an HTTP request to the supplied url and returns the response as * an JSON-decoded php datastructure (usually an array; may be a string). * eg. '/services/v3/activities?newer_than_version=134' * * @param string $url * @return array */ protected function sendRequest($url) { $request = new \Altumo\Http\OutgoingHttpRequest('https://www.pivotaltracker.com' . $url); $request->addHeader('X-TrackerToken', $this->getToken()); $response = $request->send(); return json_decode(\Altumo\Javascript\Json\JsonFormatter::convertXmlToJson($response)); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here $url = $options['url']; $api_key = $options['api-key']; $request = new \Altumo\Http\OutgoingHttpRequest($url); $request->setVerifySslPeer(false); $request->addHeader('Authorization', sprintf('Basic %s', base64_encode(sprintf('%s:X', $api_key)))); echo $request->send(); }
/** * Makes the HTTP request for this SystemEventInstanceMessage. * Saves this SystemEventInstanceMessage as sent, if successful. * * Successful requests must be 200 level and return the following * json message body: * { * "status": "received" * } * * @throws \Exception on error */ public function send() { try { //send the http post request $request = new \Altumo\Http\OutgoingHttpRequest($this->getSystemEventSubscription()->getRemoteUrl()); $request->setVerifySslPeer(false); $request->setRequestMethod(\Altumo\Http\OutgoingHttpRequest::HTTP_METHOD_POST); $request->setMessageBody($this->getSystemEventInstance()->getMessage()); $request->setHeaders(array('Accept' => 'application/json', 'X-Authorization-Token' => $this->getSystemEventSubscription()->getAuthorizationToken())); $http_response_message = $request->sendAndGetResponseMessage(); //if the http response is not 200 level, error if ($http_response_message->getStatusCode() < 200 || $http_response_message->getStatusCode() >= 300) { throw new \Exception('Non 200 level response from subscriber.'); } //get the reponse json $message_body = $http_response_message->getMessageBody(); $json_message_body = json_decode($message_body); if (!$json_message_body) { throw new \Exception('JSON response expected. Response is not valid JSON.'); } if (property_exists($json_message_body, 'status')) { $status = $json_message_body->status; if (!is_string($status)) { throw new \Exception('"status" field must be a string.'); } else { if (strtolower($status) !== 'received') { throw new \Exception('"status" field is expected to be "received".'); } else { //success... message received... update the object $this->setReceived(true); $this->setReceivedAt(\Altumo\Utils\Date::getInstance()->get()); $this->setStatusMessage($message_body); $this->save(); } } } else { throw new \Exception('"status" field not found. JSON response expects a "status" field.'); } } catch (\Exception $e) { $this->setStatusMessage($e->getMessage()); $this->save(); throw $e; } }
/** * Getter for the session field on this ApiClient. * * @return \Altumo\Http\OutgoingHttpRequest */ public function getSession() { //there is an outstanding bug in the curl library that prevents //persistent sessions from working properly //so we create a temporarily create a new OutgoingHttpRequest //for every request (hence the 1 below) if (1 || !$this->session instanceof \Altumo\Http\OutgoingHttpRequest) { if ($this->getHttps()) { $scheme = 'https'; } else { $scheme = 'http'; } $request = new \Altumo\Http\OutgoingHttpRequest($scheme . '://' . $this->getHostname()); $request->addHeader('Accept', 'application/json'); $request->setVerifySslPeer($this->getVerifySslPeer()); $this->session = $request; } return $this->session; }