Class: Ubcbooker::Scraper::BaseScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/ubcbooker/scrapers/base_scraper.rb

Direct Known Subclasses

Cs

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ BaseScraper

Returns a new instance of BaseScraper.



4
5
6
7
8
9
10
# 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

Instance Method Details

#is_logged_in(page) ⇒ Object



12
13
14
15
16
# File 'lib/ubcbooker/scrapers/base_scraper.rb', line 12

def is_logged_in(page)
  page_body = Nokogiri::HTML(page.body)
   = page_body.css("p").first.text
  return !.include?("Login Failed")
end

#login_ubc_cwl(login_page) ⇒ Object

Do login for UBC CWL system



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ubcbooker/scrapers/base_scraper.rb', line 28

def ()
  begin
     = ()
    if is_logged_in()
      return 
    else
      raise Ubcbooker::Error::LoginFailed
    end
  rescue Ubcbooker::Error::LoginFailed => e
    puts e.message
    exit(1)
  end
end

#populate_account_info(login_page) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ubcbooker/scrapers/base_scraper.rb', line 18

def ()
  username_feild = .form.field_with(name: "j_username")
  username_feild.value = @username
  password_field = .form.field_with(name: "j_password")
  password_field.value = @password
  redirect_page = .form.submit
  return redirect_page.form.submit
end