module FmRest::V1::Auth

Constants

ACCESS_TOKEN_HEADER

Public Instance Methods

request_auth_token(connection = FmRest::V1.auth_connection) click to toggle source

Requests a token through basic auth

@param connection [Faraday] the auth connection to use for

the request

@return The token if successful @return `false` if authentication failed

# File lib/fmrest/v1/auth.rb, line 14
def request_auth_token(connection = FmRest::V1.auth_connection)
  request_auth_token!(connection)
rescue FmRest::APIError::AccountError
  false
end
request_auth_token!(connection = FmRest.V1.auth_connection) click to toggle source

Requests a token through basic auth, raising `FmRest::APIError::AccountError` if auth fails

@param (see request_auth_token) @return The token if successful @raise [FmRest::APIError::AccountError] if authentication failed

# File lib/fmrest/v1/auth.rb, line 26
def request_auth_token!(connection = FmRest.V1.auth_connection)
  resp = connection.post(V1.session_path)
  resp.headers[ACCESS_TOKEN_HEADER] || resp.body["response"]["token"]
end