Class: Slackdraft::Attachment
- Defined in:
- lib/slackdraft/attachment.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add_field(title, value, short = true) ⇒ Object
Short defines if it’s 1 column or not, default: not.
-
#generate_attachment ⇒ Object
Generate the payload for slack attachments.
-
#initialize(url = nil) ⇒ Attachment
constructor
Capture the url if we pass it in.
-
#send! ⇒ Object
Send it directly from Attachment.
-
#to_h ⇒ Object
To hash, for use in Message.
Methods inherited from Message
#add_attachment, #channel, #generate_payload, #icon_emoji, #icon_url, #parse_usernames_and_channels, #text, #username
Methods inherited from Base
Constructor Details
#initialize(url = nil) ⇒ Attachment
Capture the url if we pass it in
22 23 24 25 26 |
# File 'lib/slackdraft/attachment.rb', line 22 def initialize(url=nil) unless url.nil? @target = url end end |
Instance Method Details
#add_field(title, value, short = true) ⇒ Object
Short defines if it’s 1 column or not, default: not
29 30 31 |
# File 'lib/slackdraft/attachment.rb', line 29 def add_field(title, value, short=true) fields.push({:title => title, :value => value, :short => short }) end |
#generate_attachment ⇒ Object
Generate the payload for slack attachments
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/slackdraft/attachment.rb', line 34 def 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. unless self..nil? payload[:author_link] = self. unless self..nil? payload[:author_icon] = self. unless self..nil? payload[:title] = self.title unless self.title.nil? payload[:title_link] = self.title_link unless self.title_link.nil? payload[:text] = self. unless self..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? payload end |
#send! ⇒ Object
Send it directly from Attachment
61 62 63 64 |
# File 'lib/slackdraft/attachment.rb', line 61 def send! () super end |
#to_h ⇒ Object
To hash, for use in Message
56 57 58 |
# File 'lib/slackdraft/attachment.rb', line 56 def to_h end |