Class: Server

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::HttpServer
Defined in:
lib/cogbot/server.rb

Overview

eventmachine engine for serving as a webhook destination

Instance Method Summary collapse

Constructor Details

#initialize(bot) ⇒ Server

Returns a new instance of Server.



5
6
7
# File 'lib/cogbot/server.rb', line 5

def initialize(bot)
  @bot = bot
end

Instance Method Details

#post_initObject



9
10
11
12
# File 'lib/cogbot/server.rb', line 9

def post_init
  super
  no_environment_strings
end

#process_http_requestObject



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

def process_http_request
  if @http_request_method == "POST"
    pluginlist = @bot.plugins.map { |e| e.class.name.split('::').last.downcase }
    query = @http_request_uri[1..-1]
    if pluginlist.include? query
      @bot.handlers.dispatch("http_#{query}".to_sym, nil, @http_post_content)
    end
  end

  response = EM::DelegatedHttpResponse.new(self)
  response.status = 200
  response.send_response
end