Class: BatchApi::Response
- Inherits:
-
Object
- Object
- BatchApi::Response
- Defined in:
- lib/batch_api/response.rb
Overview
Public: a response from an internal operation in the Batch API. It contains all the details that are needed to describe the call’s outcome.
Instance Attribute Summary collapse
-
#body ⇒ Object
Public: the attributes of the HTTP response.
-
#headers ⇒ Object
Public: the attributes of the HTTP response.
-
#status ⇒ Object
Public: the attributes of the HTTP response.
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Object
Public: convert the response to JSON.
-
#initialize(response) ⇒ Response
constructor
Public: create a new response representation from a Rack-compatible response (e.g. [status, headers, response_object]).
Constructor Details
#initialize(response) ⇒ Response
Public: create a new response representation from a Rack-compatible response (e.g. [status, headers, response_object]).
11 12 13 14 |
# File 'lib/batch_api/response.rb', line 11 def initialize(response) @status, @headers = *response @body = process_body(response[2]) end |
Instance Attribute Details
#body ⇒ Object
Public: the attributes of the HTTP response.
7 8 9 |
# File 'lib/batch_api/response.rb', line 7 def body @body end |
#headers ⇒ Object
Public: the attributes of the HTTP response.
7 8 9 |
# File 'lib/batch_api/response.rb', line 7 def headers @headers end |
#status ⇒ Object
Public: the attributes of the HTTP response.
7 8 9 |
# File 'lib/batch_api/response.rb', line 7 def status @status end |
Instance Method Details
#as_json(options = {}) ⇒ Object
Public: convert the response to JSON. nil values are ignored.
17 18 19 20 21 22 23 |
# File 'lib/batch_api/response.rb', line 17 def as_json( = {}) {}.tap do |result| result[:body] = @body unless @body.nil? result[:headers] = @headers unless @headers.nil? result[:status] = @status unless @status.nil? end end |