Class: SupermarketSync::Notifier

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

Overview

> Notifications

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) {|_self| ... } ⇒ Notifier

Returns a new instance of Notifier.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
26
# File 'lib/supermarket_sync/notifier.rb', line 20

def initialize(**args)
  @url       = args[:url]
  @channels  = args[:channels]
  @username  = args[:username]
  @http_opts = args[:http_opts] || {}
  yield self if block_given?
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



18
19
20
# File 'lib/supermarket_sync/notifier.rb', line 18

def channels
  @channels
end

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/supermarket_sync/notifier.rb', line 18

def url
  @url
end

#usernameObject

Returns the value of attribute username.



18
19
20
# File 'lib/supermarket_sync/notifier.rb', line 18

def username
  @username
end

Instance Method Details

#deprecatedObject

> Accumulators



49
50
51
# File 'lib/supermarket_sync/notifier.rb', line 49

def deprecated
  @deprecated ||= []
end

#send!Object



28
29
30
31
32
33
34
# File 'lib/supermarket_sync/notifier.rb', line 28

def send!
  messages = [build_deprecated, build_updated].compact
  return unless messages.any?
  Array(@channels).each do |channel|
    slack.ping '', attachments: messages, channel: channel
  end
end

#slackObject



36
37
38
39
40
41
42
43
# File 'lib/supermarket_sync/notifier.rb', line 36

def slack
  (cfg = {})[:username] = @username
  cfg[:http_options] = { verify_mode: OpenSSL::SSL::VERIFY_NONE }

  Slack::Notifier.new @url do
    defaults cfg
  end
end

#updatedObject



53
54
55
# File 'lib/supermarket_sync/notifier.rb', line 53

def updated
  @updated ||= []
end