Class: PushNotificationAndPush
- Inherits:
-
Object
- Object
- PushNotificationAndPush
- Defined in:
- app/my_lib/push_notification_andpush.rb
Instance Method Summary collapse
-
#initialize(type) ⇒ PushNotificationAndPush
constructor
A new instance of PushNotificationAndPush.
-
#publish(to:, title:, body:, deep_link:, id:, type:, click_action: nil, ring_it_loud: false) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity.
- #publish_event(event_name, options = {}) ⇒ Object
- #publish_promotion(promotion_id) ⇒ Object
Constructor Details
#initialize(type) ⇒ PushNotificationAndPush
Returns a new instance of PushNotificationAndPush.
8 9 10 |
# File 'app/my_lib/push_notification_andpush.rb', line 8 def initialize(type) @firebase_for = type end |
Instance Method Details
#publish(to:, title:, body:, deep_link:, id:, type:, click_action: nil, ring_it_loud: false) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/my_lib/push_notification_andpush.rb', line 14 def publish(to:, title:, body:, deep_link:, id:, type:, click_action: nil, ring_it_loud: false) # rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/PerceivedComplexity if ring_it_loud && for_staff android_channel_id = 'HUNGRYHUB_DELIVERY' sound = 'delivery.caf' else android_channel_id = 'HUNGRYHUB_PARTNER' sound = 'hungry.caf' end payload = { to: to, notification: { click_action: click_action, title: title, body: body, sound: sound, android_channel_id: android_channel_id, }, android_channel_id: 'transaction', data: { id: id, deepLink: deep_link, notification: { title: title, body: body, }, data: { deepLink: deep_link, id: id, type: type, }, }, } Retriable.retriable(on: [Curl::Err::ConnectionFailedError, Curl::Err::CantReconnectError], tries: 5, base_interval: 1, on_retry: APMErrorHandler.report_retriable_event('notification.push_notification')) do if for_user begin user_firebase.push(payload) rescue Andpush::Unauthorized, Andpush::NotFound UserDevice.find_by(token: to)&.delete end elsif for_staff begin staff_firebase.push(payload) rescue Andpush::Unauthorized, Andpush::NotFound StaffDevice.find_by(token: to)&.delete end end end end |
#publish_event(event_name, options = {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/my_lib/push_notification_andpush.rb', line 86 def publish_event(event_name, = {}) case event_name.to_sym when :reservation_created push_reservation_created() when :reservation_cancelled push_reservation_cancelled() # send_reservation_cancelled_message(options) when :reservation_modified push_reservation_modified() # send_reservation_modified_message(options) when :redemption_completed push_redemption_completed() # send_redemption_completed_message(options) when :cooking_reminder push_cooking_reminder() when :points_expiry_reminder push_points_expiry_reminder() else raise(NotImplementedError) end end |
#publish_promotion(promotion_id) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/my_lib/push_notification_andpush.rb', line 70 def publish_promotion(promotion_id) promotion = Promotion.find(promotion_id) MyLocaleManager.available_locales.each do |locale| topic = "/topics/promotions-#{locale}" publish( to: topic, title: promotion.send("title_#{locale}".to_sym), body: promotion.send("content_#{locale}".to_sym), deep_link: "app://promotions/#{promotion_id}", id: promotion_id, type: 'promotions', ) end end |