Class: UEncode::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/uencode/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ Request

Returns a new instance of Request.



12
13
14
# File 'lib/uencode/request.rb', line 12

def initialize(job)
  @job = job
end

Instance Method Details

#sendObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/uencode/request.rb', line 16

def send
  url_base = "https://api.uencode.com/300/jobs"      
  key = @job.customerkey || UEncode.customer_key
  if @job.instance_of?(Job)
    response = self.class.post url_base, :body => @job.to_xml, :headers=>{"Authorization"=>key, "Accept"=>"text/xml"}
  elsif !@job.key.nil?
    response = self.class.get url_base + "/" + @job.key, :headers=>{"Authorization"=>key, "Accept"=>"text/xml"}
  else
    url = url_base
    if !@job.userdata.nil?
      url += "?userdata=" + URI::escape(@job.userdata)
    end
    response = self.class.get url, :headers=>{"Authorization"=>key, "Accept"=>"text/xml"}
  end
  parse_response response
end