Sha256: c1a0a09fe1fd0ab04298fbdfd2c3b1f85b5469ac8680499438004154dc2acd14

Contents?: true

Size: 920 Bytes

Versions: 39

Compression:

Stored size: 920 Bytes

Contents

module Her
  module Middleware
    # This middleware expects the resource/collection data to be contained in the `data`
    # key of the JSON object
    class JsonApiParser < ParseJSON
      # Parse the response body
      #
      # @param [String] body The response body
      # @return [Mixed] the parsed response
      # @private
      def parse(body)
        json = parse_json(body)

        {
          :data => json[:data] || {},
          :errors => json[:errors] || [],
          :metadata => json[:meta] || {},
        }
      end

      # This method is triggered when the response has been received. It modifies
      # the value of `env[:body]`.
      #
      # @param [Hash] env The response environment
      # @private
      def on_complete(env)
        env[:body] = case env[:status]
        when 204
          parse('{}')
        else
          parse(env[:body])
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
test_track_rails_client-4.0.0.alpha12 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha11 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha10 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha9 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha8 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha7 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha6 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha5 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha4 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha3 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha2 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-4.0.0.alpha1 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-3.0.1 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-3.0.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-2.0.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-1.3.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-1.2.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-1.1.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
test_track_rails_client-1.0.0 vendor/gems/her/lib/her/middleware/json_api_parser.rb
her-0.8.6 lib/her/middleware/json_api_parser.rb