Class: Cookie::Models::BaseResponse Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/cookie/models/base_response.rb

Overview

This class is abstract.

Subclass and add attributes specific to the endpoint

Base class for API responses that provides error checking capabilities

Direct Known Subclasses

LoginResponse, OrderResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ BaseResponse

Returns a new instance of BaseResponse.

Parameters:

  • attributes (Hash)

    Raw response attributes from the API



22
23
24
25
26
27
# File 'lib/cookie/models/base_response.rb', line 22

def initialize(attributes)
  @type = attributes["type"]
  @error_code = attributes["errorCode"]
  @error_message = attributes["errorMessage"]
  @expired = attributes["expired"] || false
end

Instance Attribute Details

#error_codeString? (readonly)

Returns Error code if present.

Returns:

  • (String, nil)

    Error code if present



13
14
15
# File 'lib/cookie/models/base_response.rb', line 13

def error_code
  @error_code
end

#error_messageString? (readonly)

Returns Error message if present.

Returns:

  • (String, nil)

    Error message if present



16
17
18
# File 'lib/cookie/models/base_response.rb', line 16

def error_message
  @error_message
end

#expiredBoolean (readonly)

Returns Whether the session is expired.

Returns:

  • (Boolean)

    Whether the session is expired



19
20
21
# File 'lib/cookie/models/base_response.rb', line 19

def expired
  @expired
end

#typeString (readonly)

Returns The type of response from the API.

Returns:

  • (String)

    The type of response from the API



10
11
12
# File 'lib/cookie/models/base_response.rb', line 10

def type
  @type
end

Instance Method Details

#authentication_error?Boolean

Returns Whether the error is an authentication error.

Returns:

  • (Boolean)

    Whether the error is an authentication error



35
36
37
# File 'lib/cookie/models/base_response.rb', line 35

def authentication_error?
  error? && error_code == "500"
end

#error?Boolean

Returns Whether the response contains an error.

Returns:

  • (Boolean)

    Whether the response contains an error



30
31
32
# File 'lib/cookie/models/base_response.rb', line 30

def error?
  !!(error_code && !error_code.empty?)
end