Class: Blanket::Response
- Inherits:
-
Object
- Object
- Blanket::Response
- Defined in:
- lib/blanket/response.rb
Overview
The Response class wraps HTTP responses
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Attribute reader for the original JSON payload string.
Instance Method Summary collapse
-
#initialize(json_string) ⇒ Blanket::Response
constructor
A Blanket HTTP response wrapper.
Constructor Details
#initialize(json_string) ⇒ Blanket::Response
A Blanket HTTP response wrapper.
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
#payload ⇒ Object (readonly)
Attribute reader for the original JSON payload string
9 10 11 |
# File 'lib/blanket/response.rb', line 9 def payload @payload end |