Module: BankApi::Clients::BancoSecurity::Session

Included in:
CompanyClient
Defined in:
lib/bank_api/clients/banco_security/concerns/session.rb

Constant Summary collapse

SESSION_VALIDATION =
"https://www.bancosecurity.cl/empresas/SessionValidation.asp"

Instance Method Summary collapse

Instance Method Details

#cookiesObject



28
29
30
31
32
# File 'lib/bank_api/clients/banco_security/concerns/session.rb', line 28

def cookies
  selenium_browser.manage.all_cookies.map do |cookie|
    "#{cookie[:name]}=#{cookie[:value]}"
  end.join("; ")
end

#session_headersObject



19
20
21
22
23
24
25
26
# File 'lib/bank_api/clients/banco_security/concerns/session.rb', line 19

def session_headers
  {
    "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 " +
      "(KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
    "Accept" => "*/*",
    "Cookie" => cookies
  }
end

#setup_authenticationObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bank_api/clients/banco_security/concerns/session.rb', line 7

def setup_authentication
  response = RestClient::Request.execute(
    url: SESSION_VALIDATION, method: :post, headers: session_headers
  )
  new_cookies = response.headers[:set_cookie].first.delete(" ").split(";").map do |a|
    a.split("=")
  end
  new_cookies.each do |key, value|
    selenium_browser.manage.add_cookie(name: key, value: value)
  end
end