Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://github.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://github.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();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My problem with this is what happens if a 500 or 403 is returned? All the user will get is false. One option would be to return nothing for success, and an exception for failure. So it could just be:

$this->getClient()
     ->delete($this->getUrl($name))
     ->send();

What do you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it will be more consistent with the rest of API.
If the code change, we need to update unit test of this function.


/**
* 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}');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job for including samples 👍

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