/** * 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)); }
/** * Gets the response body as a json string. * * @param boolean $format //pretty formats the json response * * @return string */ public function getReponseBody($format = false, $errors = null) { $response = new \stdClass(); $body_name = $this->getBodyName(); if ($this->isPaged()) { $response->has_many_pages = $this->getPager()->hasManyPages(); $response->total_results = $this->getPager()->getTotalResults(); $response->page_size = $this->getPager()->getPageSize(); $response->page = $this->getPager()->getPageNumber(); } if (!empty($body_name)) { $response->{$body_name} = $this->getBody(); } else { $response = $this->getBody(); } if ($response instanceof \stdClass) { $response->errors = $errors; } elseif (is_string($response)) { $string = $response; $response = array(); $response['message'] = $string; $response['errors'] = $errors; } else { $response['errors'] = $errors; } $json_string = json_encode($response); if ($format) { return \Altumo\Javascript\Json\JsonFormatter::format($json_string); } else { return $json_string; } }