Class: Banacle::InteractiveMessage::Handler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, auth: nil) ⇒ Handler

Returns a new instance of Handler.



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

def initialize(config, auth: nil)
  @config = config
  @auth = auth
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#requestObject

Returns the value of attribute request.



16
17
18
# File 'lib/banacle/interactive_message/handler.rb', line 16

def request
  @request
end

Instance Method Details

#handle(raw_request) ⇒ Object



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

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

  self.request = Request.new(raw_request)

  json = if request.action.approved?
           handle_approval
         elsif request.action.rejected?
           handle_reject
         elsif request.action.cancelled?
           handle_cancellation
         end
  puts json

  json
end