Class: Blanket::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/blanket/response.rb

Overview

The Response class wraps HTTP responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_string) ⇒ Blanket::Response

A Blanket HTTP response wrapper.

Parameters:

  • json_string (String)

    A string containing data in the JSON format



14
15
16
17
# File 'lib/blanket/response.rb', line 14

def initialize(json_string)
  json_string ||= "{}"
  @payload = payload_from_json(JSON.parse(json_string))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Allows accessing the payload’s JSON keys through methods.



22
23
24
25
26
27
28
# 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

Instance Attribute Details

#payloadObject (readonly)

Attribute reader for the original JSON payload string



9
10
11
# File 'lib/blanket/response.rb', line 9

def payload
  @payload
end