7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rapidash/response.rb', line 7
def new(response)
return nil unless response.body
return nil if response.body.empty?
return nil if response.body == "null"
type = response.["content-type"]
body = JSON.parse(response.body)
if body.kind_of?(Hash)
return Hashie::Mash.new(body)
elsif body.kind_of?(Array)
output = []
body.each do |el|
output << Hashie::Mash.new(el)
end
return output
end
rescue JSON::ParserError => e
raise ParseError.new("Failed to parse content for type: #{type}")
end
|