Class: Newshound::SlackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/newshound/slack_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration: nil, logger: nil, transport: nil) ⇒ SlackNotifier

Returns a new instance of SlackNotifier.



9
10
11
12
13
# File 'lib/newshound/slack_notifier.rb', line 9

def initialize(configuration: nil, logger: nil, transport: nil)
  @configuration = configuration || Newshound.configuration
  @logger = logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
  @transport = transport || build_transport
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/newshound/slack_notifier.rb', line 7

def configuration
  @configuration
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/newshound/slack_notifier.rb', line 7

def logger
  @logger
end

#transportObject (readonly)

Returns the value of attribute transport.



7
8
9
# File 'lib/newshound/slack_notifier.rb', line 7

def transport
  @transport
end

Instance Method Details

#post(message) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/newshound/slack_notifier.rb', line 15

def post(message)
  return unless configuration.valid?

  transport.deliver(message)
rescue StandardError => e
  logger.error "Newshound: Failed to send notification: #{e.message}"
end