Sha256: 01db74440f97a9404ba9216abaf703440c12c331220d8823408e07477d4838f0
Contents?: true
Size: 675 Bytes
Versions: 2
Compression:
Stored size: 675 Bytes
Contents
require 'json' require 'hashie' module Rapidash class Response class << self def new(response) return nil unless response.body type = response.headers["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: #{response.headers["content-type"]}") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rapidash-0.1.2 | lib/rapidash/response.rb |
rapidash-0.1.1 | lib/rapidash/response.rb |