Class: InstanceId::Response
- Inherits:
-
Object
- Object
- InstanceId::Response
- Defined in:
- lib/instance_id/response.rb,
lib/instance_id/response/delete.rb,
lib/instance_id/response/get_info.rb,
lib/instance_id/response/batch_operation.rb
Direct Known Subclasses
Defined Under Namespace
Classes: BatchOperation, Delete, GetInfo
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
- #body_json ⇒ Object
- #errors ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(status:, body: nil, headers: nil) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, body: nil, headers: nil) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 |
# File 'lib/instance_id/response.rb', line 10 def initialize(status:, body: nil, headers: nil) @status = status.to_i @body = body @headers = headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/instance_id/response.rb', line 7 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/instance_id/response.rb', line 8 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/instance_id/response.rb', line 6 def status @status end |
Instance Method Details
#body_json ⇒ Object
24 25 26 27 28 |
# File 'lib/instance_id/response.rb', line 24 def body_json parse_body.tap do |json| break json.key?(:error) ? nil : json end end |
#errors ⇒ Object
30 31 32 33 34 |
# File 'lib/instance_id/response.rb', line 30 def errors parse_body.tap do |json| break json.key?(:error) ? [json.slice(:error)] : [] end end |
#failure? ⇒ Boolean
20 21 22 |
# File 'lib/instance_id/response.rb', line 20 def failure? !success? end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/instance_id/response.rb', line 16 def success? @status.in? 200...400 end |