Class: Bender::BaseServlet Abstract

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/base_servlet.rb

Overview

This class is abstract.

Subclass and override #mountpoint to implement

Base class for all Servlets

-- Provides uri autoload and helpers for working with SpunkBot
Author

Michael Heijmans ([email protected])

Copyright

Copyright © 2013-2015 Michael Heijmans

License

MIT

Direct Known Subclasses

HTTP::Parrot, HTTP::Ping, HTTP::Stats

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, *options) ⇒ BaseServlet


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

Instance Attribute Details

#auth_tokenObject (readonly)

The auth_token defined in Bender.config.http_auth_token


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

#botObject (readonly)

The SpunkBot object


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

#configObject (readonly)

The config object


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

#optionsObject (readonly)

The passed in options hash


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

#serverObject (readonly)

The server object


26
27
28
29
30
31
32
# File 'lib/base_servlet.rb', line 26

def initialize(server, *options)
  @server     = @config = server
  @logger     = @server[:Logger]
  @options    = options
  @bot        = @config[:bot]
  @auth_token = Bender.config.http_auth_token
end

Class Method Details

.mountpointObject

The uri mountpoint to use for the Servlet

Examples:

Mount my servlet at '/stats'

def self.mountpoint
  './stats'
end

Raises:

  • (NotImplementedError)

44
45
46
47
# File 'lib/base_servlet.rb', line 44

def self.mountpoint
  obj = self
  raise NotImplementedError, "you must implement #mountpoint class method for #{obj}"
end

Instance Method Details

#params(request) ⇒ Object

A helper to return the query params hash for a given `request`


35
36
37
# File 'lib/base_servlet.rb', line 35

def params(request)
  request.query
end