Class: Pepito::HTTPApi::HTTPCallback

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

Overview

Class to help callback functions for the http routes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot, klass, func) ⇒ void

Parameters:

  • robot (Pepito::Robot)

    The currently running robot.

  • klass (Pepito::Handler)

    The class where to call the function.

  • func (Symbol)

    The function to call.



23
24
25
26
27
# File 'lib/pepito/http_api/http_callback.rb', line 23

def initialize(robot, klass, func)
  @robot = robot
  @klass = klass
  @func = func
end

Instance Attribute Details

#funcSymbol (readonly)

The function to call

Returns:

  • (Symbol)


17
18
19
# File 'lib/pepito/http_api/http_callback.rb', line 17

def func
  @func
end

#klassPepito::Handler (readonly)

The class to call the function

Returns:



13
14
15
# File 'lib/pepito/http_api/http_callback.rb', line 13

def klass
  @klass
end

#robotPepito::Robot (readonly)

Currently running robot

Returns:



9
10
11
# File 'lib/pepito/http_api/http_callback.rb', line 9

def robot
  @robot
end

Instance Method Details

#call(env) ⇒ void

This method returns an undefined value.

Call method

Parameters:

  • env (Object)

    The environment of the request



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pepito/http_api/http_callback.rb', line 32

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

  if request.head?
    response.status = 204
  else
    begin
      @klass.public_send(@func, request, response)
      response.finish
    rescue => e
      puts e
    end
  end
end