class

Responsible::Response

Inherits Reference / Object

Wrapper object for lifted responses. Provides extensions need for defining locally scoped error behaviors and parse tools for extraction of returned data.

Constructors

Creates a new Response by wrapping a supported response type. response must by a type that includes ResponsibleInterface. This can be inserted manually, or by using the Responsible.support macro.

Source

Instance methods

>>(x : T.class) : T forall T

Parses the contents of this response to the type x.

If x is nilable, a parser error will result in nil being returned, otherwise a Responsible::Error will be raised if parsing is not possible.

Source
on_client_error

Execute the passed block if this is a client_error response.

Source
on_informational

Execute the passed block if this is a informational response.

Source
on_redirection

Execute the passed block if this is a redirection response.

Source
on_server_error

Execute the passed block if this is a server_error response.

Source
on_success

Execute the passed block if this is a success response.

Source
parse_to(x : T.class, ignore_response_code = @in_handler, & : Exception -> U) : T | U forall T, U

Reads the contents of the body into the specified type x.

If the response cannot be parsed, the block will be yielded to to provide an alternative parser.

T.from_json must exist and be capable of deserializing a JSON string. This works out-of-the-box for most types where attributes map directly. The JSON::Serializable module provides tools for more complex parsing.

Source
parse_to(x : T.class, ignore_response_code = @in_handler) : T forall T

Parses the contents of this response to the type x, or raises an Responsible::Error if this is not possible.

Source
parse_to?(x : T.class, ignore_response_code = @in_handler) : T | Nil forall T

Parses the contents of this response to the type x, or nil if this is not possible.

Source

Macros

method_missing(call)
Source