Sha256: e942652d18d65969266ed795a3662dbd1ceffa499a2c67d1dcba807a8e397dcc

Contents?: true

Size: 597 Bytes

Versions: 55

Compression:

Stored size: 597 Bytes

Contents

module Her
  module Middleware
    class ParseJSON < Faraday::Response::Middleware
      # @private
      def parse_json(body = nil)
        body = '{}' if body.blank?
        message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"

        json = begin
          MultiJson.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

55 entries across 55 versions & 4 rubygems

Version Path
test_track_rails_client-4.0.0.alpha12 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha11 vendor/gems/her/lib/her/middleware/parse_json.rb
her-0.10.4 lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha10 vendor/gems/her/lib/her/middleware/parse_json.rb
her-0.10.3 lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha9 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha8 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha7 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha6 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha5 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha4 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha3 vendor/gems/her/lib/her/middleware/parse_json.rb
her-0.10.2 lib/her/middleware/parse_json.rb
her-1.0.1 lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha2 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha1 vendor/gems/her/lib/her/middleware/parse_json.rb
her-1.0.0 lib/her/middleware/parse_json.rb
her-0.10.1 lib/her/middleware/parse_json.rb
test_track_rails_client-3.0.1 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-3.0.0 vendor/gems/her/lib/her/middleware/parse_json.rb