Skip to content

Commit

Permalink
batch delete docs
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorfinnell committed Jan 13, 2018
1 parent 93b3cfa commit 66e6d8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -81,6 +81,13 @@ You can also pass additional headers (e.g. metadata):
client.put_object("bucket_name", "object_key", "myobjectbody", {"x-amz-meta-name" => "myobject"})
```

## **Batch Delete Objects**

```crystal
resp = client.batch_delete("bucket_name", ["key1", "key2"])
resp.success? # => true
```

## **Get Object**

```crystal
Expand Down
5 changes: 1 addition & 4 deletions src/awscr-s3/client.cr
Expand Up @@ -190,13 +190,10 @@ module Awscr::S3
# success, false otherwise. Note: A return value of false could still have
# deleted some of the keys in the request.
#
# TODO: Track which keys were deleted and which failed in the delete request
# and use that as return object
#
# ```
# client = Client.new("region", "key", "secret")
# resp = client.batch_delete("bucket1", ["obj", "obj2"])
# p resp # => true
# p resp.success? # => true
# ```
def batch_delete(bucket, keys : Array(String))
raise "More than 1000 keys is not yet supported." if keys.size > 1_000
Expand Down
9 changes: 9 additions & 0 deletions src/awscr-s3/responses/batch_delete_output.cr
@@ -1,13 +1,19 @@
module Awscr::S3::Response
class BatchDeleteOutput
class DeletedObject
# The key of the deleted object
getter key

# The failure code
getter code

# Human friendly failure message
getter message

def initialize(@key : String, @code : String, @message : String)
end

# Returns true of object was deleted, false otherwise
def deleted?
@code.empty?
end
Expand Down Expand Up @@ -40,14 +46,17 @@ module Awscr::S3::Response
@objects = objects
end

# Returns true if all objects were deleted, false otherwise.
def success?
!@objects.map(&.deleted?).includes?(false)
end

# Returns an array of objects that were successfully deleted
def deleted_objects
@objects.select(&.deleted?)
end

# Returns an array of objects that failed to be deleted
def failed_objects
@objects.reject(&.deleted?)
end
Expand Down

0 comments on commit 66e6d8e

Please sign in to comment.