Advertisement
saasbook

Another RESTful front end to crappy website

Oct 28th, 2013
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.33 KB | None | 0 0
  1.     user = 'USERNAME HERE'
  2.     pass = 'PASSWORD HERE'
  3.     security_answers = {
  4.       'What was the color of your first car?' => 'XXX',
  5.       'What was the name of your first boyfriend?' => 'XXX',
  6.       'What was the first bone you broke?' => 'XXX'
  7.     }
  8.     agent = Mechanize.new
  9.     login_form = agent.get('https://www.ucard.chase.com/').form_with(:name => 'form1')
  10.     login_form.userId = user
  11.     login_form.password = pass
  12.     result = agent.submit(login_form)
  13.     # if it forces us to validate security question, do so
  14.     if (security_question_form =
  15.         result.form_with(:action => '/authenticate_isSecurityAnswerValid.action'))
  16.       question =
  17.         result.parser.xpath('//td[@class="cdpLeftAlignedTdLabel"]').first.text.strip
  18.       security_question_form.securityAnswer = security_answers[question]
  19.       result = agent.submit(security_question_form)
  20.     end
  21.     # ok, now we should be on main login page
  22.     today = Date.today
  23.     # when will balance expire? on 10th of each month.
  24.     exp_month = if today.day < 10 then today.month else 1+today.month end
  25.     exp_date = Date.civil(today.year, exp_month, 10)
  26.     days_left = (exp_date - today).to_i
  27.     message = " will be forfeited on #{exp_date.strftime('%b %e')} (in #{days_left} days)"
  28.     html { (result.body =~ /\$\s*(\d+\.\d\d)/ ?  $1 : '???') + message }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement