From ee2cb878511e7a1f291de0e4fe9ea6b3d9c4ce00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fankh=C3=A4nel?= Date: Thu, 7 Jul 2016 17:22:42 +0200 Subject: [PATCH] Deprecate get_input_details, introduce get_details Future changes will require handling output-related data. Since this data is obtained from the same API endpoint as input-related data, get_input_details is deprecated in favor of a more general method. --- app/jobs/pageflow/poll_zencoder_job.rb | 2 +- lib/pageflow/zencoder_api.rb | 5 +++ spec/jobs/poll_zencoder_job_spec.rb | 6 ++-- spec/support/helpers/zencoder_api_double.rb | 34 ++++++++++----------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/jobs/pageflow/poll_zencoder_job.rb b/app/jobs/pageflow/poll_zencoder_job.rb index cbbdc6b7eb..c84b34594b 100644 --- a/app/jobs/pageflow/poll_zencoder_job.rb +++ b/app/jobs/pageflow/poll_zencoder_job.rb @@ -48,7 +48,7 @@ def self.fetch_thumbnail(file) end def self.fetch_input_details(file, api) - file.meta_data_attributes = api.get_input_details(file.job_id) + file.meta_data_attributes = api.get_details(file.job_id) rescue ZencoderApi::RecoverableError => e file.encoding_error_message = e.message throw(:halt, :pending) diff --git a/lib/pageflow/zencoder_api.rb b/lib/pageflow/zencoder_api.rb index 55d4aa7282..718ff34917 100644 --- a/lib/pageflow/zencoder_api.rb +++ b/lib/pageflow/zencoder_api.rb @@ -36,7 +36,12 @@ def get_info(job_id) end end + # @deprecated Use `get_details(job_id)` instead. def get_input_details(job_id) + get_details(job_id) + end + + def get_details(job_id) with_exception_translation do response = Zencoder::Job.details(job_id) diff --git a/spec/jobs/poll_zencoder_job_spec.rb b/spec/jobs/poll_zencoder_job_spec.rb index e6a8100eca..f2ced65bfd 100644 --- a/spec/jobs/poll_zencoder_job_spec.rb +++ b/spec/jobs/poll_zencoder_job_spec.rb @@ -120,7 +120,7 @@ module Pageflow expect(result).to eq(:error) end - it 'passes job id of file to get_input_details method of zencoder api' do + it 'passes job id of file to get_details method of zencoder api' do video_file = build(:video_file, :job_id => 43) allow(ZencoderApi).to receive(:instance).and_return(ZencoderApiDouble.finished) @@ -129,7 +129,7 @@ module Pageflow result = PollZencoderJob.perform_with_result(video_file, {}) - expect(ZencoderApi.instance).to have_received(:get_input_details).with(43) + expect(ZencoderApi.instance).to have_received(:get_details).with(43) end it 'assigns meta data' do @@ -138,7 +138,7 @@ module Pageflow meta_data = {} allow(ZencoderApi).to receive(:instance).and_return(zencoder_api) - allow(zencoder_api).to receive(:get_input_details).and_return(meta_data) + allow(zencoder_api).to receive(:get_details).and_return(meta_data) stub_request(:get, /#{zencoder_options[:s3_host_alias]}/) .to_return(:status => 200, :body => File.read('spec/fixtures/image.jpg')) allow(video_file).to receive(:meta_data_attributes=) diff --git a/spec/support/helpers/zencoder_api_double.rb b/spec/support/helpers/zencoder_api_double.rb index 5d84f96e1d..9f65b5cc1b 100644 --- a/spec/support/helpers/zencoder_api_double.rb +++ b/spec/support/helpers/zencoder_api_double.rb @@ -14,7 +14,7 @@ def finished allow(api).to receive(:create_job).and_return(1) allow(api).to receive(:get_info).and_return(finished_info_result) - allow(api).to receive(:get_input_details).and_return(input_details) + allow(api).to receive(:get_details).and_return(details) api end @@ -24,7 +24,7 @@ def finished_but_failed allow(api).to receive(:create_job).and_return(1) allow(api).to receive(:get_info).and_return(failed_info_result) - allow(api).to receive(:get_input_details).and_return(input_details) + allow(api).to receive(:get_details).and_return(details) api end @@ -34,7 +34,7 @@ def once_pending_then_finished allow(api).to receive(:create_job).and_return(1) allow(api).to receive(:get_info).and_return(pending_info_result, finished_info_result) - allow(api).to receive(:get_input_details).and_return(input_details) + allow(api).to receive(:get_details).and_return(details) api end @@ -44,7 +44,7 @@ def pending(options = {}) allow(api).to receive(:create_job).and_return(1) allow(api).to receive(:get_info).and_return(pending_info_result(options)) - allow(api).to receive(:get_input_details).and_return(input_details) + allow(api).to receive(:get_details).and_return(details) api end @@ -72,27 +72,27 @@ def double end def pending_info_result(options = {}) - { :state => 'encoding', - :progress => options.fetch(:progress, 20), - :finished => false } + {state: 'encoding', + progress: options.fetch(:progress, 20), + finished: false} end def finished_info_result - { :state => 'finished', - :progress => 100, - :finished => true } + {state: 'finished', + progress: 100, + finished: true} end def failed_info_result - { :state => 'failed', - :finished => false } + {state: 'failed', + finished: false} end - def input_details - { :format => 'ogg', - :width => 200, - :height => 100, - :duration_in_ms => 5000 } + def details + {format: 'ogg', + width: 200, + height: 100, + duration_in_ms: 5000} end end