21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-22 10:18:48 +02:00
chexpire/app/services/notifier/channels/base.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
# License: GNU AGPL-3+ (see full text in LICENSE file)
2018-06-04 14:06:37 +02:00
module Notifier
module Channels
class Base
def notify(notification) # rubocop:disable Metrics/MethodLength
return unless supports?(notification)
2018-06-04 14:06:37 +02:00
notification.ongoing!
case notification.check.kind.to_sym
when :domain
2018-06-04 14:06:37 +02:00
domain_notify_expires_soon(notification)
when :ssl
2018-07-02 18:40:09 +02:00
ssl_notify_expires_soon(notification)
2018-06-04 14:06:37 +02:00
else
fail ArgumentError,
"Invalid notification for check kind `#{notification.check.kind}`."
2018-06-04 14:06:37 +02:00
end
end
private
# :nocov:
def supports?(_notification)
2018-06-04 14:06:37 +02:00
fail NotImplementedError,
"#{self.class.name} channel did not implemented method #{__callee__}"
end
2018-07-02 18:40:09 +02:00
%i[
domain_notify_expires_soon
ssl_notify_expires_soon
].each do |method|
define_method(method) do
fail NotImplementedError,
"Channel #{self.class.name} does not implement method #{method}."
end
2018-06-04 14:06:37 +02:00
end
# :nocov:
end
end
end