Sha256: 1fc7045d081b620bd0887617c5a981ba43e6e46165f5cc2ed40e29b59664f883

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 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 ||= if to_string.nil?
                      {}
                    else
                      MultiJson.load(to_string)
                    end
        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

2 entries across 2 versions & 1 rubygems

Version Path
esplanade-1.1.0 lib/esplanade/request/raw/body.rb
esplanade-1.0.1 lib/esplanade/request/raw/body.rb