Class: BCIBank

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

Constant Summary collapse

URL =
"https://www.bci.cl/cl/bci/aplicaciones/seguridad/autenticacion/loginPersonas.jsf"
LOGIN_FORM_NAME =
"frm"
BROWSER =
"Mac FireFox"
START_URL =
"https://www.bci.cl/cuentaswls/ControladorCuentas?opcion=CTACTECARTOLA&objeto="

Instance Attribute Summary collapse

Attributes inherited from Bank

#branch

Instance Method Summary collapse

Constructor Details

#initialize(account = {}) ⇒ BCIBank

Returns a new instance of BCIBank.



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

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

Instance Attribute Details

#account_numberObject

Returns the value of attribute account_number.



4
5
6
# File 'lib/cartolify/banks/bci_bank.rb', line 4

def 
  @account_number
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/cartolify/banks/bci_bank.rb', line 4

def password
  @password
end

#sessionObject (readonly)

Returns the value of attribute session.



5
6
7
# File 'lib/cartolify/banks/bci_bank.rb', line 5

def session
  @session
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/cartolify/banks/bci_bank.rb', line 4

def user
  @user
end

Instance Method Details

#balanceObject



23
24
25
26
27
28
29
30
# File 'lib/cartolify/banks/bci_bank.rb', line 23

def balance
	# We make sure we are on the first page
	session.get("#{START_URL}#{self.}")
	# The balance is in the 7 table, second td
	string_balance = session.page.root.css("table")[6].css("td")[1].text
	# Remove de $ simbol and the dots
	convert_money_to_integer(string_balance)
end

#new_sessionObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cartolify/banks/bci_bank.rb', line 53

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

	form["frm"]="frm"
   	form["frm:canal"]="110"
   	form["frm:clave"]= self.password
    form["frm:clave_aux"]=""
    form["frm:dvCliente"] = self.user[-1] #digito verificador rut
   	form["frm:grupo"] = ""
   	form["frm:j_idt12"] ="Ingresar"
   	# Rut only numbers without verification
   	form["frm:rutCliente"]= self.user[0..-2].gsub(/[\--.]/,'')
   	form["frm:rut_aux"] = ""
   	form["frm:servicioInicial"]="SuperCartola"
   	form["frm:touch"] = "#{(Time.now.to_f*1000).to_i}"
   	form["frm:transaccion"] = ""
	form.submit
	agent
end

#transactionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cartolify/banks/bci_bank.rb', line 32

def transactions
	transactions = []
	# We go to the transactions page
	session.get("#{START_URL}#{self.}")
	# Tables that hold the transactions, we select the tr's
	table_rows = session.page.root.css("table")[10].css("tr.blanco, tr.suave")
	table_rows.each do |row|
		values = row.css("td").map { |td| clean_string(td) }
		total = values[3].size > 0 ? values[3] : values[4]

		transaccion_info = {
			:date => Date.parse(values[0]),
			:description => values[1],
			:serial => values[2],
			:total => convert_money_to_integer(total)
		}
		transactions << Transaction.new(transaccion_info)
	end
	transactions
end

#urlObject



19
20
21
# File 'lib/cartolify/banks/bci_bank.rb', line 19

def url
	URL
end