lib/uencode/request.rb in uencode-0.0.3 vs lib/uencode/request.rb in uencode-3.0.0

- old
+ new

@@ -1,33 +1,43 @@ +# Copyright (c) 2011, uEncode, Cassio Marques + module UEncode class Request + include HTTParty + require 'rubygems' + require 'crack' - base_uri "https://www.uencode.com" format :xml def initialize(job) @job = job end def send - response = self.class.put "/jobs?version=300", :body => @job.to_xml + 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 private def parse_response(response_xml) - doc = Nokogiri::XML response_xml.body - code = doc.xpath("//code").text - message = doc.xpath("//message").text - jobid = doc.xpath("//jobid").text - userdata = doc.xpath("//userdata").text - + code = response_xml.code + data = Crack::XML.parse(response_xml.body) Response.new( :code => code, - :message => message, - :jobid => jobid, - :userdata => userdata + :data => data ) end end end