American Express OFX Downloader
Join the DZone community and get the full member experience.
Join For Free// description of your code here
class AmexRobot
def initialize(username, password, opts={})
super(opts)
agent.keep_alive = false
page = request { agent.get "https://www99.americanexpress.com/myca/logon/us/en/en_US/logon/LogLogon.jsp?DestPage=https%3A%2F%2Fwww99.americanexpress.com%2Fmyca%2Facctsumm%2Fus%2Faction%3Frequest_type%3Dauthreg_acctAccountSummary%26Face%3Den_US" }
form = page.form('frmLogon')
form['UserID'] = username
form['Password'] = password
page = request { form.click_button }
unless page.uri.to_s == "https://www99.americanexpress.com/myca/acctsumm/us/action?request_type=authreg_acctAccountSummary&Face=en_US"
raise unknown_page(page)
end
end
def download(days_ago=nil)
page = request { agent.get "https://www99.americanexpress.com/myca/ofxdl/us/action?request_type=authreg_ofxdownload&Face=en_US&intlink=des_downloadcardact" }
form = page.form('downloadForm')
page = form.click_button(form.button('continueButton'))
form = page.form('downloadForm')
form['selAccNum0'] = 'on'
form['timeFrame0'] = 'downloadDates'
# This downloads items since last statement
form['cycleCut01'] = 'on'
## AMEX doesn't do dates, so we have to estimate
# These are the statements
form['cycleCut02'] = 'on' if days_ago > 10
form['cycleCut03'] = 'on' if days_ago > 40
form['cycleCut04'] = 'on' if days_ago > 70
form['cycleCut05'] = 'on' if days_ago > 100
output = form.click_button(form.button('downloadButton'))
if output.is_a?(WWW::Mechanize::File) && output.body.match(/DATA:OFXSGML/)
return output.body
else
raise unknown_page(output)
end
end
def request(time=1)
retryable(:on => StandardError, :times => 2) do
sleep time
yield
end
end
def agent
@agent ||= WWW::Mechanize.new {|a| a.log = logger }
end
end
Express
Opinions expressed by DZone contributors are their own.
Comments