Sha256: 46a039931b8d600b2c07a68b09f06a2e4395cc00d9533eee46ec0d63d450045d

Contents?: true

Size: 648 Bytes

Versions: 1

Compression:

Stored size: 648 Bytes

Contents

require 'multi_json'

module Esplanade
  class Request
    class Raw
      class Body
        def initialize(raw_request, env)
          @raw_request = raw_request
          @env = env
        end

        def to_string
          @string ||= @env['rack.request.form_vars']
        end

        def to_hash
          @hash ||= MultiJson.load(to_string)
        rescue MultiJson::ParseError
          raise BodyIsNotJson, message
        end

        private

        def message
          {
            method: @raw_request.method,
            path: @raw_request.path,
            body: to_string
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esplanade-1.0.0 lib/esplanade/request/raw/body.rb