DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

American Express OFX Downloader

Snippets Manager user avatar by
Snippets Manager
·
Mar. 12, 09 · · Code Snippet
Like (0)
Save
Tweet
686 Views

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.

Popular on DZone

  • SDLC Vs STLC: What's the Difference?
  • How To Integrate Third-Party Login Systems in Your Web App Using OAuth 2.0
  • Top Six Kubernetes Best Practices for Fleet Management
  • Application Scalability — How To Do Efficient Scaling

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo