Class: Banacle::InteractiveMessage::Renderer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, command) ⇒ Renderer

Returns a new instance of Renderer.



23
24
25
26
# File 'lib/banacle/interactive_message/renderer.rb', line 23

def initialize(params, command)
  @params = params
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



28
29
30
# File 'lib/banacle/interactive_message/renderer.rb', line 28

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



28
29
30
# File 'lib/banacle/interactive_message/renderer.rb', line 28

def params
  @params
end

Class Method Details

.render(params, command) ⇒ Object



7
8
9
# File 'lib/banacle/interactive_message/renderer.rb', line 7

def self.render(params, command)
  new(params, command).render
end

.render_error(error) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/banacle/interactive_message/renderer.rb', line 15

def self.render_error(error)
  Slack::Response.new(
    response_type: "ephemeral",
    replace_original: false,
    text: "An error occurred: #{error}",
  ).to_json
end

.render_unauthenticatedObject



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

def self.render_unauthenticated
  self.render_error("you are not authorized to perform this action")
end

Instance Method Details

#renderObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/banacle/interactive_message/renderer.rb', line 30

def render
  action = Slack::Action.new(payload[:actions].first)

  if action.approved?
    render_approved_message(payload, command)
  elsif action.rejected?
    render_rejected_message(payload, command)
  elsif action.cancelled?
    render_cancelled_message(payload, command)
  else
    # Do nothing
  end
end