Class: BCIBank
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
-
#account_number ⇒ Object
Returns the value of attribute account_number.
-
#password ⇒ Object
Returns the value of attribute password.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes inherited from Bank
Instance Method Summary collapse
- #balance ⇒ Object
-
#initialize(account = {}) ⇒ BCIBank
constructor
A new instance of BCIBank.
- #new_session ⇒ Object
- #transactions ⇒ Object
- #url ⇒ Object
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(account = {}) @user = account[:user] @password = account[:password] @account_number = account[:number] @session = new_session end |
Instance Attribute Details
#account_number ⇒ Object
Returns the value of attribute account_number.
4 5 6 |
# File 'lib/cartolify/banks/bci_bank.rb', line 4 def account_number @account_number end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/cartolify/banks/bci_bank.rb', line 4 def password @password end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
5 6 7 |
# File 'lib/cartolify/banks/bci_bank.rb', line 5 def session @session end |
#user ⇒ Object
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
#balance ⇒ Object
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.account_number}") # 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_session ⇒ Object
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 |
#transactions ⇒ Object
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.account_number}") # 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 |
#url ⇒ Object
19 20 21 |
# File 'lib/cartolify/banks/bci_bank.rb', line 19 def url URL end |