Class: Slackdraft::Message

Inherits:
Base
  • Object
show all
Defined in:
lib/slackdraft/message.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

#channelObject

Set the destination channel



18
19
20
21
# File 'lib/slackdraft/message.rb', line 18

def channel
  return '#general' if @channel.nil?
  @channel
end

#generate_payloadObject

Generate the payload if stuff was provided



53
54
55
56
57
58
59
60
61
62
# File 'lib/slackdraft/message.rb', line 53

def generate_payload
    payload = {}
    payload[:channel]    = self.channel    unless self.channel.nil?
    payload[:username]   = self.username   unless self.username.nil?
    payload[:icon_url]   = self.icon_url   unless self.icon_url.nil?
    payload[:icon_emoji] = self.icon_emoji unless self.icon_emoji.nil?
    payload[:text]       = self.text       unless self.text.nil?

    payload
end

#icon_emojiObject

Set the emoji



29
30
31
# File 'lib/slackdraft/message.rb', line 29

def icon_emoji
  return ':fire:' if @icon_emoji.nil?
end

#icon_urlObject

Set the icon URL and default to the emoji



24
25
26
# File 'lib/slackdraft/message.rb', line 24

def icon_url
  @icon_url || icon_emoji
end

#refchannel(channel) ⇒ Object



33
34
35
# File 'lib/slackdraft/message.rb', line 33

def refchannel(channel)
  "<#C024BE7LR|#{channel}>"
end

#refuser(user) ⇒ Object



37
38
39
# File 'lib/slackdraft/message.rb', line 37

def refuser(user)
  "<@U024BE7LH|#{user}>"
end

#textObject

Set the text of the message



42
43
44
45
46
47
48
49
50
# File 'lib/slackdraft/message.rb', line 42

def text
  
  if @text.kind_of?(Array)
    return @text.join("\n")
  end
  
  @text

end

#usernameObject

Set the api call username



12
13
14
15
# File 'lib/slackdraft/message.rb', line 12

def username
  return 'slackdraft' if @username.nil?
  @username
end