Class: Stealth::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/stealth/dispatcher.rb

Overview

Responsible for coordinating incoming messages

1. Receives incoming request params
2. Initializes respective service request handler
3. Processes params through service request handler (might be async)
4. Inits base StealthController with state params returned from the service
   request handler
5. Returns an HTTP response to be returned to the requestor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service:, params:, headers:) ⇒ Dispatcher

Returns a new instance of Dispatcher.



17
18
19
20
21
22
23
24
25
# File 'lib/stealth/dispatcher.rb', line 17

def initialize(service:, params:, headers:)
  @service = service
  @params = params
  @headers = headers
  @message_handler = message_handler_klass.new(
    params: params,
    headers: headers
  )
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



15
16
17
# File 'lib/stealth/dispatcher.rb', line 15

def headers
  @headers
end

#message_handlerObject (readonly)

Returns the value of attribute message_handler.



15
16
17
# File 'lib/stealth/dispatcher.rb', line 15

def message_handler
  @message_handler
end

#paramsObject (readonly)

Returns the value of attribute params.



15
16
17
# File 'lib/stealth/dispatcher.rb', line 15

def params
  @params
end

#serviceObject (readonly)

Returns the value of attribute service.



15
16
17
# File 'lib/stealth/dispatcher.rb', line 15

def service
  @service
end

Instance Method Details

#coordinateObject



27
28
29
# File 'lib/stealth/dispatcher.rb', line 27

def coordinate
  message_handler.coordinate
end

#processObject



31
32
33
34
35
# File 'lib/stealth/dispatcher.rb', line 31

def process
  service_message = message_handler.process
  bot_controller = BotController.new(service_message: service_message)
  bot_controller.route
end