Module: Krawler::Authentication

Included in:
Base
Defined in:
lib/krawler/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(agent, user, password, login_url) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/krawler/authentication.rb', line 5

def authenticate(agent, user, password, )
  agent.get() do |page|
     = page.form

    ['user[email]'] = user
    ['user[password]'] = password

    agent.submit(, .buttons.first)
  end
end

#use_authentication?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/krawler/authentication.rb', line 16

def use_authentication?
  !@username.nil? || !@password.nil? || !@login_url.nil?
end

#validate_authentication_optionsObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/krawler/authentication.rb', line 20

def validate_authentication_options
  any_nil = [@login_url, @username, @password].any? {|v| v.nil?}
  all_nil = [@login_url, @username, @password].all? {|v| v.nil?}
  if (any_nil && !all_nil)
    puts "You must either provide all authentication options" +
      " (username, password, and loginurl) or provide none."
    return false
  else
    return true
  end
end