Class: Impostor::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/impostor/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Auth

Auth is initialized with the config of the impostor



10
11
12
13
# File 'lib/impostor/auth.rb', line 10

def initialize(config)
  @config = config
  self.extend eval("Impostor::#{config.type.to_s.capitalize}::Auth")
end

Instance Attribute Details

#authenticatedObject (readonly) Also known as: authenticated?

Returns the value of attribute authenticated.



4
5
6
# File 'lib/impostor/auth.rb', line 4

def authenticated
  @authenticated
end

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/impostor/auth.rb', line 3

def config
  @config
end

Instance Method Details

#fetch_login_pageObject

get the page for logging in



68
69
70
71
72
73
74
# File 'lib/impostor/auth.rb', line 68

def 
  begin
    self.config.agent.get(self.config.)
  rescue StandardError => err
    raise Impostor::LoginError.new(err)
  end
end

#get_login_form(page) ⇒ Object

returns the login form from the login page



79
80
81
# File 'lib/impostor/auth.rb', line 79

def (page)
  raise Impostor::MissingTemplateMethodError.new("get_login_form must be implemented")
end

#logged_in?(page) ⇒ Boolean

given the state of the page, are we logged in to the forum?

Returns:

  • (Boolean)

Raises:



61
62
63
# File 'lib/impostor/auth.rb', line 61

def logged_in?(page)
  raise Impostor::MissingTemplateMethodError.new("logged_in? must be implemented")
end

#loginObject

Login to the impostor’s forum. #login is comprised of the following template methods to allow implementation for specific forum applications:

  • fetch_login_page

  • logged_in?(page)

  • get_login_form(page)

  • set_username_and_password(form)

  • post_login(form)



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/impostor/auth.rb', line 25

def 
  return true if self.authenticated?

  page = self.
  return true if self.logged_in?(page)

  form = self.(page)
  self.set_username_and_password(form)
  page = self.(form)

  @authenticated = self.logged_in?(page)
end

#login_with_raisesObject



38
39
40
41
42
# File 'lib/impostor/auth.rb', line 38

def 
  return true if self.

  raise Impostor::LoginError.new("not logged in")
end

#logoutObject

logot of the impostor’s forum



47
48
49
50
51
52
53
54
55
56
# File 'lib/impostor/auth.rb', line 47

def logout
  return false unless self.authenticated?

  self.config.save_topics
  self.config.save_cookie_jar

  @authenticated = false

  not self.authenticated?
end

#post_login(form) ⇒ Object

does the work of posting the login form



93
94
95
96
97
98
99
100
# File 'lib/impostor/auth.rb', line 93

def (form)
  begin
    config.sleep_before_post
    page = form.submit
  rescue StandardError => err
    raise Impostor::LoginError.new(err)
  end
end

#set_username_and_password(form) ⇒ Object

Sets the user name and pass word on the loing form.



86
87
88
# File 'lib/impostor/auth.rb', line 86

def set_username_and_password(form)
  raise Impostor::MissingTemplateMethodError.new("set_username_and_password must be implemented")
end