Class: Cieloloja::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/cieloloja/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cieloloja/connection.rb', line 4

def initialize
  @environment = eval(Cieloloja.environment.to_s.capitalize)
  port = 443
  @http = Net::HTTP.new(@environment::BASE_URL,port)
  @http.use_ssl = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  @http.ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs') # Ubuntu
  @http.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt') # Mac OS X      
  
  @http.open_timeout = 10*1000
  @http.read_timeout = 40*1000
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/cieloloja/connection.rb', line 3

def environment
  @environment
end

Instance Method Details

#request!(params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/cieloloja/connection.rb', line 18

def request!(params={})
  str_params = ""
  params.each do |key, value| 
    str_params+="&" unless str_params.empty?
    str_params+="#{key}=#{value}"
  end
  
  Rails.logger.info "Enviando XML para Cielo: #{str_params}"
  @http.request_post(self.environment::WS_PATH, str_params)
end