class Ubcbooker::Scraper::BaseScraper
Public Class Methods
new(username, password)
click to toggle source
# File lib/ubcbooker/scrapers/base_scraper.rb, line 4 def initialize(username, password) @agent = Mechanize.new do |agent| agent.user_agent_alias = "Linux Mozilla" end @username = username @password = password end
Public Instance Methods
is_logged_in(page)
click to toggle source
# File lib/ubcbooker/scrapers/base_scraper.rb, line 12 def is_logged_in(page) page_body = Nokogiri::HTML(page.body) login_status_text = page_body.css("p").first.text return !login_status_text.include?("Login Failed") end
login_ubc_cwl(login_page)
click to toggle source
Do login for UBC CWL system
# File lib/ubcbooker/scrapers/base_scraper.rb, line 28 def login_ubc_cwl(login_page) begin after_login_page = populate_account_info(login_page) if is_logged_in(after_login_page) return after_login_page else raise Ubcbooker::Error::LoginFailed end rescue Ubcbooker::Error::LoginFailed => e puts e.message exit(1) end end
populate_account_info(login_page)
click to toggle source
# File lib/ubcbooker/scrapers/base_scraper.rb, line 18 def populate_account_info(login_page) username_feild = login_page.form.field_with(name: "j_username") username_feild.value = @username password_field = login_page.form.field_with(name: "j_password") password_field.value = @password redirect_page = login_page.form.submit return redirect_page.form.submit end