class Martlet::Authenticator
Public Class Methods
new(agent)
click to toggle source
# File lib/martlet/authenticator.rb, line 5 def initialize(agent) @agent = agent end
Public Instance Methods
authenticate(email, password)
click to toggle source
# File lib/martlet/authenticator.rb, line 9 def authenticate(email, password) # Go to login page login_page = @agent.get(login_url) # Find and fill login form form = login_form(login_page) form['sid'] = email form['PIN'] = password submit_login_form(form) end
Private Instance Methods
login_form(page)
click to toggle source
# File lib/martlet/authenticator.rb, line 27 def login_form(page) if form = page.form('loginform1') form else raise AuthenticationError.new('Login form not found') end end
login_url()
click to toggle source
# File lib/martlet/authenticator.rb, line 23 def login_url 'https://horizon.mcgill.ca/pban1/twbkwbis.P_WWWLogin' end
submit_login_form(form)
click to toggle source
# File lib/martlet/authenticator.rb, line 35 def submit_login_form(form) page = form.submit body = page.body unless body.match(/Welcome,\+(.*),\+to\+Minerva/) if body.include?('Authorization Failure') raise AuthenticationError.new('Invalid email or password') else raise AuthenticationError.new('Authentication failed') end end end