Class: CHILEEMPRESASBank

Inherits:
Bank
  • Object
show all
Defined in:
lib/cartolify/banks/chileempresas_bank.rb

Constant Summary collapse

HOST =
"www.empresas.bancochile.cl"
URL =
"https://#{HOST}/cgi-bin/navega?pagina=enlinea/login_fus"
LOGIN_FORM_NAME =
"theform"
BROWSER =
"Mac FireFox"
START_URL =
"https://www.empresas.bancochile.cl/CCOLSaldoMovimientosWEB/selectorCuentas.do?accion=initSelectorCuentas&moneda=CTD&cuenta="
FONDOS_MUTUO_URL =
"https://www.empresas.bancochile.cl/cgi-bin/cgiinvbanch"

Instance Attribute Summary collapse

Attributes inherited from Bank

#branch

Instance Method Summary collapse

Constructor Details

#initialize(account = {}) ⇒ CHILEEMPRESASBank

Returns a new instance of CHILEEMPRESASBank.



12
13
14
15
16
17
18
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 12

def initialize( = {})
  @company_rut = [:company_rut]
  @user = [:user]
  @password = [:password]
  @account_number = [:number]
  @session = new_session
end

Instance Attribute Details

#account_numberObject

Returns the value of attribute account_number.



2
3
4
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2

def 
  @account_number
end

#company_rutObject

Returns the value of attribute company_rut.



2
3
4
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2

def company_rut
  @company_rut
end

#passwordObject

Returns the value of attribute password.



2
3
4
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2

def password
  @password
end

#sessionObject (readonly)

Returns the value of attribute session.



3
4
5
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 3

def session
  @session
end

#userObject

Returns the value of attribute user.



2
3
4
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2

def user
  @user
end

Instance Method Details

#balanceObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 24

def balance
  # We make sure we are on the first page
  session.get("#{START_URL}#{self.}")
  # The value is inside a div#saldos in the second td
  string_balance = clean_string(session.page.root.css("#estaCuen").css(".detalleSaldosMov").css("td").last)
  # The above result has an ":" character that we need to remove
  string_balance.gsub!(/:/,'')
  # Remove de $ simbol and the dots
  convert_money_to_integer(string_balance)
end

#balance_fondos_mutuosObject



60
61
62
63
64
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 60

def balance_fondos_mutuos
  session.get(FONDOS_MUTUO_URL)
  string_balance = session.page.root.css("table")[4].css("tr")[2].css("td").last.text.lstrip
  convert_money_to_integer(string_balance)
end

#new_sessionObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 67

def new_session
  agent = Mechanize.new
  agent.user_agent_alias=BROWSER
  agent.get(URL)
  form = agent.page.form(LOGIN_FORM_NAME)

  form["rut_emp"] = self.company_rut[0..-2].gsub(/[\--.]/,'')
  form["dv_emp"] = self.company_rut[-1]
  form["rut_apo"] = self.user[0..-2].gsub(/[\--.]/,'')
  form["dv_apo"] =  self.user[-1]
  form["pin"] = self.password

  form.submit
  agent
end

#transactionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 35

def transactions
  transactions = []
  total = 0
  movements = get_transactions_json
  movements.each do |mov|
    
    if mov[4].empty? # Out money
      total = convert_money_to_integer(mov[5])
    else
      total = convert_money_to_integer(mov[4]) * -1 
    end
    
    saldo = convert_money_to_integer(mov[6])
    
    transaccion_info = {
		:date => Date.parse(mov[0]),
		:description => mov[1],
		:total => total,
		:saldo => saldo
	}
	transactions << Transaction.new(transaccion_info)
  end
  transactions
end

#urlObject



20
21
22
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 20

def url
  URL
end