/** * Performs a GET request to a CREST endpoint, returning the full response object. * * @param string $url the URL of the endpoint * @param bool $auth if authentication header should be sent * @param string $accept the requested representation * * @return \iveeCrest\Response */ public function getEndpointResponse($url, $auth = false, $accept = null) { if ($auth) { $header = $this->getBearerAuthHeader(); } else { $header = array(); } if (isset($accept)) { $header[] = 'Accept: application/' . $accept; } try { $get = $this->cw->get($url, $header); } catch (Exceptions\CrestException $e) { $match = 'Authentication needed, bad token'; if (strpos($e->getMessage(), $match) !== false) { echo time2s() . "cl.getEndpointResponse() exception: token expired\n"; $token = $this->getAccessToken2(); echo time2s() . "cl.getEndpointResponse() new token {$token}\n"; $header = array('Authorization: Bearer ' . $token); if (isset($accept)) { $header[] = 'Accept: application/' . $accept; } $this->client->getEndpoint(str_replace('token', 'verify', $this->getRootEndpoint()->authEndpoint->href), true); $get = $this->cw->get($url, $header); } else { echo time2s() . "cl.getEndpointResponse() unknown error\n"; var_dump($e); } } return $get; }
/** * Performs a GET request to a CREST endpoint, returning the full response object. * * @param string $url the URL of the endpoint * @param bool $auth if authentication header should be sent * @param string $accept the requested representation * @param bool $cache whether the response should be cached or not * * @return \iveeCrest\Response */ public function getEndpointResponse($url, $auth = false, $accept = null, $cache = true) { if ($auth) { $header = $this->getBearerAuthHeader(); } else { $header = []; } if (isset($accept)) { $header[] = 'Accept: application/' . $accept; } return $this->cw->get($url, $header, $cache); }