class Dinero::Bank::CapitalOne

Constants

ACCOUNTS_SUMMARY_PATH
CONNECTION_TIMEOUT
LOGIN_URL

Public Instance Methods

accounts() click to toggle source

extract account data from the account summary page

# File lib/dinero/banks/capital_one.rb, line 53
def accounts
  return @accounts if @accounts

  # find the bricklet articles, which contains the balance data
  articles = accounts_summary_document.xpath("//article").
    select{|a| a.attributes["class"].value == "bricklet"}

  @accounts = articles.map do |article|
    prefix = article.attributes["id"].value.gsub("_bricklet", '')
    name = article.xpath(".//a[@class='product_desc_link']").text
    number = article.xpath(".//span[@id='#{prefix}_number']").text
    balance = article.xpath(".//span[@id='#{prefix}_current_balance_amount']").text
    available = first_numeric(article.xpath(".//div[@id='#{prefix}_available_credit_amount']").text)
    Account.new(:credit_card, name, number, balance, available)
  end
end
after_successful_login() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 32
def after_successful_login
  # the subdomain frequently changes, so capture the actual URL
  # so we can return to the page if necessary.
  @accounts_summary_url = connection.current_url
end
default_options() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 8
def default_options
  { timeout: CONNECTION_TIMEOUT, login_url: LOGIN_URL }
end
first_numeric(value) click to toggle source
# File lib/dinero/banks/capital_one.rb, line 48
def first_numeric value
  value.split("\n").reject{|r| r.empty?}.first
end
goto_accounts_summary_page() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 42
def goto_accounts_summary_page
  return if authenticated? && on_accounts_summary_page?
  authenticated? ? connection.navigate.to(@accounts_summary_url) : login!
  wait.until { connection.find_element(id: "main_content") }
end
on_accounts_summary_page?() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 38
def on_accounts_summary_page?
  URI(connection.current_url).path == ACCOUNTS_SUMMARY_PATH
end
post_credentials!() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 27
def post_credentials!
  post_username!
  post_password!
end
post_password!() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 19
def post_password!
  password_field = @signin_form.find_element(id: "password")
  password_field.send_keys password

  login_btn = @signin_form.find_element(id: "id-signin-submit")
  login_btn.click
end
post_username!() click to toggle source
# File lib/dinero/banks/capital_one.rb, line 12
def post_username!
  wait.until { connection.find_element(id: "id-signin-form") }
  @signin_form = connection.find_element(id: "id-signin-form")
  username_field = @signin_form.find_element(id: "username")
  username_field.send_keys username
end