Class: Openpix::RubySdk::ApiResponse
- Inherits:
-
Object
- Object
- Openpix::RubySdk::ApiResponse
- Defined in:
- lib/openpix/ruby_sdk/api_response.rb
Overview
An Object representing the response from a call to Woovi API
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #error_response ⇒ Object
-
#initialize(status:, body:, single_resource: nil, collection_resource: nil) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
- #pagination_meta ⇒ Object
- #resource_response ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, body:, single_resource: nil, collection_resource: nil) ⇒ ApiResponse
Returns a new instance of ApiResponse.
9 10 11 12 13 14 15 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 9 def initialize(status:, body:, single_resource: nil, collection_resource: nil) @success = status == 200 @status = status @body = body @single_resource = single_resource @collection_resource = collection_resource end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7 def status @status end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
7 8 9 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7 def success @success end |
Instance Method Details
#error_response ⇒ Object
27 28 29 30 31 32 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 27 def error_response return @body['error'] if @body['error'] return @body['errors'].first['message'] if @body['errors'] && !@body['errors'].empty? '' end |
#pagination_meta ⇒ Object
34 35 36 37 38 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 34 def return @body['pageInfo'] if @body['pageInfo'] {} end |
#resource_response ⇒ Object
21 22 23 24 25 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 21 def resource_response return @body[@single_resource] if @single_resource @body[@collection_resource] end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/openpix/ruby_sdk/api_response.rb', line 17 def success? success end |