Advertisement
saasbook

Another RESTful front end to crappy website

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