Class: Jiralicious::CookieSession
- Defined in:
- lib/jiralicious/cookie_session.rb
Overview
The CookieSesssion class extends the Session class with the functionality of utilizing cookies for authorization management.
- Deprecated
-
CookieSession is deprecated as of version 0.2.0
Instance Attribute Summary collapse
-
#authenticating ⇒ Object
Adds attributes to the CookieSession.
-
#login_info ⇒ Object
Adds attributes to the CookieSession.
-
#session ⇒ Object
Adds attributes to the CookieSession.
Instance Method Summary collapse
-
#after_request(response) ⇒ Object
Handles the response from the request.
-
#alive? ⇒ Boolean
Checks to see if session is active.
-
#before_request ⇒ Object
Provides login information on every request.
-
#login ⇒ Object
Authenticates the login.
-
#logout ⇒ Object
Logs out of the API.
Methods inherited from Session
Instance Attribute Details
#authenticating ⇒ Object
Adds attributes to the CookieSession
11 12 13 |
# File 'lib/jiralicious/cookie_session.rb', line 11 def authenticating @authenticating end |
#login_info ⇒ Object
Adds attributes to the CookieSession
11 12 13 |
# File 'lib/jiralicious/cookie_session.rb', line 11 def login_info @login_info end |
#session ⇒ Object
Adds attributes to the CookieSession
11 12 13 |
# File 'lib/jiralicious/cookie_session.rb', line 11 def session @session end |
Instance Method Details
#after_request(response) ⇒ Object
Handles the response from the request
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jiralicious/cookie_session.rb', line 24 def after_request(response) unless @authenticating if captcha_required(response) raise Jiralicious::CaptchaRequired. new("Captacha is required. Try logging into Jira via the web interface") elsif (response) # Can usually be fixed by logging in again clear_session raise Jiralicious::CookieExpired end end @authenticating = false end |
#alive? ⇒ Boolean
Checks to see if session is active
14 15 16 |
# File 'lib/jiralicious/cookie_session.rb', line 14 def alive? @session && @login_info end |
#before_request ⇒ Object
Provides login information on every request
19 20 21 |
# File 'lib/jiralicious/cookie_session.rb', line 19 def before_request self.login if require_login? && !@authenticating end |
#login ⇒ Object
Authenticates the login
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jiralicious/cookie_session.rb', line 39 def login @authenticating = true handler = Proc.new do |response| if response.code == 200 @session = response["session"] @login_info = response["loginInfo"] self.class.({self.session["name"] => self.session["value"]}) else clear_session case response.code when 401 then raise Jiralicious::InvalidLogin.new("Invalid login") when 403 raise Jiralicious::CaptchaRequired.new("Captacha is required. Try logging into Jira via the web interface") else # Give Net::HTTP reason raise Jiralicious::JiraError.new(response) end end end self.request(:post, '/rest/auth/latest/session', :body => { :username => Jiralicious.username, :password => Jiralicious.password}.to_json, :handler => handler) end |
#logout ⇒ Object
Logs out of the API
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jiralicious/cookie_session.rb', line 68 def logout handler = Proc.new do |request| if response.code == 204 clear_session else case response.code when 401 then raise Jiralicious::NotLoggedIn.new("Not logged in") else # Give Net::HTTP reason raise Jiralicious::JiraError.new(response) end end end request(:delete, '/rest/auth/latest/session', :handler => handler) end |