Class: ADAL::TokenResponse

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/adal/token_response.rb

Overview

The return type of all of the instance methods that return tokens.

Direct Known Subclasses

ErrorResponse, SuccessResponse

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::DEFAULT_LOG_OUTPUT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger

Class Method Details

.parse(raw_response) ⇒ Object

Constructs a TokenResponse from a raw hash. It will return either a SuccessResponse or an ErrorResponse depending on the fields of the hash.

Parameters:

  • Hash

    raw_response The body of the HTTP response expressed as a raw hash.

Returns:

  • TokenResponse



42
43
44
45
46
47
48
49
50
51
# File 'lib/adal/token_response.rb', line 42

def self.parse(raw_response)
  logger.verbose('Attempting to create a TokenResponse from raw response.')
  if raw_response.nil?
    ErrorResponse.new
  elsif raw_response['error']
    ErrorResponse.new(JSON.parse(raw_response))
  else
    SuccessResponse.new(JSON.parse(raw_response))
  end
end

Instance Method Details

#error?Boolean

Shorthand for checking if a token response is successful or failed.

Returns:

  • (Boolean)

    Boolean



59
60
61
# File 'lib/adal/token_response.rb', line 59

def error?
  self.respond_to? :error
end