Class: Lita::HTTPCallback Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/http_callback.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A wrapper around a handler's HTTP route callbacks that sets up the request and response.

Since:

  • 4.0.0

Instance Method Summary collapse

Constructor Details

#initialize(handler_class, callback) ⇒ HTTPCallback

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HTTPCallback

Parameters:

  • handler_class (Lita::Handler)

    The handler defining the callback.

  • callback (Proc)

    The callback.

Since:

  • 4.0.0



8
9
10
11
# File 'lib/lita/http_callback.rb', line 8

def initialize(handler_class, callback)
  @handler_class = handler_class
  @callback = callback
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call the Rack endpoint with a standard environment hash.

Since:

  • 4.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lita/http_callback.rb', line 14

def call(env)
  request = Rack::Request.new(env)
  response = Rack::Response.new

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

    @callback.call(handler, request, response)
  end

  response.finish
end