Class: FineAnts::Adapters::Vanguard

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

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Vanguard

Returns a new instance of Vanguard.



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

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

Instance Method Details

#downloadObject



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

def download
  rows = find("[id='BalancesTabBoxId:balancesForm:balancesTable']").all("tr:not([tbodyid])")
  rows.map { |row|
    cells = row.all("td")
    {
      adapter: :vanguard,
      user: @user,
      id: cells.first.all("a").first[:href].match(/.*#(.*)$/)[1],
      name: cells.first.text,
      amount: BigDecimal(cells.last.text.match(/\$(.*)$/)[1].delete(","))
    }
  }.tap { click_link "Log off" }
end

#loginObject



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

def 
  visit "https://personal.vanguard.com/us/hnwnesc/nesc/LoginPage"
  fill_in "LoginForm:USER", with: @user
  sleep 0.2
  fill_in "LoginForm:PASSWORD-blocked", with: @password
  click_button "LoginForm:submitInput"
  begin
    find_field "LoginForm:ANSWER"
    false
  rescue Capybara::ElementNotFound
    verify_login!
    true
  end
end

#two_factor_response(answer) ⇒ Object



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

def two_factor_response(answer)
  fill_in "LoginForm:ANSWER", with: answer
  choose "LoginForm:DEVICE:0"
  click_button "LoginForm:ContinueInput"
  verify_login!
end