Class: Request::Response
- Inherits:
-
Object
- Object
- Request::Response
- Defined in:
- lib/request/resources/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status, body) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #struct(value = json) ⇒ Object
Constructor Details
#initialize(status, body) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 |
# File 'lib/request/resources/response.rb', line 7 def initialize(status, body) @status = Integer(status) @body = body @body = struct(json) unless @body.nil? || @body.empty? end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/request/resources/response.rb', line 5 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/request/resources/response.rb', line 5 def status @status end |
Instance Method Details
#json ⇒ Object
13 14 15 |
# File 'lib/request/resources/response.rb', line 13 def json JSON.parse(@body) end |
#struct(value = json) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/request/resources/response.rb', line 17 def struct(value = json) if value.is_a?(Hash) OpenStruct.new(value.transform_values { |v| struct(v) }) elsif value.is_a?(Array) value.map { |v| struct(v) } else value end end |