class GOVUK::Client::Response
An API response. This delegates to a hash containing the parsed response body. It also has methods for accessing the response metadata.
This is expected to represent a HTTP response with a JSON body, but in the case where the body is not JSON (eg for some error responses), this will delegate to an empty Hash. The raw response can then be accessed via the {#raw_body} accessor.
Attributes
code[R]
@return [Integer] The HTTP response code
raw_body[R]
@return [String] The raw HTTP response body
Public Class Methods
new(code, body_str)
click to toggle source
@param code [Integer] The http status code @param body_str [String] The JSON encoded response body.
Calls superclass method
# File lib/govuk/client/response.rb, line 18 def initialize(code, body_str) @code = code @raw_body = body_str super(MultiJson.load(@raw_body)) rescue MultiJson::ParseError # Delegate to empty hash so that this instance still quacks like a hash. super({}) end