Sha256: 1ebb6247894f5e878ee328a2202bdadb5c9cce1cbc45d02968ae215cb9ab1d37

Contents?: true

Size: 683 Bytes

Versions: 1

Compression:

Stored size: 683 Bytes

Contents

require 'rubygems'
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.2 lib/rapidash/response.rb