Class: Lita::Handlers::Info

Inherits:
Lita::Handler show all
Defined in:
lib/lita/handlers/info.rb

Overview

Provides information about the currently running robot.

Instance Method Summary collapse

Methods included from Lita::Handler::EventRouter

#event_subscriptions_for, extended, #on, #trigger

Methods included from Lita::Handler::HTTPRouter

extended, #http, #http_routes

Methods included from Lita::Handler::ChatRouter

#dispatch, #dispatch_to_route, extended, #route, #routes

Instance Method Details

#chat(response) ⇒ void

This method returns an undefined value.

Replies with the current version of Lita, the current version of Redis, and Redis memory usage.

Parameters:

Since:

  • 3.0.0



17
18
19
20
21
22
# File 'lib/lita/handlers/info.rb', line 17

def chat(response)
  response.reply(
    %(Lita #{Lita::VERSION} - https://www.lita.io/),
    %(Redis #{redis_version} - Memory used: #{redis_memory_usage})
  )
end

#redis_infoObject

A hash of information about Redis.



42
43
44
# File 'lib/lita/handlers/info.rb', line 42

def redis_info
  @redis_info ||= redis.info
end

#redis_memory_usageObject

The amount of memory Redis is using.



52
53
54
# File 'lib/lita/handlers/info.rb', line 52

def redis_memory_usage
  redis_info["used_memory_human"]
end

#redis_versionObject

The current version of Redis.



47
48
49
# File 'lib/lita/handlers/info.rb', line 47

def redis_version
  redis_info["redis_version"]
end

#web(_request, response) ⇒ void

This method returns an undefined value.

Returns JSON with basic information about the robot.

Parameters:

  • _request (Rack::Request)

    The HTTP request.

  • response (Rack::Response)

    The HTTP response.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lita/handlers/info.rb', line 28

def web(_request, response)
  response.headers["Content-Type"] = "application/json"
  json = MultiJson.dump(
    adapter: robot.config.robot.adapter,
    lita_version: Lita::VERSION,
    redis_memory_usage: redis_memory_usage,
    redis_version: redis_version,
    robot_mention_name: robot.mention_name,
    robot_name: robot.name
  )
  response.write(json)
end