module Nearmiss::Authentication

Authentication methods for {Nearmiss::Client}

Public Instance Methods

basic_authenticated?() click to toggle source

Indicates if the client was supplied Basic Auth username and password

@see @return [Boolean]

# File lib/nearmiss-ruby/authentication.rb, line 11
def basic_authenticated?
  !!(@email && @password)
end
login()
Alias for: sign_in
logout()
Alias for: sign_out
sign_in() click to toggle source
# 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
Also aliased as: login
sign_out() click to toggle source

Closes the current active session by expiring the ticket.

# File lib/nearmiss-ruby/authentication.rb, line 45
def sign_out
  post "api/logout"
  @me = nil
end
Also aliased as: logout
signed_in?() click to toggle source

Check is a user is currently signed in.

@return [Boolean]

# File lib/nearmiss-ruby/authentication.rb, line 54
def signed_in?
  !!@me
end
token_authenticated?() click to toggle source

Indicates if the client was supplied an OAuth access token

@see @return [Boolean]

# File lib/nearmiss-ruby/authentication.rb, line 20
def token_authenticated?
  !!@access_token
end
update_headers(headers) click to toggle source
# 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