Skip to content

Commit

Permalink
Fully implement list_folder
Browse files Browse the repository at this point in the history
list_folder now accepts all available parameters.

list_folder and continue_list_folder return the has_more flag and
cursor along with the entries.

This allows a multi-page response to be processed.
  • Loading branch information
cmason committed Feb 7, 2017
1 parent 247b957 commit d3197d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
26 changes: 22 additions & 4 deletions lib/dropbox/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,37 @@ def get_thumbnail(path, format='jpeg', size='w64h64')
# Get the contents of a folder.
#
# @param [String] path
# @param [boolean] recursive
# @param [boolean] include_media_info
# @param [boolean] include_deleted
# @param [boolean] include_has_explicit_shared_members
#
# @return [Array<Dropbox::Metadata>]
def list_folder(path)
resp = request('/files/list_folder', path: path)
resp['entries'].map { |e| parse_tagged_response(e) }
# @return [Boolean] has_more
# @return [String] cursor
def list_folder(path, recursive: false,
include_media_info: false,
include_deleted: false,
include_has_explicit_shared_members: false )
resp = request('/files/list_folder', path: path,
recursive: recursive,
include_media_info: include_media_info,
include_deleted: include_deleted,
include_has_explicit_shared_members: include_has_explicit_shared_members)
entries = resp['entries'].map { |e| parse_tagged_response(e) }
return entries, resp['has_more'], resp['cursor']
end

# Get the contents of a folder that are after a cursor.
#
# @param [String] cursor
# @return [Array<Dropbox::Metadata>]
# @return [Boolean] has_more
# @return [String] cursor
def continue_list_folder(cursor)
resp = request('/files/list_folder/continue', cursor: cursor)
resp['entries'].map { |e| parse_tagged_response(e) }
entries = resp['entries'].map { |e| parse_tagged_response(e) }
return entries, resp['has_more'], resp['cursor']
end

# Get a cursor for a folder's current state.
Expand Down
6 changes: 4 additions & 2 deletions test/test_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,21 @@ def test_get_thumbnail_error

def test_list_folder
stub_request(:post, url('files/list_folder')).to_return(stub('folder_contents'))
entries = @client.list_folder('/Homework/math')
entries, more, cursor = @client.list_folder('/Homework/math')

assert_equal 2, entries.length
assert entries[0].is_a?(Dropbox::FileMetadata)
assert_equal 'Prime_Numbers.txt', entries[0].name
assert_equal 7212, entries[0].size
assert entries[1].is_a?(Dropbox::FolderMetadata)
assert_equal 'math', entries[1].name
assert_equal false, more
assert_equal "ZtkX9_EHj3x7PMkVuFIhwKYXEpwpLwyxp9vMKomUhllil9q7eWiAu", cursor
end

def test_list_folder_empty
stub_request(:post, url('files/list_folder')).to_return(stub('empty_folder_contents'))
entries = @client.list_folder('/empty_folder')
entries, more, cursor = @client.list_folder('/empty_folder')

assert_equal 0, entries.length
end
Expand Down
6 changes: 4 additions & 2 deletions test/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def test_folders
@client.move(moved.path_lower, folder.path_lower)

cursor = @client.get_latest_list_folder_cursor(folder.path_lower)
entries = @client.list_folder(folder.path_lower)
entries, more, cursor = @client.list_folder(folder.path_lower)
assert_equal 1, entries.length
assert_instance_of Dropbox::FolderMetadata, entries[0]
assert_equal false, more
assert_instance_of String, cursor

@client.create_folder(folder.path_lower + '/new_folder')
entries = @client.continue_list_folder(cursor)
entries, more, cursor = @client.continue_list_folder(cursor)
assert_equal 1, entries.length
assert_instance_of Dropbox::FolderMetadata, entries[0]
assert_equal 'new_folder', entries[0].name
Expand Down

0 comments on commit d3197d9

Please sign in to comment.