Class: Pepito::Handlers::Info

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

Overview

Handler to give the bot’s info.

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

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

Info for the chat

Parameters:

  • _source (Pepito::Source)

    Source of the message. Not used.

  • _match_data (MatchData)

    Match Data. Not used.

Returns:

  • (Array<String>)


33
34
35
36
37
# File 'lib/pepito/handlers/info.rb', line 33

def chat(_source, _match_data)
  strings = []
  strings << 'Pepito Version: ' + Pepito::VERSION
  strings
end

#runvoid

This method returns an undefined value.

Run the handler.



12
13
14
15
# File 'lib/pepito/handlers/info.rb', line 12

def run
  http_route('GET', '/info', :web)
  chat_route(/^info$/i, :chat, command: true, help: "info -> show bot's info")
end

#web(_request, response) ⇒ void

This method returns an undefined value.

Info for the http api.

Parameters:

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


21
22
23
24
25
26
27
# File 'lib/pepito/handlers/info.rb', line 21

def web(_request, response)
  response.headers['Content-Type'] = 'application/json'
  json = MultiJson.dump(
    pepito_version: Pepito::VERSION
  )
  response.write(json)
end