Sha256: 263c57f855c3622ab12d336821585fe1affa0bb2c1a4f5cd50581497a5f5f333

Contents?: true

Size: 917 Bytes

Versions: 14

Compression:

Stored size: 917 Bytes

Contents

module Lita
  # A wrapper around a handler's HTTP route callbacks that sets up the request and response.
  # @api private
  # @since 4.0.0
  class HTTPCallback
    # @param handler_class [Lita::Handler] The handler defining the callback.
    # @param callback [Proc] The callback.
    def initialize(handler_class, callback)
      @handler_class = handler_class
      @callback = callback
    end

    # Call the Rack endpoint with a standard environment hash.
    def call(env)
      request = Rack::Request.new(env)
      response = Rack::Response.new

      if request.head?
        response.status = 204
      else
        begin
          handler = @handler_class.new(env["lita.robot"])

          @callback.call(handler, request, response)
        rescue Exception => e
          env["lita.robot"].config.robot.error_handler.call(e)
          raise
        end
      end

      response.finish
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lita-4.8.0 lib/lita/http_callback.rb
lita-4.8.0.beta1 lib/lita/http_callback.rb
lita-4.7.1 lib/lita/http_callback.rb
lita-4.7.0 lib/lita/http_callback.rb
lita-4.6.1 lib/lita/http_callback.rb
lita-4.6.0 lib/lita/http_callback.rb
lita-4.5.0 lib/lita/http_callback.rb
lita-4.4.3 lib/lita/http_callback.rb
lita-4.4.2 lib/lita/http_callback.rb
lita-4.4.1 lib/lita/http_callback.rb
lita-4.4.0 lib/lita/http_callback.rb
lita-4.3.2 lib/lita/http_callback.rb
lita-4.3.1 lib/lita/http_callback.rb
lita-4.3.0 lib/lita/http_callback.rb