Class: Dinero::Bank::CapitalOne360
- Inherits:
-
Base
- Object
- Base
- Dinero::Bank::CapitalOne360
show all
- Defined in:
- lib/dinero/banks/capital_one_360.rb
Constant Summary
collapse
- LOGIN_URL =
"https://secure.capitalone360.com/myaccount/banking/login.vm"
- ACCOUNTS_SUMMARY_URL =
"https://secure.capitalone360.com/myaccount/banking/account_summary.vm"
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, #after_successful_login, #authenticated?, #class_name, #connection, #establish_connection, #goto_login_page, #initialize, #login!, #screenshot_on_error, #snap, #validate!, #wait
Instance Method Details
#accounts ⇒ Object
extract account data from the account summary page
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/dinero/banks/capital_one_360.rb', line 87
def accounts
return @accounts if @accounts
@accounts = []
begin
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 }
account_tables.map do |table|
= table.shift
account_type = decipher_account_type [0]
has_account_number = [1] =~ /Account/
rows = table.reject{|row| balance_row? row }
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? ⇒ Boolean
49
50
51
52
53
54
|
# 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) ⇒ Boolean
66
67
68
|
# File 'lib/dinero/banks/capital_one_360.rb', line 66
def balance_row? row
row[1] =~ /Total/
end
|
#decipher_account_type(title) ⇒ Object
74
75
76
77
78
79
|
# 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 ⇒ Object
7
8
9
|
# File 'lib/dinero/banks/capital_one_360.rb', line 7
def default_options
{ login_url: LOGIN_URL }
end
|
#goto_accounts_summary_page ⇒ Object
60
61
62
63
64
|
# 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? ⇒ Boolean
56
57
58
|
# File 'lib/dinero/banks/capital_one_360.rb', line 56
def on_accounts_summary_page?
connection.current_url == ACCOUNTS_SUMMARY_URL
end
|
#post_credentials! ⇒ Object
44
45
46
47
|
# File 'lib/dinero/banks/capital_one_360.rb', line 44
def post_credentials!
post_username!
post_password!
end
|
#post_password! ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# 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! ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# 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
|
70
71
72
|
# 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) ⇒ Object
81
82
83
84
|
# File 'lib/dinero/banks/capital_one_360.rb', line 81
def sanitize value
return unless value
value.split("\u00A0").first.strip
end
|