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.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/slack-notify/payload.rb', line 5

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

  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

#textObject

Returns the value of attribute text.



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

def text
  @text
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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slack-notify/payload.rb', line 17

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

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