Class: BCIMobiBank
Constant Summary collapse
- URL =
"https://bci.mobi"
- LOGIN_FORM_NAME =
"loginform"
- BROWSER =
"Mac FireFox"
- START_URL =
"https://bci.mobi/supercartola.do"
Instance Attribute Summary collapse
-
#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
- #get_transactions ⇒ Object
-
#initialize(account = {}) ⇒ BCIMobiBank
constructor
A new instance of BCIMobiBank.
- #new_session ⇒ Object
- #url ⇒ Object
Methods inherited from Bank
Constructor Details
#initialize(account = {}) ⇒ BCIMobiBank
Returns a new instance of BCIMobiBank.
12 13 14 15 16 |
# File 'lib/cartolify/banks/bci_mobi_bank.rb', line 12 def initialize(account = {}) @user = account[:user] @password = account[:password] @session = new_session end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/cartolify/banks/bci_mobi_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_mobi_bank.rb', line 5 def session @session end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/cartolify/banks/bci_mobi_bank.rb', line 4 def user @user end |
Instance Method Details
#balance ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cartolify/banks/bci_mobi_bank.rb', line 22 def balance # We make sure we are on the first page session.get(START_URL) # The balance is in the 5 table, second tr, second td inside a div string_balance = session.page.root.css("table")[4].css("tr")[1].css("td")[1].children.text # Remove de $ simbol and the dots string_balance.gsub!(/[\$-.]/,'') # Return Integer string_balance.to_i end |
#get_transactions ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cartolify/banks/bci_mobi_bank.rb', line 33 def get_transactions transactions = [] # We go to the transactions page session.get(START_URL) # Go to transaction pages # 4 link, the first that reads "Más" session.page.links[3].click # Tables that hold the transactions, 3 tables per page tables = session.page.root.css("table")[5].css("tr")[1].css("td").css("table") tables.each do |table| h = { :date => table.css("tr")[0].css("td")[1].text, :description => table.css("tr")[1].css("td")[1].text, :serial => table.css("tr")[2].css("td")[1].text, :total => table.css("tr")[3].css("td")[1].text } transactions << h end transactions end |
#new_session ⇒ Object
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_mobi_bank.rb', line 54 def new_session agent = Mechanize.new agent.user_agent_alias=BROWSER agent.get(URL) form = agent.page.form(LOGIN_FORM_NAME) form.rut = self.user form.clave = self.password form.canal = "901" form.="targetSupercartola" form.submit agent if agent.page.root.css("table").first.css("h1").text.eql?("Autentificación Inválida") false elsif agent.page.root.css("table").first.css("h1").text.eql?("Clave bloqueada") false elsif agent.page.root.css("table").first.css("h1").text.eql?("Error desconocido.") false else agent end end |
#url ⇒ Object
18 19 20 |
# File 'lib/cartolify/banks/bci_mobi_bank.rb', line 18 def url URL end |