Module: Cielo::HTTP

Instance Method Summary collapse

Instance Method Details

#request(host = nil, port = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cielo/http.rb', line 5

def request(host = nil, port = nil)
  host ||= Cielo.configuration.host
  port ||= Cielo.configuration.port

  http = Net::HTTP.new(host, port)
  http.use_ssl = true
  http.ssl_version = :TLSv1
  http.open_timeout = 10 * 1000
  http.read_timeout = 40 * 1000
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  Cielo.logger.info(http.inspect)

  post_body = "mensagem=#{to_xml}"
  Cielo.logger.info(post_body)

  response = http.request_post(Cielo.configuration.path, post_body)
  Cielo.logger.info(response.body)

  Transaction.parse(response.body, :single => true) || Error.parse(response.body, :single => true)
end