Sha256: 21b194a3950b64ff8290dfe908b5082d27638585c828717d9396d171a3cf15a5

Contents?: true

Size: 704 Bytes

Versions: 3

Compression:

Stored size: 704 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"]
        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

3 entries across 3 versions & 1 rubygems

Version Path
rapidash-0.1.0 lib/rapidash/response.rb
rapidash-0.0.6 lib/rapidash/response.rb
rapidash-0.0.5 lib/rapidash/response.rb