Class: Motivosity::Auth
- Inherits:
-
Object
- Object
- Motivosity::Auth
- Includes:
- HTTParty
- Defined in:
- lib/mvclient/auth.rb
Instance Method Summary collapse
- #auth_headers ⇒ Object
-
#initialize ⇒ Auth
constructor
A new instance of Auth.
- #login!(username, password) ⇒ Object
- #logout! ⇒ Object
- #process_response_headers(response) ⇒ Object
Constructor Details
#initialize ⇒ Auth
Returns a new instance of Auth.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mvclient/auth.rb', line 14 def initialize = File.("~/.motivosity-session") # make sure to create the cookie jar as read/write to current user only old_umask = File.umask(0177) begin @cookies = HTTP::CookieJar.new(store: :mozilla, filename: ) ensure File.umask(old_umask) end end |
Instance Method Details
#auth_headers ⇒ Object
47 48 49 |
# File 'lib/mvclient/auth.rb', line 47 def auth_headers { "Cookie" => HTTP::Cookie.(@cookies.) } end |
#login!(username, password) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mvclient/auth.rb', line 25 def login!(username, password) @cookies.clear response = self.class.post('/login.xhtml', { body: { "loginForm" => 'loginForm', "email" => username, "j_password" => password, "rememberMe" => 'on', "signInLink" => 'Sign In', "javax.faces.ViewState" => "3465473682371097839:-947621468971335341" } }) raise UnauthorizedError.new("invalid username or password") unless response.code == 302 process_response_headers(response) @cookies..length > 0 end |
#logout! ⇒ Object
42 43 44 45 |
# File 'lib/mvclient/auth.rb', line 42 def logout! @cookies.clear true end |
#process_response_headers(response) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/mvclient/auth.rb', line 51 def process_response_headers(response) (response.headers['Set-Cookie']).each do || @cookies.parse(, "https://www.motivosity.com/") do || .max_age ||= 604800 if .name == 'JSESSIONID' # force the gem to persist the session key (for one week) end end end |