Class: Encoder::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id = nil, user_key = nil) ⇒ Client

Returns a new instance of Client.



42
43
44
45
46
# File 'lib/encoder.rb', line 42

def initialize(user_id=nil, user_key=nil)
  @user_id = user_id
  @user_key = user_key
  @url = 'http://manage.encoding.com/'
end

Instance Attribute Details

#last_errorObject (readonly)

Returns the value of attribute last_error.



40
41
42
# File 'lib/encoder.rb', line 40

def last_error
  @last_error
end

#urlObject (readonly)

Returns the value of attribute url.



40
41
42
# File 'lib/encoder.rb', line 40

def url
  @url
end

#user_idObject (readonly)

Returns the value of attribute user_id.



40
41
42
# File 'lib/encoder.rb', line 40

def user_id
  @user_id
end

#user_keyObject (readonly)

Returns the value of attribute user_key.



40
41
42
# File 'lib/encoder.rb', line 40

def user_key
  @user_key
end

Instance Method Details

#cancel_media(media_id) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/encoder.rb', line 105

def cancel_media(media_id)
  xml = Builder::XmlMarkup.new :indent => 2
  xml.instruct!
  xml.query do |q|
    q.userid    @user_id
    q.userkey   @user_key
    q.action    EncodingActions::CANCEL_MEDIA
    q.mediaid   media_id
  end

  response = request_send(xml.target!)
  return RequestResponse::ERROR if request_error?(response)

  document = Nokogiri::XML(response.body)
  return RequestResponse::ERROR if api_error?(document)

  true

end

#request_encoding(source = nil, notify_url = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/encoder.rb', line 48

def request_encoding(source=nil, notify_url=nil)
  #{ :size, :bitrate, :audio_bitrate, :audio_sample_rate,
  #:audio_channels_number, :framerate, :two_pass, :cbr,
  #:deinterlacing, :destination, :add_meta

  xml = Builder::XmlMarkup.new :indent=>2
  xml.instruct! 
  xml.query do |q|
    q.userid  @user_id
    q.userkey @user_key
    q.action  EncodingActions::ADD_MEDIA
    q.source  source
    q.notify  notify_url

    yield q
  end

  response = request_send(xml.target!)
  return RequestResponse::ERROR if request_error?(response)

  document = Nokogiri::XML(response.body)
  return RequestResponse::ERROR if api_error?(document)

  document.css("MediaID").text.to_i
end

#request_status(media_id) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/encoder.rb', line 74

def request_status(media_id)
  xml = Builder::XmlMarkup.new :indent=>2
  xml.instruct!
  xml.query do |q|
    q.userid    @user_id
    q.userkey   @user_key
    q.action    EncodingActions::GET_STATUS
    q.mediaid   media_id
  end

  response = request_send(xml.target!)
  return RequestResponse::ERROR if request_error?(response)

  document = Nokogiri::XML(response.body)
  return RequestResponse::ERROR if api_error?(document)

  status   = document.css("response > status").text
  progress = document.css("progress").text.to_i

  # there is a bug where the progress reports
  # as 100% if the status is 'Waiting for encoder'
  if (status == EncodingStatusType::WAITING)
    progress = 0
  end

  status = { 
    :message => status,
    :progress => progress
  }
end