Class: Esplanade::Response::Raw::Body
- Inherits:
-
Object
- Object
- Esplanade::Response::Raw::Body
- Defined in:
- lib/esplanade/response/raw/body.rb
Instance Method Summary collapse
-
#initialize(request, raw_response, raw_body) ⇒ Body
constructor
A new instance of Body.
- #to_hash ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(request, raw_response, raw_body) ⇒ Body
5 6 7 8 9 |
# File 'lib/esplanade/response/raw/body.rb', line 5 def initialize(request, raw_response, raw_body) @request = request @raw_response = raw_response @raw_body = raw_body end |
Instance Method Details
#to_hash ⇒ Object
16 17 18 19 20 |
# File 'lib/esplanade/response/raw/body.rb', line 16 def to_hash @hash ||= JSON.parse(to_string) rescue JSON::ParserError raise BodyIsNotJson.new(**) end |
#to_string ⇒ Object
11 12 13 14 |
# File 'lib/esplanade/response/raw/body.rb', line 11 def to_string @to_string ||= @raw_body.body rescue nil @to_string ||= @raw_body.first rescue nil end |