Class: KairosMcp::Daemon::ProposalRoutes::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/kairos_mcp/daemon/proposal_routes.rb

Instance Method Summary collapse

Constructor Details

#initialize(approval_gate:, mailbox:, auth:) ⇒ Handler

Returns a new instance of Handler.



31
32
33
34
35
# File 'lib/kairos_mcp/daemon/proposal_routes.rb', line 31

def initialize(approval_gate:, mailbox:, auth:)
  @gate    = approval_gate
  @mailbox = mailbox
  @auth    = auth
end

Instance Method Details

#dispatch(req, res) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kairos_mcp/daemon/proposal_routes.rb', line 37

def dispatch(req, res)
  return unless @auth.call(req, res)

  path = req.path
  case req.request_method
  when 'GET'
    if path == '/v1/proposals' || path == '/v1/proposals/'
      handle_list(res)
    elsif (m = path.match(%r{\A/v1/proposals/([^/]+)/?\z}))
      handle_show(m[1], res)
    else
      json_error(res, 404, 'not_found', "unknown path: #{path}")
    end
  when 'POST'
    if (m = path.match(%r{\A/v1/proposals/([^/]+)/approve/?\z}))
      handle_approve(req, m[1], res)
    elsif (m = path.match(%r{\A/v1/proposals/([^/]+)/reject/?\z}))
      handle_reject(req, m[1], res)
    else
      json_error(res, 404, 'not_found', "unknown path: #{path}")
    end
  else
    json_error(res, 405, 'method_not_allowed', 'GET or POST only')
  end
end