Class: Dscf::Core::NotificationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/dscf/core/notification_service.rb

Defined Under Namespace

Modules: Adapters

Class Method Summary collapse

Class Method Details

.deliver(notification) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/services/dscf/core/notification_service.rb', line 7

def deliver(notification)
  phone = notification.recipient&.phone
  raise ArgumentError, "Recipient phone is blank" if phone.blank?
  adapter = resolve_adapter
  adapter.send_sms(phone, notification.body)
  notification.update!(status: :delivered, delivered_at: Time.current)
rescue => e
  Rails.logger.error("Notification delivery failed: #{e.message}")
  notification.update(status: :failed) rescue nil
end

.resolve_adapterObject



18
19
20
21
22
23
24
25
# File 'app/services/dscf/core/notification_service.rb', line 18

def resolve_adapter
  adapter_name = Rails.application.config.x.sms_adapter || :stub

  case adapter_name.to_sym
  when :stub then Adapters::SmsStub
  else raise ArgumentError, "Unknown SMS adapter: #{adapter_name}"
  end
end