Class: ChatSDK::Webhook::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/chat_sdk/webhook/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(chat, adapters) ⇒ Router

Returns a new instance of Router.



6
7
8
9
# File 'lib/chat_sdk/webhook/router.rb', line 6

def initialize(chat, adapters)
  @chat = chat
  @adapters = adapters
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chat_sdk/webhook/router.rb', line 11

def call(env)
  path = env["PATH_INFO"].to_s.split("/").last&.to_sym
  adapter = @adapters[path]

  unless adapter
    return [404, {"content-type" => "text/plain"}, ["Unknown adapter: #{path}"]]
  end

  endpoint = Endpoint.new(chat: @chat, adapter: adapter, adapter_name: path)
  endpoint.call(env)
end