Module: Krawler::Authentication
- Included in:
- Base
- Defined in:
- lib/krawler/authentication.rb
Instance Method Summary collapse
- #authenticate(agent, user, password, login_url) ⇒ Object
- #use_authentication? ⇒ Boolean
- #validate_authentication_options ⇒ Object
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, login_url) agent.get(login_url) do |page| login_form = page.form login_form['user[email]'] = user login_form['user[password]'] = password agent.submit(login_form, login_form..first) end end |
#use_authentication? ⇒ Boolean
16 17 18 |
# File 'lib/krawler/authentication.rb', line 16 def use_authentication? !@username.nil? || !@password.nil? || !@login_url.nil? end |
#validate_authentication_options ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/krawler/authentication.rb', line 20 def 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 |