Class: Dinero::Bank::CapitalOne

Inherits:
Base
  • Object
show all
Defined in:
lib/dinero/banks/capital_one.rb

Constant Summary collapse

LOGIN_URL =
"https://verified.capitalone.com/sic-ui/#/esignin?Product=Card"
ACCOUNTS_SUMMARY_PATH =
"/accounts/"
CONNECTION_TIMEOUT =
30

Instance Attribute Summary

Attributes inherited from Base

#login_url, #password, #security_questions, #timeout, #username

Instance Method Summary collapse

Methods inherited from Base

#accounts_summary_document, #authenticated?, #class_name, #connection, #establish_connection, #goto_login_page, #initialize, #login!, #screenshot_on_error, #snap, #validate!, #wait

Constructor Details

This class inherits a constructor from Dinero::Bank::Base

Instance Method Details

#accountsObject

extract account data from the account summary page



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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)
    .new(:credit_card, name, number, balance, available)
  end
end

#after_successful_loginObject



32
33
34
35
36
# File 'lib/dinero/banks/capital_one.rb', line 32

def 
  # 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_optionsObject



8
9
10
# File 'lib/dinero/banks/capital_one.rb', line 8

def default_options
  { timeout: CONNECTION_TIMEOUT, login_url:  }
end

#first_numeric(value) ⇒ Object



48
49
50
# 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_pageObject



42
43
44
45
46
# 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?Boolean

Returns:

  • (Boolean)


38
39
40
# 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!Object



27
28
29
30
# File 'lib/dinero/banks/capital_one.rb', line 27

def post_credentials!
  post_username!
  post_password!
end

#post_password!Object



19
20
21
22
23
24
25
# 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

   = @signin_form.find_element(id: "id-signin-submit")
  .click
end

#post_username!Object



12
13
14
15
16
17
# 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