Class: ActsAsHocPushable::PushNotification
- Inherits:
-
Object
- Object
- ActsAsHocPushable::PushNotification
- Defined in:
- lib/acts_as_hoc_pushable/push_notification.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#devices ⇒ Object
Returns the value of attribute devices.
-
#message ⇒ Object
Returns the value of attribute message.
-
#title ⇒ Object
writeonly
Sets the attribute title.
Class Method Summary collapse
- .send_push_notification(devices:, title: nil, message: nil, **data) ⇒ Object
- .send_push_notification_to_topic(topic:, title: nil, message: nil, **data) ⇒ Object
- .send_silent_push_notification(devices:, **data) ⇒ Object
- .send_silent_push_notification_to_topic(topic:, **data) ⇒ Object
Instance Method Summary collapse
-
#initialize(devices:, title:, message:, **data) ⇒ PushNotification
constructor
A new instance of PushNotification.
- #perform ⇒ Object
- #perform_topic(topic:) ⇒ Object
Constructor Details
#initialize(devices:, title:, message:, **data) ⇒ PushNotification
Returns a new instance of PushNotification.
8 9 10 11 12 13 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 8 def initialize(devices:, title:, message:, **data) @devices = devices @title = title = @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6 def data @data end |
#devices ⇒ Object
Returns the value of attribute devices.
6 7 8 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6 def devices @devices end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6 def end |
#title=(value) ⇒ Object
Sets the attribute title
6 7 8 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 6 def title=(value) @title = value end |
Class Method Details
.send_push_notification(devices:, title: nil, message: nil, **data) ⇒ Object
24 25 26 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 24 def self.send_push_notification(devices:, title: nil, message: nil, **data) new(devices: devices, title: title, message: , **data).perform end |
.send_push_notification_to_topic(topic:, title: nil, message: nil, **data) ⇒ Object
15 16 17 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 15 def self.send_push_notification_to_topic(topic:, title: nil, message: nil, **data) new(devices: nil, title: title, message: , **data).perform_topic(topic: topic) end |
.send_silent_push_notification(devices:, **data) ⇒ Object
28 29 30 31 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 28 def self.send_silent_push_notification(devices:, **data) silent_data = data.merge({ content_avaiable: true }) new(devices: devices, title: nil, message: nil, **silent_data).perform end |
.send_silent_push_notification_to_topic(topic:, **data) ⇒ Object
19 20 21 22 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 19 def self.send_silent_push_notification_to_topic(topic:, **data) silent_data = data.merge({ content_avaiable: true }) new(devices: nil, title: nil, message: nil, **silent_data).perform_topic(topic: topic) end |
Instance Method Details
#perform ⇒ Object
38 39 40 41 42 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 38 def perform tokens = @devices.map {|d| d.token } response = client.send(tokens, ) handle_response(response) end |
#perform_topic(topic:) ⇒ Object
33 34 35 36 |
# File 'lib/acts_as_hoc_pushable/push_notification.rb', line 33 def perform_topic(topic:) response = client.send_to_topic(topic, ) handle_response(response) end |