Class: Loginator::Response

Inherits:
Struct
  • Object
show all
Includes:
JsonableStruct, Transaction
Defined in:
lib/loginator/response.rb

Overview

A Response is a response to a Request. It should include the same elements as a request, plus the status of the response (an indicator if the API request was successful or not) as well as an optional response body. Whether or not to log the response is entirely left up to implementation decisions and production log volume considerations. It is trivial to log response bodies in development, but not in production.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Transaction

#format_time, #uuid

Methods included from JsonableStruct

included, #to_json

Constructor Details

#initialize(request_id = uuid, timestamp = format_time, path = nil, status = 0, body = '') ⇒ Response

Create a new Loginator::Response

Parameters:

  • request_id (String) (defaults to: uuid)

    (SecureRandom.uuid) Unique identifier for the request

  • timestamp (Float) (defaults to: format_time)

    (Time.now.utc.to_f) Time of the request

  • path (String) (defaults to: nil)

    (nil) Path associated with the request

  • status (Integer) (defaults to: 0)

    (0) Status returned to the requester

  • body (String) (defaults to: '')

    ({}) Parameters of the request



23
24
25
# File 'lib/loginator/response.rb', line 23

def initialize(request_id = uuid, timestamp = format_time, path = nil, status = 0, body = '')
  super
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



13
14
15
# File 'lib/loginator/response.rb', line 13

def body
  @body
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



13
14
15
# File 'lib/loginator/response.rb', line 13

def path
  @path
end

#request_idObject

Returns the value of attribute request_id

Returns:

  • (Object)

    the current value of request_id



13
14
15
# File 'lib/loginator/response.rb', line 13

def request_id
  @request_id
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



13
14
15
# File 'lib/loginator/response.rb', line 13

def status
  @status
end

#timestampObject

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



13
14
15
# File 'lib/loginator/response.rb', line 13

def timestamp
  @timestamp
end