Class: Banacle::SlashCommand::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/banacle/slash_command/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Handler

Returns a new instance of Handler.



11
12
13
# File 'lib/banacle/slash_command/handler.rb', line 11

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/banacle/slash_command/handler.rb', line 15

def config
  @config
end

Instance Method Details

#handle(raw_request) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/banacle/slash_command/handler.rb', line 17

def handle(raw_request)
  unless slack_validator.valid_signature?(raw_request)
    return [401, {}, "invalid signagure"]
  end

  request = Request.new(raw_request)

  begin
    authenticate_requester!(request)
    command = Parser.parse(request.text)
  rescue Error => e
    return Renderer.render_error(e)
  end

  json = Renderer.new(request, command, config).render_approval_request
  puts json

  json
end