Class: Equipoise::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/equipoise/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers:, body:) ⇒ Response

Returns a new instance of Response.



22
23
24
25
26
# File 'lib/equipoise/response.rb', line 22

def initialize(status:, headers:, body:)
  @status  = status
  @headers = headers || {}
  @body    = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



20
21
22
# File 'lib/equipoise/response.rb', line 20

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



20
21
22
# File 'lib/equipoise/response.rb', line 20

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



20
21
22
# File 'lib/equipoise/response.rb', line 20

def status
  @status
end

Instance Method Details

#dataObject

The envelope's data (Hash or Array). Falls back to the whole body when a response isn't enveloped (defensive — every documented 2xx is).



34
35
36
# File 'lib/equipoise/response.rb', line 34

def data
  body.is_a?(Hash) && body.key?("data") ? body["data"] : body
end

#metaObject



38
39
40
# File 'lib/equipoise/response.rb', line 38

def meta
  body.is_a?(Hash) ? (body["meta"] || {}) : {}
end

#retry_afterObject

Seconds to wait, from the Retry-After header or the legacy body field. Returns an Integer (or nil when neither is present / unparseable).



48
49
50
51
52
# File 'lib/equipoise/response.rb', line 48

def retry_after
  raw = headers["retry-after"]
  raw = body["retry_after"] if raw.to_s.empty? && body.is_a?(Hash)
  parse_retry_after(raw)
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/equipoise/response.rb', line 28

def success?
  (200..299).cover?(status)
end

#sync_statusObject



42
43
44
# File 'lib/equipoise/response.rb', line 42

def sync_status
  meta["sync_status"]
end