Sha256: 11586a35f7dc3852ff5f3698c1ceecfa716941e8ba5d48987eac139ce74714ff

Contents?: true

Size: 598 Bytes

Versions: 38

Compression:

Stored size: 598 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) || json.is_a?(Array)

        json
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
test_track_rails_client-7.1.2 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-7.1.1 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-7.0.0 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-6.0.0 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-5.0.1 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-5.0.0 vendor/gems/her/lib/her/middleware/parse_json.rb
her-1.1.1 lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.2 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.1 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.rc3 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.rc2 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha35 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha34 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha33 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha32 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha31 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha30 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha29 vendor/gems/her/lib/her/middleware/parse_json.rb
test_track_rails_client-4.0.0.alpha28 vendor/gems/her/lib/her/middleware/parse_json.rb