Skip to content

Commit

Permalink
Combine parse_save_url_response with parse_tagged_response
Browse files Browse the repository at this point in the history
  • Loading branch information
waits committed Jul 2, 2016
1 parent 522d07e commit 01a44b4
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions lib/dropbox/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def restore(path, rev)
# @return [Dropbox::FileMetadata] if the processing is synchronous.
def save_url(path, url)
resp = request('/files/save_url', path: path, url: url)
parse_save_url_response(resp)
parse_tagged_response(resp)
end

# Check the status of a save_url job.
Expand All @@ -208,7 +208,7 @@ def save_url(path, url)
# @return [String] an error message, if the job failed.
def check_save_url_job_status(async_job_id)
resp = request('/files/save_url/check_job_status', async_job_id: async_job_id)
parse_save_url_response(resp)
parse_tagged_response(resp)
end

# Search for files and folders.
Expand Down Expand Up @@ -315,21 +315,6 @@ def get_space_usage
end

private
def parse_save_url_response(resp)
case resp['.tag']
when 'complete'
FileMetadata.new(resp)
when 'async_job_id'
resp['async_job_id']
when 'in_progress'
nil
when 'failed'
resp['failed']['.tag']
else
raise ClientError.unknown_response_type(resp['.tag'])
end
end

def parse_tagged_response(resp)
case resp['.tag']
when 'file'
Expand All @@ -342,6 +327,14 @@ def parse_tagged_response(resp)
BasicAccount.new(resp)
when 'full_account'
FullAccount.new(resp)
when 'complete'
FileMetadata.new(resp)
when 'async_job_id'
resp['async_job_id']
when 'in_progress'
nil
when 'failed'
resp['failed']['.tag']
else
raise ClientError.unknown_response_type(resp['.tag'])
end
Expand Down

0 comments on commit 01a44b4

Please sign in to comment.