Sha256: a2561df931fb3993035f94e5c3fadd1c7fad4b91442ed404ae65db01d970dbbd

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 Bytes

Contents

require 'json'
require 'hashie'

module Rapidash
  class Response

    class << self
      def new(response)
        type = response.headers["content-type"]
        if type.include?("application/json")
          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
        else
          raise ParseError.new("Cannot parse content type: #{response.headers["content-type"]}")
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapidash-0.0.1 lib/rapidash/response.rb