Class: FineAnts::Adapters::Schwab

Inherits:
Object
  • Object
show all
Defined in:
lib/fine_ants/adapters/schwab.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Schwab

Returns a new instance of Schwab.



6
7
8
9
# File 'lib/fine_ants/adapters/schwab.rb', line 6

def initialize(credentials)
  @user = credentials[:user]
  @password = credentials[:password]
end

Instance Method Details

#downloadObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fine_ants/adapters/schwab.rb', line 35

def download
  rows = all(".account-row")
  rows.map { |row|
    {
      adapter: :schwab,
      user: @user,
      id: row.all(".account.number").first.text.strip,
      name: row.all(".nickName-wrapper").first.text.strip,
      amount: BigDecimal(row.all(".balance-container-cs .values-wrapper").first.text.match(/\$(.*)$/)[1].delete(","))
    }
  }.tap { click_button "Log Out" }
end

#loginObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fine_ants/adapters/schwab.rb', line 11

def 
  visit "https://client.schwab.com/Login/SignOn/CustomerCenterLogin.aspx"
  within_frame 'lmsSecondaryLogin' do
    fill_in "loginIdInput", with: @user
    fill_in "passwordInput", with: @password
    select "Accounts Summary", from: "landingPageOptions"
    click_button "btnLogin"
  end

  begin
    find("#otp_sms").click
    false
  rescue Capybara::ElementNotFound
    verify_login!
    true
  end
end

#two_factor_response(answer) ⇒ Object



29
30
31
32
33
# File 'lib/fine_ants/adapters/schwab.rb', line 29

def two_factor_response(answer)
  fill_in "securityCode", with: answer
  click_button "continueButton"
  verify_login!
end