class Blanket::Response
The Response
class wraps HTTP responses
Attributes
payload[R]
Attribute reader for the original JSON payload string
Public Class Methods
new(json_string)
click to toggle source
A Blanket
HTTP response wrapper. @param [String] json_string A string containing data in the JSON format @return [Blanket::Response] The wrapped Response
object
# File lib/blanket/response.rb, line 14 def initialize(json_string) json_string ||= "{}" @payload = payload_from_json(JSON.parse(json_string)) end
Private Instance Methods
method_missing(method, *args, &block)
click to toggle source
Allows accessing the payload’s JSON keys through methods.
Calls superclass method
# File lib/blanket/response.rb, line 22 def method_missing(method, *args, &block) if payload.respond_to? method payload.public_send method, *args, &block else super end end
payload_from_json(json)
click to toggle source
# File lib/blanket/response.rb, line 30 def payload_from_json(json) parsed = [json].flatten.map do |item| RecursiveOpenStruct.new item, recurse_over_arrays: true end (json.is_a? Array) ? parsed : parsed.first end