From 01a44b411830a2847a4b498be8bc8d7e1302293a Mon Sep 17 00:00:00 2001 From: Dylan Waits Date: Fri, 1 Jul 2016 20:41:45 -0700 Subject: [PATCH] Combine `parse_save_url_response` with `parse_tagged_response` --- lib/dropbox/client.rb | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/dropbox/client.rb b/lib/dropbox/client.rb index a0bbf0b..8f12239 100644 --- a/lib/dropbox/client.rb +++ b/lib/dropbox/client.rb @@ -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. @@ -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. @@ -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' @@ -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