Skip to content

Commit

Permalink
Add get_copy_reference and save_copy_reference methods
Browse files Browse the repository at this point in the history
  • Loading branch information
waits committed Jun 21, 2016
1 parent 1ce7d06 commit 3696d31
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/dropbox/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ def get_account_batch(account_ids)
resp.map { |a| BasicAccount.new(a) }
end

# Get a copy reference to a file or folder.
#
# @param [String] path
# @return [Dropbox::Metadata] metadata
# @return [String] copy_reference
def get_copy_reference(path)
resp = request('/files/copy_reference/get', path: path)
metadata = parse_tagged_response(resp['metadata'])
return metadata, resp['copy_reference']
end

# Get information about the current user's account.
#
# @return [Dropbox::FullAccount]
Expand Down Expand Up @@ -177,6 +188,16 @@ def revoke_token
raise APIError.new(r) if r.code != 200
end

# Save a copy reference to the user's Dropbox.
#
# @param [String] copy_reference
# @param [String] path
# @return [Dropbox::Metadata] metadata
def save_copy_reference(copy_reference, path)
resp = request('/files/copy_reference/save', copy_reference: copy_reference, path: path)
parse_tagged_response(resp['metadata'])
end

# Save a specified URL into a file in user's Dropbox.
#
# @param [String] path
Expand Down
28 changes: 28 additions & 0 deletions test/test_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ def test_download_error
end
end

# TODO: Getting 500 errors from the API. Mention it to Dropbox.
#
# def test_get_save_copy_reference
# meta, ref = @client.get_copy_reference('/file.txt')
#
# assert meta.is_a?(Dropbox::FileMetadata)
# assert ref.is_a?(String)
# assert_match /^[a-z0-9]+$/i, ref
#
# saved_meta = @client.save_copy_reference('/copied_file.txt')
#
# assert meta.is_a?(Dropbox::FileMetadata)
# assert_equal 'copied_file.txt', file.name
# assert_equal 22, file.size
# end

def test_get_copy_reference_error
assert_raises(Dropbox::APIError) do
@client.get_copy_reference('/not_found')
end
end

def test_get_metadata
file = @client.get_metadata('/file.txt')

Expand Down Expand Up @@ -201,6 +223,12 @@ def test_save_url_error
end
end

def test_save_copy_reference_error
assert_raises(Dropbox::APIError) do
@client.save_copy_reference('invalid', '/saved_copy_reference.txt')
end
end

def test_search
matches = @client.search('empty')
assert_equal 2, matches.length
Expand Down

0 comments on commit 3696d31

Please sign in to comment.