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


58
59
60
# File 'lib/pageflow/zencoder_api.rb', line 58

def self.instance
  ZencoderApi.new
end

Instance Method Details

#create_job(definition) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pageflow/zencoder_api.rb', line 11

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_info(job_id) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pageflow/zencoder_api.rb', line 23

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


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pageflow/zencoder_api.rb', line 39

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

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

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