Class: Equipoise::Response
- Inherits:
-
Object
- Object
- Equipoise::Response
- Defined in:
- lib/equipoise/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#data ⇒ Object
The envelope's
data(Hash or Array). -
#initialize(status:, headers:, body:) ⇒ Response
constructor
A new instance of Response.
- #meta ⇒ Object
-
#retry_after ⇒ Object
Seconds to wait, from the Retry-After header or the legacy body field.
- #success? ⇒ Boolean
- #sync_status ⇒ Object
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
20 21 22 |
# File 'lib/equipoise/response.rb', line 20 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
20 21 22 |
# File 'lib/equipoise/response.rb', line 20 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
20 21 22 |
# File 'lib/equipoise/response.rb', line 20 def status @status end |
Instance Method Details
#data ⇒ Object
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 |
#meta ⇒ Object
38 39 40 |
# File 'lib/equipoise/response.rb', line 38 def body.is_a?(Hash) ? (body["meta"] || {}) : {} end |
#retry_after ⇒ Object
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
28 29 30 |
# File 'lib/equipoise/response.rb', line 28 def success? (200..299).cover?(status) end |
#sync_status ⇒ Object
42 43 44 |
# File 'lib/equipoise/response.rb', line 42 def sync_status ["sync_status"] end |