Class: Dinero::Bank::Scottrade
- Inherits:
-
Base
- Object
- Base
- Dinero::Bank::Scottrade
show all
- Defined in:
- lib/dinero/banks/scottrade.rb
Overview
San Diego County Credit Union
Constant Summary
collapse
- LOGIN_URL =
"https://trading.scottrade.com/default.aspx"
- CONNECTION_TIMEOUT =
20
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, #find_answer, #goto_login_page, #initialize, #login!, #screenshot_on_error, #snap, #validate!, #wait
Instance Method Details
#accounts ⇒ Object
extract account data from the account summary page
113
114
115
116
|
# File 'lib/dinero/banks/scottrade.rb', line 113
def accounts
return @accounts if @accounts
@accounts = [ brokerage_account, bank_account ].compact
end
|
#after_successful_login ⇒ Object
53
54
55
56
57
|
# File 'lib/dinero/banks/scottrade.rb', line 53
def after_successful_login
@accounts_summary_url = connection.current_url
end
|
#bank_account ⇒ Object
106
107
108
109
110
|
# File 'lib/dinero/banks/scottrade.rb', line 106
def bank_account
if data = bank_data
Account.new :bank, "Bank", "", data[:balance], data[:available]
end
end
|
#bank_data ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/dinero/banks/scottrade.rb', line 97
def bank_data
rows = bank_table.xpath("tbody/tr").map{|tr| tr.xpath("td").map(&:text)}
available = rows.shift.last
balance = rows.shift.last
return { available: available, balance: balance }
rescue
return nil
end
|
#bank_table ⇒ Object
79
80
81
|
# File 'lib/dinero/banks/scottrade.rb', line 79
def bank_table
table = accounts_summary_document.css("#bankBalance66")
end
|
#brokerage_account ⇒ Object
92
93
94
95
|
# File 'lib/dinero/banks/scottrade.rb', line 92
def brokerage_account
data = brokerage_data
Account.new :brokerage, username, username, data[:balance], data[:available]
end
|
#brokerage_data ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/dinero/banks/scottrade.rb', line 83
def brokerage_data
rows = brokerage_table.xpath("tbody/tr").map{|tr| tr.xpath("td").map(&:text)}
available = rows.shift.last
rows.shift
rows.shift
balance = rows.shift.last
return { available: available, balance: balance }
end
|
#brokerage_table ⇒ Object
75
76
77
|
# File 'lib/dinero/banks/scottrade.rb', line 75
def brokerage_table
accounts_summary_document.css("#ctl00_PageContent_ctl02_w1_widgetContent1_tblBalanceElements66").first
end
|
#default_options ⇒ Object
8
9
10
|
# File 'lib/dinero/banks/scottrade.rb', line 8
def default_options
{ timeout: CONNECTION_TIMEOUT, login_url: LOGIN_URL }
end
|
#expand_bank_table ⇒ Object
68
69
70
71
72
73
|
# File 'lib/dinero/banks/scottrade.rb', line 68
def expand_bank_table
return unless connection.page_source =~ /ctl00_PageContent_ctl02_w1_widgetContent1_lblDisplayBankBalanceLink/
expand_link = connection.find_element(id: "ctl00_PageContent_ctl02_w1_widgetContent1_lblDisplayBankBalanceLink")
expand_link.click
wait.until { connection.find_element(id: "bankBalance66") }
end
|
#goto_accounts_summary_page ⇒ Object
63
64
65
66
|
# File 'lib/dinero/banks/scottrade.rb', line 63
def goto_accounts_summary_page
return if authenticated? && on_accounts_summary_page?
authenticated? ? connection.navigate.to(@accounts_summary_url) : login!
end
|
#on_accounts_summary_page? ⇒ Boolean
59
60
61
|
# File 'lib/dinero/banks/scottrade.rb', line 59
def on_accounts_summary_page?
connection.page_source =~ /Brokerage Balances/
end
|
#post_credentials! ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/dinero/banks/scottrade.rb', line 45
def post_credentials!
post_username!
post_password!
skip_confirmations_page
skip_monthly_statements_modal
expand_bank_table
end
|
#post_password! ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/dinero/banks/scottrade.rb', line 20
def post_password!
screenshot_on_error do
password_field = connection.find_element(id: "ctl00_body_txtPassword")
password_field.send_keys password
login_btn = connection.find_element(id: "ctl00_body_btnLogin")
login_btn.click
end
end
|
#post_username! ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/dinero/banks/scottrade.rb', line 12
def post_username!
screenshot_on_error do
wait.until { connection.find_element(id: "ctl00_body_txtAccountNumber") }
username_field = connection.find_element(id: "ctl00_body_txtAccountNumber")
username_field.send_keys username
end
end
|
#skip_confirmations_page ⇒ Object
30
31
32
33
34
35
|
# File 'lib/dinero/banks/scottrade.rb', line 30
def skip_confirmations_page
if connection.page_source =~ /has trade confirmations/
button = connection.find_element(id: "ctl00_body_btnViewLater")
button.click
end
end
|
#skip_monthly_statements_modal ⇒ Object
<button type=“button” class=“ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only” role=“button” aria-disabled=“false”><span class=“ui-button-text”>Close</span></button>
38
39
40
41
42
43
|
# File 'lib/dinero/banks/scottrade.rb', line 38
def skip_monthly_statements_modal
if connection.page_source =~ /ui\-dialog\-title\-monthlyStatementsDiv/
button = connection.find_element(xpath: "button[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only']")
button.click
end
end
|