Class: FineAnts::Adapters::Betterment

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

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Betterment

Returns a new instance of Betterment.



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

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

Instance Method Details

#downloadObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fine_ants/adapters/betterment.rb', line 32

def download
  betterment_accounts = find("h2", text: "Betterment Accounts").
                        find(:xpath, "../..")
  accounts = betterment_accounts.all(".SummaryTable-card")
  accounts.map do ||
    {
      :adapter => :betterment,
      :user => @user,
      :id => id_for(),
      :name => name_for(),
      :amount => total_for()
    }
  end.tap do
    find('.sc-Nav-panelTrigger').click
    find('.sc-Nav-panelTrigger').click
    find('.sc-Nav-panelTrigger .SecondaryNavLogoutAction button', visible: false).click
  end
end

#loginObject



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

def 
  visit "https://wwws.betterment.com/app/login"
  fill_in "web_authentication[email]", :with => @user
  fill_in "web_authentication[password]", :with => @password
  click_button "Log in"
  begin
    find_field "web_second_factor_authentication[verification_code]"
    return false
  rescue Capybara::ElementNotFound
    verify_login!
    return true
  end
end

#two_factor_response(answer) ⇒ Object



25
26
27
28
29
30
# File 'lib/fine_ants/adapters/betterment.rb', line 25

def two_factor_response(answer)
  fill_in "web_second_factor_authentication[verification_code]", :with => answer
  find(".web_second_factor_authentication_trust_device").click
  click_button "Verify"
  verify_login!
end