Skip to content

Commit

Permalink
Deprecate get_input_details, introduce get_details
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aviav authored and tf committed Oct 20, 2016
1 parent 02527db commit ee2cb87
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/jobs/pageflow/poll_zencoder_job.rb
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/pageflow/zencoder_api.rb
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions spec/jobs/poll_zencoder_job_spec.rb
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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=)
Expand Down
34 changes: 17 additions & 17 deletions spec/support/helpers/zencoder_api_double.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ee2cb87

Please sign in to comment.