Class: ActionNativePush::Notification
- Inherits:
-
Object
- Object
- ActionNativePush::Notification
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- lib/action_native_push/notification.rb
Overview
Action Native Push Notification
A notification that can be delivered to devices.
Instance Attribute Summary collapse
-
#apple_data ⇒ Object
Returns the value of attribute apple_data.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#body ⇒ Object
Returns the value of attribute body.
-
#context ⇒ Object
Returns the value of attribute context.
-
#data ⇒ Object
Returns the value of attribute data.
-
#google_data ⇒ Object
Returns the value of attribute google_data.
-
#high_priority ⇒ Object
Returns the value of attribute high_priority.
-
#sound ⇒ Object
Returns the value of attribute sound.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #deliver_later_to(devices) ⇒ Object
- #deliver_to(device) ⇒ Object
-
#initialize(title: nil, body: nil, badge: nil, thread_id: nil, sound: nil, high_priority: true, apple_data: {}, google_data: {}, data: {}, **context) ⇒ Notification
constructor
Attributes.
Constructor Details
#initialize(title: nil, body: nil, badge: nil, thread_id: nil, sound: nil, high_priority: true, apple_data: {}, google_data: {}, data: {}, **context) ⇒ Notification
Attributes
title - The title
body - The message body
badge - The badge number to display on the app icon
thread_id - The thread ID for grouping notifications
sound - The sound to play when the notification is received
high_priority - Whether to send the notification with high priority (default: true).
For silent notifications is recommended to set this to false
apple_data - Apple Push Notification Service (APNS) specific data
google_data - Firebase Cloud Messaging (FCM) specific data
data - Custom data to be sent with the notification
Any extra attributes are set inside the `context` hash.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/action_native_push/notification.rb', line 47 def initialize(title: nil, body: nil, badge: nil, thread_id: nil, sound: nil, high_priority: true, apple_data: {}, google_data: {}, data: {}, **context) @title = title @body = body @badge = badge @thread_id = thread_id @sound = sound @high_priority = high_priority @apple_data = apple_data @google_data = google_data @data = data @context = context end |
Instance Attribute Details
#apple_data ⇒ Object
Returns the value of attribute apple_data.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def apple_data @apple_data end |
#badge ⇒ Object
Returns the value of attribute badge.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def badge @badge end |
#body ⇒ Object
Returns the value of attribute body.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def body @body end |
#context ⇒ Object
Returns the value of attribute context.
11 12 13 |
# File 'lib/action_native_push/notification.rb', line 11 def context @context end |
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def data @data end |
#google_data ⇒ Object
Returns the value of attribute google_data.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def google_data @google_data end |
#high_priority ⇒ Object
Returns the value of attribute high_priority.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def high_priority @high_priority end |
#sound ⇒ Object
Returns the value of attribute sound.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def sound @sound end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def thread_id @thread_id end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/action_native_push/notification.rb', line 10 def title @title end |
#token ⇒ Object
Returns the value of attribute token.
12 13 14 |
# File 'lib/action_native_push/notification.rb', line 12 def token @token end |
Class Method Details
.queue_as(name) ⇒ Object
21 22 23 |
# File 'lib/action_native_push/notification.rb', line 21 def queue_as(name) self.queue_name = name end |
Instance Method Details
#as_json ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/action_native_push/notification.rb', line 72 def as_json { title: title, body: body, badge: badge, thread_id: thread_id, sound: sound, high_priority: high_priority, apple_data: apple_data, google_data: google_data, data: data, **context }.compact end |
#deliver_later_to(devices) ⇒ Object
66 67 68 69 70 |
# File 'lib/action_native_push/notification.rb', line 66 def deliver_later_to(devices) Array(devices).each do |device| ApplicationPushNotificationJob.set(queue: queue_name).perform_later(self.class.name, self.as_json, device) end end |
#deliver_to(device) ⇒ Object
60 61 62 63 64 |
# File 'lib/action_native_push/notification.rb', line 60 def deliver_to(device) if enabled run_callbacks(:delivery) { device.push(self) } end end |