Class: PushNotificationSender
- Inherits:
-
Object
- Object
- PushNotificationSender
- Defined in:
- app/services/push_notification_sender.rb
Constant Summary collapse
- REQUIRED_KEYS =
%i[title body].freeze
- OPTIONAL_KEYS =
%i[click_action sound android_channel_id icon].freeze
Instance Attribute Summary collapse
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
Instance Method Summary collapse
-
#initialize(notification) ⇒ PushNotificationSender
constructor
A new instance of PushNotificationSender.
- #run ⇒ Object
Constructor Details
#initialize(notification) ⇒ PushNotificationSender
Returns a new instance of PushNotificationSender.
9 10 11 |
# File 'app/services/push_notification_sender.rb', line 9 def initialize(notification) @notification = notification end |
Instance Attribute Details
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
4 5 6 |
# File 'app/services/push_notification_sender.rb', line 4 def notification @notification end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/services/push_notification_sender.rb', line 13 def run return if notification.receiver.device_ids.blank? return if notification.delivered_with?(:fcm) return unless REQUIRED_KEYS.all? { |key| notification.respond_to?(key) } notification.receiver.device_ids.each do |device_id| fcm_client.send(message: (device_id)) rescue FirebaseCloudMessenger::Error job_class = Hertz::Fcm.deletion_job_class_name.safe_constantize job_class.perform_later(device_id) end notification.mark_delivered_with(:fcm) end |