Sha256: 2103644154f34037c763851ed3586f8c0b47540458f0f728d1a13fc760e1b8f3

Contents?: true

Size: 640 Bytes

Versions: 2

Compression:

Stored size: 640 Bytes

Contents

require 'json'

module Lotus
  module Routing
    module Parsing
      class JsonParser < Parser
        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 [Lotus::Routing::Parsing::BodyParsingError] when the body can't be parsed.
        #
        # @since 0.2.0
        def parse(body)
          JSON.parse(body)
        rescue JSON::ParserError => e
          raise BodyParsingError.new(e.message)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lotus-router-0.5.1 lib/lotus/routing/parsing/json_parser.rb
lotus-router-0.5.0 lib/lotus/routing/parsing/json_parser.rb