app/controllers/cogy/cogy_controller.rb in cogy-0.3.0 vs app/controllers/cogy/cogy_controller.rb in cogy-0.4.0
- old
+ new
@@ -1,24 +1,23 @@
require_dependency "cogy/application_controller"
module Cogy
+ # This is the entry point to the host application.
+ #
+ # All Cogy-command invocations of the users end up being served by this
+ # controller ({#command}).
class CogyController < ApplicationController
- # POST <mount_path>/cmd/:cmd/:user
+ # POST /<mount_path>/cmd/:cmd
#
- # The command endpoint is the one that the cogy executable (see
- # https://github.com/skroutz/cogy-bundle hits. It executes the requested
- # {Command} and responds back the result, which is then printed to the user
- # by the cogy executable.
- #
- # See https://github.com/skroutz/cogy-bundle.
+ # Executes the requested {Command} and returns the result.
def command
cmd = params[:cmd]
args = params.select { |k, _| k.start_with?("COG_ARGV_") }
.sort_by { |k, _| k.match(/\d+\z/)[0] }.to_h.values
opts = params.select { |k, _| k.start_with?("COG_OPT_") }
.transform_keys { |k| k.sub("COG_OPT_", "").downcase }
- user = params[:user]
+ user = params["COG_CHAT_HANDLE"]
cog_env = request.request_parameters
begin
if (command = Cogy.commands[cmd])
result = Context.new(command, args, opts, user, cog_env).invoke
@@ -41,14 +40,13 @@
end
end
end
end
- # GET <mount_path>/inventory
+ # GET /<mount_path>/inventory
#
- # The inventory endpoint, is essentially the bundle config in YAML format,
- # which is installable by Cog. It is typically installed by the
- # `cogy:install` command (see https://github.com/skroutz/cogy-bundle).
+ # Returns the bundle config in YAML format, which is installable by Cog.
+ # It is typically hit by `cogy:install` (https://github.com/skroutz/cogy-bundle).
def inventory
render text: Cogy.bundle_config.to_yaml, content_type: "application/x-yaml"
end
end
end