Class: Slackdraft::Attachment

Inherits:
Base
  • Object
show all
Defined in:
lib/slackdraft/attachment.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #send!, #target

Constructor Details

This class inherits a constructor from Slackdraft::Base

Instance Method Details

#add_field(title, value, short = true) ⇒ Object

Short defines if it’s 1 column or not, default: not



22
23
24
# File 'lib/slackdraft/attachment.rb', line 22

def add_field(title, value, short=true)
    fields.push({:title => title, :value => value, :short => short })
end

#generate_payloadObject

Generate the payload for slack attachments



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/slackdraft/attachment.rb', line 27

def generate_payload
    payload = {}
    payload[:fallback]    = self.fallback    unless self.fallback.nil?
    payload[:color]       = self.color       unless self.color.nil?
    payload[:pretext]     = self.pretext     unless self.pretext.nil?
    payload[:author_name] = self.author_name unless self.author_name.nil?
    payload[:author_link] = self.author_link unless self.author_link.nil?
    payload[:author_icon] = self.author_icon unless self.author_icon.nil?
    payload[:title]       = self.title       unless self.title.nil?
    payload[:title_link]  = self.title_link  unless self.title_link.nil?
    payload[:text]        = self.text        unless self.text.nil?
    
    unless self.fields.nil?
        payload[:fields]      = self.fields if self.fields.length > 0
    end

    payload[:image_url]   = self.image_url   unless self.image_url.nil?

    puts payload.inspect

    payload
end