class PinganApi::Base
Public Instance Methods
send_request(body)
click to toggle source
# File lib/pingan_api/base.rb, line 12 def send_request(body) #File.open("tmp/#{Time.now.to_i}.xml", "w") { |file| file.write body } uri = URI(PinganApi.config.server) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.read_timeout = 10 pem = File.read(PinganApi.config.cert) http.cert = OpenSSL::X509::Certificate.new(pem) http.key = OpenSSL::PKey::RSA.new(pem) request = Net::HTTP::Post.new("/", initheader = {'Content-Type' => 'application/xml;charset=' + PinganApi.config.encoding}) request.body = body.encode(PinganApi.config.encoding) return send_request_and_log(http, request) end
send_request_and_log(http, request)
click to toggle source
# File lib/pingan_api/base.rb, line 31 def send_request_and_log(http, request) #log = PinganApi::Models::Log.new # TODO,save request #log.write_request(request) #begin # TODO, save response if PinganApi.config.output_log File.open("tmp/#{Time.now.to_i}_request.xml", "w") { |file| file.write request.body } end res = http.request(request) #log.write_response(res) if PinganApi.config.output_log File.open("tmp/#{Time.now.to_i}_response.xml", "w") { |file| file.write res.body.force_encoding(PinganApi.config.encoding) } end return res.body.force_encoding(PinganApi.config.encoding) #rescue => e #log.write_error(e.to_s) # return nil #end end
send_request_with_data_and_template(data, template_path)
click to toggle source
# File lib/pingan_api/base.rb, line 6 def send_request_with_data_and_template(data, template_path) erb = ERB.new(File.read(template_path)) body = erb.result(data.get_binding) return send_request(body) end