Class: MyUW::Session
- Inherits:
-
Object
- Object
- MyUW::Session
- Defined in:
- lib/myuw/session.rb
Overview
Synopsis
This class encapsulates a MyUW session. It handles the login/logout of the MyUW portal.
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#myuw ⇒ Object
Returns the value of attribute myuw.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
-
#initialize(myuw = nil) ⇒ Session
constructor
A new instance of Session.
-
#logged_in? ⇒ Boolean
Checks if a user is logged in.
-
#login ⇒ Object
Logs a user in using the given email and password.
-
#logout ⇒ Object
Log out of the MyUW site.
Constructor Details
#initialize(myuw = nil) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 |
# File 'lib/myuw/session.rb', line 10 def initialize(myuw=nil) @myuw ||= myuw @email = @password = nil end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
7 8 9 |
# File 'lib/myuw/session.rb', line 7 def email @email end |
#myuw ⇒ Object
Returns the value of attribute myuw.
6 7 8 |
# File 'lib/myuw/session.rb', line 6 def myuw @myuw end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/myuw/session.rb', line 8 def password @password end |
Instance Method Details
#logged_in? ⇒ Boolean
Checks if a user is logged in. This method is actually pretty expensive in terms of time since it actually verifies by going to the MyUW homepage and seeing if the dashboard loads.
20 21 22 23 24 |
# File 'lib/myuw/session.rb', line 20 def logged_in? home = relay_page = home.form_with(:name => 'f').submit() !relay_page.search("span.greetingw").empty? end |
#login ⇒ Object
Logs a user in using the given email and password
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/myuw/session.rb', line 27 def login # Make sure that email and password are filled out or this is # useless if @email.nil? || @password.nil? raise ArgumentError.new("Email and password weren't specified for MyUW session") end # Log out first logout # Go to the MyUW page and get to the login form login_page = get_login_page login_form = login_page.form_with(:name => 'query') raise InvalidPageError.new(login_page, "Login form was not found on the MyUW page") if login_form.nil? login_form.user = @email login_form.pass = @password relay_page = login_form.submit() # Check if the login failed unless relay_page.form_with(:name => 'query').nil? return false end # Follow the relay follow_relay_page(relay_page) true end |
#logout ⇒ Object
Log out of the MyUW site
56 57 58 |
# File 'lib/myuw/session.rb', line 56 def logout @myuw.browser..clear! end |