/** * Builds an AccessToken object from an XML string. * @param string $data */ public static function fromXml($data) { $dom = new DOMDocument(); $parseOk = false; $parseOk = $dom->loadXML($data); if (!$parseOk) { throw new EsuException('Failed to parse Policy XML'); } $accessToken = new AccessToken(); $root = $dom->firstChild; if ($root->localName != 'access-token') { throw new EsuException('Expected root node to be \'access-token\'. It was ' . $root->localName); } $accessToken->loadFromElement($root); return $accessToken; }
/** * Gets information about an anonymous access token. * @param string $tokenId * @return AccessToken the access token info object. */ public function getAccessTokenInfo($tokenId) { // Build the request $resource = $this->context . "/accesstokens/" . $tokenId; $req = $this->buildRequestNoEscape($resource, 'info'); $headers = array(); $headers['x-emc-uid'] = $this->uid; $headers['Date'] = gmdate('r'); // Sign and send the request $this->signRequest($req, 'GET', $resource, $headers, null); try { $response = @$req->send(); } catch (HTTP_Request2_Exception $e) { throw new EsuException('Sending request failed: ' . $e->__toString()); } // Return the response if ($response->getStatus() > 299) { $this->handleError($response); } // Parse the returned objects. They are passed in the response // body in an XML format. return AccessToken::fromXml($response->getBody()); }