Sha256: 7c56adf51fa35e47918217c215b06f7da5e6a4b63198839883c900ddb0bf27d6

Contents?: true

Size: 796 Bytes

Versions: 19

Compression:

Stored size: 796 Bytes

Contents

require 'hanami/utils/json'

module Hanami
  module Routing
    module Parsing
      # @since 0.2.0
      # @api private
      class JsonParser < Parser
        # @since 0.2.0
        # @api private
        def mime_types
          ['application/json', 'application/vnd.api+json']
        end

        # Parse a json string
        #
        # @param body [String] a json string
        #
        # @return [Hash] the parsed json
        #
        # @raise [Hanami::Routing::Parsing::BodyParsingError] when the body can't be parsed.
        #
        # @since 0.2.0
        # @api private
        def parse(body)
          Hanami::Utils::Json.parse(body)
        rescue Hanami::Utils::Json::ParserError => e
          raise BodyParsingError.new(e.message)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
hanami-router-1.3.2 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.3.1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.3.0 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.3.0.beta1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.2.0 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.2.0.rc2 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.2.0.rc1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.2.0.beta2 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.2.0.beta1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.0 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.0.rc1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.0.beta3 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.0.beta2 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.1.0.beta1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.0.1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.0.0 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.0.0.rc1 lib/hanami/routing/parsing/json_parser.rb
hanami-router-1.0.0.beta3 lib/hanami/routing/parsing/json_parser.rb