Sha256: 3302e1578a1bb4fea39a650b2ce5a5221fc6e4f5af965a3f9cc8d44de8ef0978

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

require 'yajl'

module Her
  module Model
    # remove deprecated data method since cassinatra returns data: []
    module DeprecatedMethods
      remove_method :data
      remove_method :data=
    end
  end
  module Middleware
    class ParseJSON < Faraday::Response::Middleware
      # @private
      def parse_json(body = nil)
        body ||= '{}'
        message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"

        json = begin
          Yajl.load(body, :symbolize_keys => true)
        rescue MultiJson::LoadError
          raise Her::Errors::ParseError, message
        end

        raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)

        json
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
quandl_client-0.0.13 lib/quandl/her/patch.rb
quandl_client-0.0.12 lib/quandl/her/patch.rb
quandl_cassinatra-0.0.6 lib/quandl/her/patch.rb