A3897deec9b1dbc6def9f5dfcb58bb60

I am not an expert of the net library so I came up with this rather ugly (but working) implementation. By the way if you know any nicer library than net/http then definitely go on and use it for the refactorings.

require 'uri'
require 'net/http'
require 'net/https'

def http_post
  uri = URI.parse(URL)
  req = Net::HTTP.new(uri.host, uri.port)
  req.use_ssl = true 
  req.read_timeout = 5
  begin
    response = req.post(uri.request_uri, @request.xml_payload, @request.headers)
    raise RequestError, 'Problems retrieving data' unless response.is_a? Net::HTTPSuccess
  rescue Timeout::Error
    raise TimeoutError, 'Time out... remote server may be out of reach'
  end
  response.body
end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel