Class: Pageflow::ZencoderApi

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/zencoder_api.rb

Defined Under Namespace

Classes: Error, RecoverableError, UnrecoverableError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



68
69
70
# File 'lib/pageflow/zencoder_api.rb', line 68

def self.instance
  ZencoderApi.new
end

Instance Method Details

#create_job(definition) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pageflow/zencoder_api.rb', line 7

def create_job(definition)
  with_exception_translation do
    response = Zencoder::Job.create(:input => definition.input_s3_url,
                                    :outputs => definition.outputs)
    if response.success?
      response.body['id']
    else
      raise translate_zencoder_errors(response.errors)
    end
  end
end

#get_details(job_id) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pageflow/zencoder_api.rb', line 40

def get_details(job_id)
  with_exception_translation do
    response = Zencoder::Job.details(job_id)

    if response.success?
      input_details = response.body['job']['input_media_file']
      outputs_details = response.body['job']['output_media_files']

      output_presences = outputs_details.inject({}) do |presences, output|
        if output['label'].present?
          presences[output['label'].to_sym] = output['state']
        end
        presences
      end

      {
        format: input_details['format'],
        duration_in_ms: input_details['duration_in_ms'],
        width: input_details['width'],
        height: input_details['height'],
        output_presences: output_presences
      }
    else
      raise translate_zencoder_errors(response.errors)
    end
  end
end

#get_info(job_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pageflow/zencoder_api.rb', line 19

def get_info(job_id)
  with_exception_translation do
    response = Zencoder::Job.progress(job_id)

    if response.success?
      {
        :state => response.body["state"],
        :progress => response.body["progress"],
        :finished => response.body["state"] == 'finished'
      }
    else
      raise translate_zencoder_errors(response.errors)
    end
  end
end

#get_input_details(job_id) ⇒ Object

Deprecated.

Use ‘get_details(job_id)` instead.



36
37
38
# File 'lib/pageflow/zencoder_api.rb', line 36

def get_input_details(job_id)
  get_details(job_id)
end