class Apia::Response
Attributes
body[W]
fields[R]
headers[R]
status[RW]
Public Class Methods
new(request, endpoint)
click to toggle source
# File lib/apia/response.rb, line 14 def initialize(request, endpoint) @request = request @endpoint = endpoint @status = @endpoint.definition.http_status_code @fields = {} @headers = {} end
Public Instance Methods
add_field(name, value)
click to toggle source
Add a field value for this endpoint
@param name [Symbol] @param value [Hash, Object
, nil] @return [void]
# File lib/apia/response.rb, line 28 def add_field(name, value) @fields[name.to_sym] = value end
add_header(name, value)
click to toggle source
Add a header to the response
@param name [String] @param value [String] @return [void]
# File lib/apia/response.rb, line 37 def add_header(name, value) @headers[name.to_s] = value&.to_s end
body()
click to toggle source
Return the body that should be returned for this response
@return [Hash]
# File lib/apia/response.rb, line 52 def body @body || hash end
hash()
click to toggle source
Return the full hash of data that should be returned for this request.
@return [Hash]
# File lib/apia/response.rb, line 45 def hash @hash ||= @endpoint.definition.fields.generate_hash(@fields, request: @request) end
rack_triplet()
click to toggle source
Return the rack triplet for this response
@return [Array]
# File lib/apia/response.rb, line 59 def rack_triplet Rack.json_triplet(body, headers: @headers, status: @status) end