Class: Bender::HTTP::Stats

Inherits:
BaseServlet
  • Object
show all
Defined in:
servlets/stats.rb

Overview

Description

provides information about the bot

Dependencies

none

Configuration

Bender.config.http_auth_token

Authors

Michael Heijmans ([email protected])

Instance Attribute Summary

Attributes inherited from BaseServlet

#auth_token, #bot, #config, #options, #server

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseServlet

#initialize, #params

Constructor Details

This class inherits a constructor from Bender::BaseServlet

Class Method Details

.mountpointObject


44
45
46
# File 'servlets/stats.rb', line 44

def self.mountpoint
  "/stats"
end

Instance Method Details

#do_GET(request, response) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'servlets/stats.rb', line 16

def do_GET(request, response)
  status = 200
  content_type = "text/html"
  body = []
  body << "<table><tr><th>Current Active Rooms</th></tr>"
  @bot.joined_rooms.each do |r|
    body << "<tr><td>#{r}</td></tr>"
  end
  body << "<table><br/><br/><br/>"
  body << "bender version #{Bender::VERSION}"

  body = body.join("\n")

  body += "\n"

  if @auth_token
    unless params(request)['token'] == @auth_token
      status = 403
      body = "You are not authorized to view this resource\n"
    end
  end

  response.status = status
  response['Content-Type'] = content_type
  response.body = body
  response.body = body
end