Class: SlackNotify::Client

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/slack-notify/client.rb

Instance Method Summary collapse

Methods included from Connection

#handle_response, #send_payload

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/slack-notify/client.rb', line 8

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

  if @webhook_url.nil?
    raise ArgumentError, "Webhook URL required"
  end
end

Instance Method Details

#notify(text, channel = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/slack-notify/client.rb', line 26

def notify(text, channel = nil)
  delivery_channels(channel).each do |chan|
    payload = SlackNotify::Payload.new(
      text:         text,
      channel:      chan,
      username:     @username,
      icon_url:     @icon_url,
      icon_emoji:   @icon_emoji,
      link_names:   @link_names,
      unfurl_links: @unfurl_links
    )

    send_payload(payload)
  end

  true
end

#testObject



22
23
24
# File 'lib/slack-notify/client.rb', line 22

def test
  notify("Test Message")
end