Module: Nearmiss::Authentication

Included in:
Client
Defined in:
lib/nearmiss-ruby/authentication.rb

Overview

Authentication methods for Client

Instance Method Summary collapse

Instance Method Details

#basic_authenticated?Boolean

Indicates if the client was supplied Basic Auth username and password

Returns:

  • (Boolean)

See Also:



11
12
13
# File 'lib/nearmiss-ruby/authentication.rb', line 11

def basic_authenticated?
  !!(@email && @password)
end

#sign_inObject Also known as: login



24
25
26
27
28
29
30
# File 'lib/nearmiss-ruby/authentication.rb', line 24

def 

  response  = post 'auth/sign_in', { email: @email, password: @password}
  update_headers(last_response.headers)
  reset_agent
  @me       = response[:data]
end

#sign_outObject 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.

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)

See Also:



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