Skip to content

Commit

Permalink
Merge pull request #651 from Ducatel/working
Browse files Browse the repository at this point in the history
Add delete object method in the container of ObjectStore.
  • Loading branch information
Jamie Hannaford committed Jan 29, 2016
2 parents dad7eaf + 9035851 commit d6b71fe
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
14 changes: 12 additions & 2 deletions doc/services/object-store/objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,19 @@ filenames inside the archive.

`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/auto-extract-archive-files.php>`_


Delete object
-------------
---------------------------------

.. code-block:: php
$container->deleteObject('{objectName}');
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/ObjectStore/delete-object-without-download.php>`_


Delete already downloaded object
---------------------------------

.. code-block:: php
Expand Down
13 changes: 13 additions & 0 deletions lib/OpenCloud/ObjectStore/Resource/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ public function deleteAllObjects()
return $this->getService()->batchDelete($paths);
}

/**
* Delete an object from the API.
*
* @param string $name The name of object you want to delete
* @throws \Guzzle\Http\Exception\BadResponseException When an error occurred
*/
public function deleteObject($name)
{
$this->getClient()
->delete($this->getUrl($name))
->send();
}

/**
* Creates a Collection of objects in the container
*
Expand Down
36 changes: 36 additions & 0 deletions samples/ObjectStore/delete-object-without-download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require dirname(__DIR__) . '/../vendor/autoload.php';

use OpenCloud\Rackspace;

// 1. Instantiate a Rackspace client. You can replace {authUrl} with
// Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array(
'username' => '{username}',
'apiKey' => '{apiKey}',
));

// 2. Obtain an Object Store service object from the client.
$objectStoreService = $client->objectStoreService(null, '{region}');

// 3. Get container.
$container = $objectStoreService->getContainer('{containerName}');

// 4. Delete object.
$container->deleteObject('{objectName}');
27 changes: 27 additions & 0 deletions tests/OpenCloud/Tests/ObjectStore/Resource/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ public function test_Delete_NonEmpty_Container()
$container->delete();
}

public function test_Delete_Object()
{
$container = $this->container;
$this->addMockSubscriber($this->makeResponse('[]', 204));
$container->deleteObject("someObject");
}

/**
* @expectedException \Guzzle\Http\Exception\BadResponseException
*/
public function test_Delete_Object_With_Failure()
{
$container = $this->container;
$this->addMockSubscriber($this->makeResponse('[]', 500));
$container->deleteObject("someObject");
}

/**
* @expectedException \Guzzle\Http\Exception\BadResponseException
*/
public function test_Delete_NonExisting_Object()
{
$container = $this->container;
$this->addMockSubscriber($this->makeResponse('[]', 404));
$container->deleteObject("someObject");
}

public function test_Object_List()
{
$container = $this->container;
Expand Down

0 comments on commit d6b71fe

Please sign in to comment.