Skip to content

Commit

Permalink
Adds support for parent_rev option in #delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Burgos committed Jul 14, 2018
1 parent 50ff709 commit 9847441
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/dropbox_api/endpoints/files/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ class Delete < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::Resource
ErrorType = DropboxApi::Errors::DeleteError

include DropboxApi::OptionsValidator

# Delete the file or folder at a given path.
#
# If the path is a folder, all its contents will be deleted too.
#
# A successful response indicates that the file or folder was deleted.
# The returned metadata will be the corresponding FileMetadata or
# FolderMetadata for the item at time of deletion, and not a
# DeletedMetadata object.
# The returned metadata will be the corresponding
# {DropboxApi::Metadata::File} or {DropboxApi::Metadata::Folder} for the
# item at time of deletion, and not a {DropboxApi::Metadata::Deleted} object.
#
# @param path [String] Path in the user's Dropbox to delete.
add_endpoint :delete do |path|
perform_request({
# @option parent_rev [String] Perform delete if given "rev" matches the
# existing file's latest "rev". This field does not support deleting a
# folder. If the given "rev" doesn't match, a
# {DropboxApi::Errors::FileConflictError} will be raised.
add_endpoint :delete do |path, options = {}|
validate_options([:parent_rev], options)

perform_request options.merge({
:path => path
})
end
Expand Down
6 changes: 6 additions & 0 deletions spec/endpoints/files/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
expect(file.name).to eq("will_be_deleted.txt")
end

it "wont' delete the file if `parent_rev` doesn't match", :cassette => "delete/invalid_parent_rev" do
expect {
@client.delete "#{path_prefix}/wont_be_deleted.txt", :parent_rev => "1c0576c68d6"
}.to raise_error(DropboxApi::Errors::FileConflictError)
end

it "returns the deleted folder", :cassette => "delete/success_folder" do
folder = @client.delete "#{path_prefix}/folder"

Expand Down
51 changes: 51 additions & 0 deletions spec/fixtures/vcr_cassettes/delete/invalid_parent_rev.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/support/dropbox_scaffold_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def build_delete
file_contents = "Tijuana, amigo."

client.upload "#{path_prefix}/will_be_deleted.txt", file_contents
client.upload "#{path_prefix}/wont_be_deleted.txt", file_contents
client.upload "#{path_prefix}/folder/a.txt", file_contents
client.upload "#{path_prefix}/folder/b.txt", file_contents
end
Expand Down

0 comments on commit 9847441

Please sign in to comment.