class Dinero::Bank::CapitalOne360
Constants
- ACCOUNTS_SUMMARY_URL
- LOGIN_URL
Public Instance Methods
accounts()
click to toggle source
extract account data from the account summary page
# File lib/dinero/banks/capital_one_360.rb, line 87 def accounts return @accounts if @accounts @accounts = [] begin # lots of spaces, tabs and the #00A0 characters, so extract # text with this extraneous junk suppressed. tables = accounts_summary_document.xpath("//table") account_tables = tables.map do |table| rows = table.xpath(".//tr").map{|row| row.xpath(".//td|.//th"). map{|cell| cell.text.strip.gsub(/\s+|\t/, " ")}} end.reject{|table| promo_table? table } # Turn tablular data into Account classes account_tables.map do |table| # the header row tells us what kind of account we're looking at header = table.shift account_type = decipher_account_type header[0] has_account_number = header[1] =~ /Account/ # ignore balance rows at bottom of tables rows = table.reject{|row| balance_row? row } # turn those rows into accounts rows.each do |row| name = sanitize(row.shift) number = (has_account_number ? sanitize(row.shift) : nil) if number.nil? || name =~ /(\.{4})(\d+)\Z/ number = name.match(/(\.{4})(\d+)\Z/).captures.join name = name.gsub(number,'') end balance = row.shift available = row.shift || balance @accounts << Account.new(account_type, name, number, balance, available) end end rescue Exception => error connection.save_screenshot('log/accounts.png') error.backtrace.each { |line| puts line } raise end return @accounts end
accounts_summary_page_fully_loaded?()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 49 def accounts_summary_page_fully_loaded? tables = connection.find_elements css: 'table' !(tables.empty? or tables.detect{|t| t.text =~ /\sLoading/}) rescue Selenium::WebDriver::Error::StaleElementReferenceError => error false end
balance_row?(row)
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 66 def balance_row? row row[1] =~ /Total/ end
decipher_account_type(title)
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 74 def decipher_account_type title return :credit_card if title =~ /Credit Cards/ return :brokerage if title =~ /Investing/ return :bank if title =~ /Checking/ return :unknown end
default_options()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 7 def default_options { login_url: LOGIN_URL } end
goto_accounts_summary_page()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 60 def goto_accounts_summary_page return if authenticated? && on_accounts_summary_page? authenticated? ? connection.navigate.to(ACCOUNTS_SUMMARY_URL) : login! wait.until { accounts_summary_page_fully_loaded? } end
on_accounts_summary_page?()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 56 def on_accounts_summary_page? connection.current_url == ACCOUNTS_SUMMARY_URL end
post_credentials!()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 44 def post_credentials! post_username! post_password! end
post_password!()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 27 def post_password! begin wait.until { connection.find_element(id: "PasswordForm").displayed? } rescue connection.save_screenshot('log/capital_one_360_password_failed.png') raise end password_form = connection.find_element(id: "PasswordForm") password_field = connection.find_element(id: "currentPassword_TLNPI") submit_button = connection.find_element :css, ".bluebutton > a:nth-child(1)" raise "Password Form not reached!" unless password_field && password_form password_field.send_keys password submit_button.click end
post_username!()
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 11 def post_username! begin wait.until { connection.find_element(id: "Signin").displayed? } rescue connection.save_screenshot('log/capital_one_360_signin_failed.png') raise end signin_form = connection.find_element(id: "Signin") username_field = connection.find_element(id: "ACNID") raise "Sign in Form not reached!" unless username_field && signin_form username_field.send_keys username signin_form.submit end
promo_table?(table)
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 70 def promo_table? table table.empty? or table[0].empty? or table[0][0].empty? end
sanitize(value)
click to toggle source
# File lib/dinero/banks/capital_one_360.rb, line 81 def sanitize value return unless value value.split("\u00A0").first.strip end