Added accountInfo method to ObjectStorage.

This commit is contained in:
Matt Butcher
2012-01-03 18:51:34 -06:00
parent 2ae6124c02
commit af74df26e0
2 changed files with 39 additions and 1 deletions

View File

@@ -338,6 +338,33 @@ class ObjectStorage {
}
}
/**
* Retrieve account info.
*
* This returns information about:
*
* - The total bytes used by this Object Storage instance (`bytes`).
* - The number of containers (`count`).
*
* @return array
* An associative array of account info. Typical keys are:
* - bytes
* - count
* @throws \HPCloud\Transport\AuthorizationException
* if the user credentials are invalid or have expired.
*/
public function accountInfo() {
$url = $this->url();
$data = $this->req($url, 'HEAD', FALSE);
$results = array(
'bytes' => $data->header('X-Account-Bytes-Used', 0),
'count' => $data->header('X-Account-Container-Count', 0),
);
return $results;
}
/**
* Do a GET on Swift.
*

View File

@@ -61,7 +61,18 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
}
/**
* Test the process of fetching a list of containers.
* @depends testCreateContainer
*/
public function testAccountInfo () {
$store = $this->auth();
$info = $store->accountInfo();
$this->assertTrue($info['count'] > 0);
$this->assertTrue($info['bytes'] > 0);
}
/**
* @depends testCreateContainer
*/
public function testContainers() {