Class: WebClient

Inherits:
Object show all
Defined in:
lib/commercebank.rb,
lib/commerce-bank-client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWebClient

Returns a new instance of WebClient.



25
26
27
28
29
30
# File 'lib/commercebank.rb', line 25

def initialize
  @cookies = Hash.new
  @http = Net::HTTP.new('banking.commercebank.com', 443)
  @http.use_ssl = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



23
24
25
# File 'lib/commercebank.rb', line 23

def cookies
  @cookies
end

#fieldsObject (readonly)

Returns the value of attribute fields.



23
24
25
# File 'lib/commercebank.rb', line 23

def fields
  @fields
end

Instance Method Details

#get(path, form = nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/commercebank.rb', line 32

def get(path, form = nil)
  response = @http.get(path, header)
  add_cookies(response)
  @fields = (form && get_form(response.body, form)) || Hash.new
  response
end

#post(path, form = nil) ⇒ Object



39
40
41
42
43
44
# File 'lib/commercebank.rb', line 39

def post(path, form = nil)
  response = @http.post(path, @fields.to_url, header)
  add_cookies(response)
  @fields = (form && get_form(response.body, form)) || Hash.new
  response
end