Class: WebClient

Inherits:
Object show all
Defined in:
lib/commercebank.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWebClient

Returns a new instance of WebClient.



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

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.



18
19
20
# File 'lib/commercebank.rb', line 18

def cookies
  @cookies
end

#fieldsObject (readonly)

Returns the value of attribute fields.



18
19
20
# File 'lib/commercebank.rb', line 18

def fields
  @fields
end

Instance Method Details

#get(path, form = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/commercebank.rb', line 27

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



34
35
36
37
38
39
# File 'lib/commercebank.rb', line 34

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