Class: BatchApi::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#bodyObject

Public: the attributes of the HTTP response.



7
8
9
# File 'lib/batch_api/response.rb', line 7

def body
  @body
end

#headersObject

Public: the attributes of the HTTP response.



7
8
9
# File 'lib/batch_api/response.rb', line 7

def headers
  @headers
end

#statusObject

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(options = {})
  {}.tap do |result|
    result[:body] = @body unless @body.nil?
    result[:headers] = @headers unless @headers.nil?
    result[:status] = @status unless @status.nil?
  end
end