Class: SlackNotify::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-notify/payload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Payload

Returns a new instance of Payload.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/slack-notify/payload.rb', line 11

def initialize(options = {})
  @username     = options[:username] || "webhookbot"
  @channel      = options[:channel]  || "#general"
  @text         = options[:text]
  @icon_url     = options[:icon_url]
  @icon_emoji   = options[:icon_emoji]
  @link_names   = options[:link_names]
  @unfurl_links = options[:unfurl_links] || "1"

  unless channel[0] =~ /^(#|@)/
    @channel = "##{@channel}"
  end
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def channel
  @channel
end

#icon_emojiObject

Returns the value of attribute icon_emoji.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def icon_emoji
  @icon_emoji
end

#icon_urlObject

Returns the value of attribute icon_url.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def icon_url
  @icon_url
end

Returns the value of attribute link_names.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def link_names
  @link_names
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def text
  @text
end

Returns the value of attribute unfurl_links.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def unfurl_links
  @unfurl_links
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/slack-notify/payload.rb', line 3

def username
  @username
end

Instance Method Details

#to_hashObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slack-notify/payload.rb', line 25

def to_hash
 hash = {
    text:         text,
    username:     username,
    channel:      channel,
    icon_url:     icon_url,
    icon_emoji:   icon_emoji,
    link_names:   link_names,
    unfurl_links: unfurl_links
  }

  hash.delete_if { |_,v| v.nil? }
end