Class: CHILEEMPRESASBank
- 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
-
#account_number ⇒ Object
Returns the value of attribute account_number.
-
#company_rut ⇒ Object
Returns the value of attribute company_rut.
-
#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
- #balance_fondos_mutuos ⇒ Object
-
#initialize(account = {}) ⇒ CHILEEMPRESASBank
constructor
A new instance of CHILEEMPRESASBank.
- #new_session ⇒ Object
- #transactions ⇒ Object
- #url ⇒ Object
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(account = {}) @company_rut = account[:company_rut] @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.
2 3 4 |
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2 def account_number @account_number end |
#company_rut ⇒ Object
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 |
#password ⇒ Object
Returns the value of attribute password.
2 3 4 |
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 2 def password @password end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 3 def session @session end |
#user ⇒ Object
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
#balance ⇒ Object
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.account_number}") # 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_mutuos ⇒ Object
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_session ⇒ Object
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 |
#transactions ⇒ Object
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 |
#url ⇒ Object
20 21 22 |
# File 'lib/cartolify/banks/chileempresas_bank.rb', line 20 def url URL end |