Class: DispatchServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb

Instance Method Summary (collapse)

Constructor Details

- (DispatchServlet) initialize(server, bot)

Returns a new instance of DispatchServlet



345
346
347
348
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 345

def initialize(server, bot)
  super server
  @bot = bot
end

Instance Method Details

- (Object) dispatch(req, res)



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 350

def dispatch(req, res)
  res['Server'] = 'RBot Web Service (http://ruby-rbot.org/)'
  begin
    m = WebMessage.new(@bot, req, res)
    @bot.web_dispatcher.handle m
  rescue WEBrick::HTTPStatus::Unauthorized
    res.status = 401
    res['Content-Type'] = 'text/plain'
    res.body = 'Authentication Required!'
    error 'authentication error (wrong password)'
  rescue
    res.status = 500
    res['Content-Type'] = 'text/plain'
    res.body = "Error: %s\n" % [$!.to_s]
    error 'web dispatch error: ' + $!.to_s
    error $@.join("\n")
  end
end

- (Object) do_GET(req, res)



369
370
371
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 369

def do_GET(req, res)
  dispatch(req, res)
end

- (Object) do_POST(req, res)



373
374
375
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 373

def do_POST(req, res)
  dispatch(req, res)
end