Class: Esplanade::Response::Raw::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/esplanade/response/raw/body.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, raw_response, raw_body) ⇒ Body

Returns a new instance of 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_hashObject



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(**message)
end

#to_stringObject



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