Class: Sinatra::Slack::Helpers::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/slack/helpers/slack_attachment.rb

Overview

Represents a message attachment sent to the Slack Channel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_id) ⇒ Attachment

Returns a new instance of Attachment.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 11

def initialize(callback_id)
  @callback_id = callback_id
  @attachment_type = 'default'
  @color = '#3AA3E3'
  @actions = []

  @text = ''
  @fallback = ''
  @image_url = ''
  @title = ''
end

Instance Attribute Details

#attachment_typeObject

Returns the value of attribute attachment_type.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def attachment_type
  @attachment_type
end

#colorObject

Returns the value of attribute color.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def color
  @color
end

#fallbackObject

Returns the value of attribute fallback.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def fallback
  @fallback
end

#image_urlObject

Returns the value of attribute image_url.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def image_url
  @image_url
end

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def text
  @text
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8

def title
  @title
end

Instance Method Details

#action_button(name, text, value) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 23

def action_button(name, text, value)
  @actions << {
    name: name,
    text: text,
    type: 'button',
    value: value
  }
end

#action_menu(name, text, options) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 32

def action_menu(name, text, options)
  @actions << {
    name: name,
    text: text,
    type: 'select',
    options: options
  }
end

#to_jsonObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 41

def to_json
  att_obj = {}

  att_obj[:callback_id] = @callback_id

  att_obj[:title] = title unless title.empty?
  att_obj[:color] = color unless color.empty?
  att_obj[:attachment_type] = attachment_type unless attachment_type.empty?
  att_obj[:text] = text unless text.empty?
  att_obj[:fallback] = fallback unless fallback.empty?
  att_obj[:image_url] = image_url unless image_url.empty?

  att_obj[:actions] = @actions unless @actions.empty?

  att_obj
end