Module: Nearmiss::Authentication
- Included in:
- Client
- Defined in:
- lib/nearmiss-ruby/authentication.rb
Overview
Authentication methods for Client
Instance Method Summary collapse
-
#basic_authenticated? ⇒ Boolean
Indicates if the client was supplied Basic Auth username and password.
- #sign_in ⇒ Object (also: #login)
-
#sign_out ⇒ Object
(also: #logout)
Closes the current active session by expiring the ticket.
-
#signed_in? ⇒ Boolean
Check is a user is currently signed in.
-
#token_authenticated? ⇒ Boolean
Indicates if the client was supplied an OAuth access token.
- #update_headers(headers) ⇒ Object
Instance Method Details
#basic_authenticated? ⇒ Boolean
Indicates if the client was supplied Basic Auth username and password
11 12 13 |
# File 'lib/nearmiss-ruby/authentication.rb', line 11 def basic_authenticated? !!(@email && @password) end |
#sign_in ⇒ Object Also known as: login
24 25 26 27 28 29 30 |
# File 'lib/nearmiss-ruby/authentication.rb', line 24 def sign_in response = post 'auth/sign_in', { email: @email, password: @password} update_headers(last_response.headers) reset_agent @me = response[:data] end |
#sign_out ⇒ Object Also known as: logout
Closes the current active session by expiring the ticket.
45 46 47 48 |
# File 'lib/nearmiss-ruby/authentication.rb', line 45 def sign_out post "api/logout" @me = nil end |
#signed_in? ⇒ Boolean
Check is a user is currently signed in.
54 55 56 |
# File 'lib/nearmiss-ruby/authentication.rb', line 54 def signed_in? !!@me end |
#token_authenticated? ⇒ Boolean
Indicates if the client was supplied an OAuth access token
20 21 22 |
# File 'lib/nearmiss-ruby/authentication.rb', line 20 def token_authenticated? !!@access_token end |
#update_headers(headers) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/nearmiss-ruby/authentication.rb', line 33 def update_headers(headers) # puts "update" # last_response.headers @client_id = headers["client"] @access_token = headers["access-token"] @expiry = headers["expiry"] @uid = headers["uid"] end |