Class: ExceptionNotifier::SnsNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/exception_notifier/sns_notifier.rb

Instance Attribute Summary

Attributes inherited from BaseNotifier

#base_options

Instance Method Summary collapse

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #send_notice

Constructor Details

#initialize(options) ⇒ SnsNotifier

Returns a new instance of SnsNotifier.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/exception_notifier/sns_notifier.rb', line 5

def initialize(options)
  super

  raise ArgumentError, "You must provide 'region' option" unless options[:region]
  raise ArgumentError, "You must provide 'access_key_id' option" unless options[:access_key_id]
  raise ArgumentError, "You must provide 'secret_access_key' option" unless options[:secret_access_key]

  @notifier = Aws::SNS::Client.new(
    region: options[:region],
    access_key_id: options[:access_key_id],
    secret_access_key: options[:secret_access_key]
  )
  @options = default_options.merge(options)
end

Instance Method Details

#call(exception, custom_opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/exception_notifier/sns_notifier.rb', line 20

def call(exception, custom_opts = {})
  custom_options = options.merge(custom_opts)

  subject = build_subject(exception, custom_options)
  message = build_message(exception, custom_options)

  notifier.publish(
    topic_arn: custom_options[:topic_arn],
    message: message,
    subject: subject
  )
end