Class: FineAnts::Adapters::Amex

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

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Amex

Returns a new instance of Amex.



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

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

Instance Method Details

#downloadObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fine_ants/adapters/amex.rb', line 22

def download
  visit "https://global.americanexpress.com/accounts"
  find(".card-block")
  all(".card-block > div").map do ||
    name = .find(".card > .pad > .heading-3").text
    owed = .text.include?("Total Balance")
    {
      adapter: :amex,
      user: @user,
      id: name,
      name: name,
      amount: -1 * BigDecimal(if owed
                     .all("table td:nth-child(2) span").first.text.gsub(/[\$,]/, "")
                   else
                     "0"
                              end)
    }
  end
end

#loginObject



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

def 
  visit "https://www.americanexpress.com"
  form_css = find("form")[:id] == "ssoform" ? "#ssoform" : ".eliloMain"
  within form_css do
    fill_in "User ID", with: @user
    fill_in "Password", with: @password
    click_thing "Log In"
  end
  verify_login!
end