# Copyright (c) 2011, uEncode, Cassio Marques module UEncode class Request include HTTParty require 'rubygems' require 'crack' format :xml def initialize(job) @job = job end 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 private def parse_response(response_xml) code = response_xml.code data = Crack::XML.parse(response_xml.body) Response.new( :code => code, :data => data ) end end end