本文整理汇总了PHP中OpenCloud\Common\Http\Message\Formatter类的典型用法代码示例。如果您正苦于以下问题:PHP Formatter类的具体用法?PHP Formatter怎么用?PHP Formatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Formatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
/**
* Test the validity of an existing resource.
*
* @access public
* @param bool $debug (default: false)
* @return void
*/
public function test($debug = false)
{
$json = json_encode($this->updateJson());
$this->checkJsonError();
$response = $this->getClient()->post($this->testExistingUrl($debug), array(), $json)->send();
return Formatter::decode($response);
}
示例2: getMetadata
/**
* Returns metadata properties associated with this Resource
*
* @return \stdClass
*/
public function getMetadata()
{
$url = clone $this->getUrl();
$url->addPath('metadata');
$response = $this->getClient()->get($url)->send();
$json = Formatter::decode($response);
return $json->metadata;
}
示例3: getSingleHistoryItem
public function getSingleHistoryItem($checkId, $historyId)
{
$url = $this->url($checkId . '/' . $historyId);
$response = $this->getClient()->get($url)->send();
if (null !== ($decoded = Formatter::decode($response))) {
$this->populate($decoded);
}
return false;
}
示例4: getConnection
/**
* @param $connectionId
* @return mixed
* @throws \OpenCloud\CloudMonitoring\Exception\AgentException
*/
public function getConnection($connectionId)
{
if (!$this->getId()) {
throw new Exception\AgentException('Please specify an "ID" value');
}
$url = clone $this->getUrl();
$url->addPath('connections')->addPath($connectionId);
$response = $this->getClient()->get($url)->send();
$body = Formatter::decode($response);
return $this->getService()->resource('AgentConnection', $body);
}
示例5: delete
/**
* DNS PTR Delete() method requires a server
*
* Note that delete will remove ALL PTR records associated with the device
* unless you pass in the parameter ip={ip address}
*
*/
public function delete()
{
$this->link_rel = $this->server->getService()->Name();
$this->link_href = $this->server->Url();
$params = array('href' => $this->link_href);
if (!empty($this->data)) {
$params['ip'] = $this->data;
}
$url = clone $this->getUrl();
$url->addPath('rdns')->addPath($this->link_rel)->setQuery($params);
$response = $this->getClient()->delete($url)->send();
return new AsyncResponse($this->getService(), Formatter::decode($response));
}
示例6: traceroute
public function traceroute(array $options)
{
if (!$this->getId()) {
throw new Exception\ZoneException('Please specify a zone ID');
}
if (!isset($options['target']) || !isset($options['target_resolver'])) {
throw new Exception\ZoneException('Please specify a "target" and "target_resolver" value');
}
$params = (object) array('target' => $options['target'], 'target_resolver' => $options['target_resolver']);
try {
$response = $this->getService()->getClient()->post($this->url('traceroute'), array(), json_encode($params))->send();
$body = Formatter::decode($response);
return isset($body->result) ? $body->result : false;
} catch (ClientErrorResponseException $e) {
return false;
}
}
示例7: __construct
/**
* Contructs a Metadata object associated with a Server or Image object
*
* @param object $parent either a Server or an Image object
* @param string $key the (optional) key for the metadata item
* @throws MetadataError
*/
public function __construct(Server $parent, $key = null)
{
// construct defaults
$this->setParent($parent);
// set the URL according to whether or not we have a key
if ($this->getParent()->getId()) {
$this->url = $this->getParent()->url('metadata');
$this->key = $key;
// in either case, retrieve the data
$response = $this->getParent()->getClient()->get($this->getUrl())->send();
// parse and assign the server metadata
$body = Formatter::decode($response);
if (isset($body->metadata)) {
foreach ($body->metadata as $key => $value) {
$this->{$key} = $value;
}
}
}
}
示例8: authenticate
/**
* Authenticate the tenant using the supplied credentials
*
* @return void
* @throws AuthenticationError
*/
public function authenticate()
{
$identity = IdentityService::factory($this);
$response = $identity->generateToken($this->getCredentials());
$body = Formatter::decode($response);
$this->setCatalog($body->access->serviceCatalog);
$this->setTokenObject($identity->resource('Token', $body->access->token));
$this->setUser($identity->resource('User', $body->access->user));
if (isset($body->access->token->tenant)) {
$this->setTenantObject($identity->resource('Tenant', $body->access->token->tenant));
}
// Set X-Auth-Token HTTP request header
$this->updateTokenHeader();
}
示例9: limitTypes
/**
* returns an array of limit types
*
* @return array
*/
public function limitTypes()
{
$response = $this->getClient()->get($this->getUrl('limits/types'))->send();
$body = Formatter::decode($response);
return $body->limitTypes;
}
示例10: getHomeDocument
/**
* Returns the home document for the CDN service
*
* @return \stdClass home document response
*/
public function getHomeDocument()
{
$url = clone $this->getUrl();
// This hack is necessary otherwise Guzzle will remove the trailing
// slash from the URL and the request will fail because the service
// expects the trailing slash :(
$url->setPath($url->getPath() . '/');
$response = $this->getClient()->get($url)->send();
return Formatter::decode($response);
}
示例11: parseResponse
/**
* Parse a HTTP response for the required content
*
* @param Response $response
* @return mixed
*/
public function parseResponse(Response $response)
{
$document = Formatter::decode($response);
$topLevelKey = $this->jsonName();
return $topLevelKey && isset($document->{$topLevelKey}) ? $document->{$topLevelKey} : $document;
}
示例12: getVersionedUrl
/**
* Returns the endpoint URL with a version in it
*
* @param string $url Endpoint URL
* @param string $supportedServiceVersion Service version supported by the SDK
* @param OpenCloud\OpenStack $client OpenStack client
* @return Guzzle/Http/Url Endpoint URL with version in it
*/
private function getVersionedUrl($url, $supportedServiceVersion, OpenStack $client)
{
$versionRegex = '/\\/[vV][0-9][0-9\\.]*/';
if (1 === preg_match($versionRegex, $url)) {
// URL has version in it; use it as-is
return Url::factory($url);
}
// If there is no version in $url but no $supportedServiceVersion
// is specified, just return $url as-is but log a warning
if (is_null($supportedServiceVersion)) {
$client->getLogger()->warning('Service version supported by SDK not specified. Using versionless service URL as-is, without negotiating version.');
return Url::factory($url);
}
// Make GET request to URL
$response = Formatter::decode($client->get($url)->send());
// Attempt to parse response and determine URL for given $version
if (!isset($response->versions) || !is_array($response->versions)) {
throw new UnsupportedVersionError('Could not negotiate version with service.');
}
foreach ($response->versions as $version) {
if (($version->status == 'CURRENT' || $version->status == 'SUPPORTED') && $version->id == $supportedServiceVersion) {
foreach ($version->links as $link) {
if ($link->rel == 'self') {
return Url::factory($link->href);
}
}
}
}
// If we've reached this point, we could not find a versioned
// URL in the response; throw an error
throw new UnsupportedVersionError(sprintf('SDK supports version %s which is not currently provided by service.', $supportedServiceVersion));
}
示例13: getRecordedChecks
public function getRecordedChecks()
{
$response = $this->getService()->getClient()->get($this->getHistoryUrl())->send();
$body = Formatter::decode($response);
return isset($body->check_ids) ? $body->check_ids : false;
}
示例14: changes
/**
* returns changes since a specified date/time
*
* @param string $since the date or time
* @return DNS\Changes
*/
public function changes($since = null)
{
$url = clone $this->getUrl();
$url->addPath('changes');
if ($since) {
$url->setQuery(array('since' => $since));
}
$response = $this->getService()->getClient()->get($url)->send();
return Formatter::decode($response);
}
示例15: appendNewCollection
/**
* Retrieve a new page of elements from the API (based on a new request), parse its response, and append them to the
* collection.
*
* @return $this|bool
*/
public function appendNewCollection()
{
$request = $this->resourceParent->getClient()->createRequest($this->getOption('request.method'), $this->constructNextUrl(), $this->getOption('request.headers'), $this->getOption('request.body'), $this->getOption('request.curlOptions'));
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
return false;
}
if (!($body = Formatter::decode($response)) || $response->getStatusCode() == 204) {
return false;
}
$this->nextUrl = $this->extractNextLink($body);
return $this->appendElements($this->parseResponseBody($body));
}