Class: Pepito::Handlers::ExtensionsCatalog

Inherits:
Pepito::Handler show all
Defined in:
lib/pepito/handlers/extensions_catalog.rb

Overview

Handler to manage (start, stop, status) the extensions.

Instance Attribute Summary

Attributes inherited from Pepito::Handler

#robot

Instance Method Summary collapse

Methods inherited from Pepito::Handler

#initialize, #start

Methods included from Pepito::Handler::ChatRouter

#chat_route, #chat_routes

Methods included from Pepito::Handler::HTTPRouter

#http_route, #http_routes

Constructor Details

This class inherits a constructor from Pepito::Handler

Instance Method Details

#adapters_chat(_source, _match_data) ⇒ Array<String>

Get a list of the currently running adapters.

Parameters:

  • _source (Pepito::Source)

    Source of the message. Not used.

  • _match_data (MatchData)

    Match Data. Not used.

Returns:

  • (Array<String>)


83
84
85
# File 'lib/pepito/handlers/extensions_catalog.rb', line 83

def adapters_chat(_source, _match_data)
  @robot.adapters.keys
end

#adapters_web(_request, response) ⇒ void

This method returns an undefined value.

HTTP API List the running adapters.

Parameters:

  • _request (Rack::Request)
  • response (Rack::Response)


51
52
53
54
55
56
57
# File 'lib/pepito/handlers/extensions_catalog.rb', line 51

def adapters_web(_request, response)
  response.headers['Content-Type'] = 'application/json'
  json = MultiJson.dump(
    adapters: @robot.adapters.keys
  )
  response.write(json)
end

#extensions_web(_request, response) ⇒ void

This method returns an undefined value.

HTTP API List the running handlers and adapters.

Parameters:

  • _request (Rack::Request)
  • response (Rack::Response)


26
27
28
29
30
31
32
33
# File 'lib/pepito/handlers/extensions_catalog.rb', line 26

def extensions_web(_request, response)
  response.headers['Content-Type'] = 'application/json'
  json = MultiJson.dump(
    handlers: @robot.handlers.keys,
    adapters: @robot.adapters.keys
  )
  response.write(json)
end

#handlers_chat(_source, _match_data) ⇒ Array<String>

Get a list of the currently running handlers.

Parameters:

  • _source (Pepito::Source)

    Source of the message. Not used.

  • _match_data (MatchData)

    Match Data. Not used.

Returns:

  • (Array<String>)


75
76
77
# File 'lib/pepito/handlers/extensions_catalog.rb', line 75

def handlers_chat(_source, _match_data)
  @robot.handlers.keys
end

#handlers_web(_request, response) ⇒ void

This method returns an undefined value.

HTTP API List the running handlers.

Parameters:

  • _request (Rack::Request)
  • response (Rack::Response)


39
40
41
42
43
44
45
# File 'lib/pepito/handlers/extensions_catalog.rb', line 39

def handlers_web(_request, response)
  response.headers['Content-Type'] = 'application/json'
  json = MultiJson.dump(
    handlers: @robot.handlers.keys
  )
  response.write(json)
end

#routes_chat(_source, _match_data) ⇒ Array<String>

Get a list of the currently active http routes.

Parameters:

  • _source (Pepito::Source)

    Source of the message. Not used.

  • _match_data (MatchData)

    Match Data. Not used.

Returns:

  • (Array<String>)


91
92
93
# File 'lib/pepito/handlers/extensions_catalog.rb', line 91

def routes_chat(_source, _match_data)
  api_routes
end

#routes_web(_request, response) ⇒ void

This method returns an undefined value.

HTTP API List the active http routes.

Parameters:

  • _request (Rack::Request)
  • response (Rack::Response)


63
64
65
66
67
68
69
# File 'lib/pepito/handlers/extensions_catalog.rb', line 63

def routes_web(_request, response)
  response.headers['Content-Type'] = 'application/json'
  json = MultiJson.dump(
    routes: api_routes
  )
  response.write(json)
end

#runvoid

This method returns an undefined value.

Run the extensions handler.



11
12
13
14
15
16
17
18
19
20
# File 'lib/pepito/handlers/extensions_catalog.rb', line 11

def run
  http_route('GET', '/extensions', :extensions_web)
  http_route('GET', '/handlers', :handlers_web)
  http_route('GET', '/adapters', :adapters_web)
  http_route('GET', '/routes', :routes_web)

  chat_route(/^handlers list$/i, :handlers_chat, command: true, help: 'handlers list -> show list of active handlers')
  chat_route(/^adapters list$/i, :adapters_chat, command: true, help: 'adapters list -> show list of active adapters')
  chat_route(/^routes list$/i, :routes_chat, command: true, help: 'routes list -> show list of active api routes')
end