Sha256: a9391d5beff65d453e921d4131f0dd712e9f3f340a02a48a4045c1d1c1936784

Contents?: true

Size: 723 Bytes

Versions: 2

Compression:

Stored size: 723 Bytes

Contents

require 'rubygems'
require 'json'
require 'hashie'

module Rapidash
  class Response

    class << self
      def new(response)
        return nil unless response.body
        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

2 entries across 2 versions & 1 rubygems

Version Path
rapidash-0.0.4 lib/rapidash/response.rb
rapidash-0.0.3 lib/rapidash/response.rb