Class: Clearbit::Slack::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/clearbit/slack/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}, options = {}) ⇒ Notifier

Returns a new instance of Notifier.



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

def initialize(attrs = {}, options = {})
  options = Slack.configuration.merge(options)

  @company       = attrs[:company]
  @message       = attrs[:message]
  @person        = attrs[:person]
  @given_name    = attrs[:given_name]
  @family_name   = attrs[:family_name]
  @email         = attrs[:email]
  @slack_url     = options[:slack_url]
  @slack_channel = options[:slack_channel]
  @slack_icon    = options[:slack_icon]
end

Instance Attribute Details

#companyObject (readonly)

Returns the value of attribute company.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def company
  @company
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def email
  @email
end

#family_nameObject (readonly)

Returns the value of attribute family_name.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def family_name
  @family_name
end

#given_nameObject (readonly)

Returns the value of attribute given_name.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def given_name
  @given_name
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def message
  @message
end

#slack_channelObject (readonly)

Returns the value of attribute slack_channel.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def slack_channel
  @slack_channel
end

#slack_iconObject (readonly)

Returns the value of attribute slack_icon.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def slack_icon
  @slack_icon
end

#slack_urlObject (readonly)

Returns the value of attribute slack_url.



4
5
6
# File 'lib/clearbit/slack/notifier.rb', line 4

def slack_url
  @slack_url
end

Instance Method Details

#attachmentsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/clearbit/slack/notifier.rb', line 34

def attachments
  result = []

  result << Attachments::Person.new(person).as_json

  if company
    result << Attachments::Company.new(company).as_json
  end

  result
end

#notifierObject



26
27
28
29
30
31
32
# File 'lib/clearbit/slack/notifier.rb', line 26

def notifier
  ::Slack::Notifier.new(
    slack_url,
    channel:  slack_channel,
    icon_url: slack_icon,
  )
end

#pingObject



22
23
24
# File 'lib/clearbit/slack/notifier.rb', line 22

def ping
  notifier.ping(message.to_s, attachments: attachments)
end