Class: ActiveNotifier::Transports::Pushmeup
- Inherits:
-
Object
- Object
- ActiveNotifier::Transports::Pushmeup
- Defined in:
- lib/active_notifier/transports/pushmeup.rb
Defined Under Namespace
Classes: Deliverable, MultipleDeliverables, PushNotificationJob
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
Instance Method Summary collapse
- #deliverable(notifier) ⇒ Object
-
#initialize(configuration, notifier) ⇒ Pushmeup
constructor
A new instance of Pushmeup.
Constructor Details
#initialize(configuration, notifier) ⇒ Pushmeup
Returns a new instance of Pushmeup.
12 13 14 |
# File 'lib/active_notifier/transports/pushmeup.rb', line 12 def initialize(configuration, notifier) self.configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/active_notifier/transports/pushmeup.rb', line 7 def configuration @configuration end |
Class Method Details
.deliver(tokens, payload, network) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_notifier/transports/pushmeup.rb', line 43 def self.deliver(tokens, payload, network) case network when 'apns' APNS.send_notification(tokens, payload) when 'gcm' GCM.send_notification(tokens, payload) else fail "Unrecognized network" end end |
Instance Method Details
#deliverable(notifier) ⇒ Object
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 |
# File 'lib/active_notifier/transports/pushmeup.rb', line 16 def deliverable(notifier) if configuration[:device_list_attribute] devices = notifier.recipient.public_send(configuration[:device_list_attribute]) else devices = Array(notifier.recipient) end deliverables = devices.map do |device| token_attribute = configuration.token_attribute token = device.public_send(token_attribute) if token.blank? raise ActiveNotifier::DeliveryImpossible.new("Recipient mobile token not present.") end network_attribute = configuration.network_attribute network = device.public_send(network_attribute) if token.blank? raise ActiveNotifier::DeliveryImpossible.new("Recipient network token not present.") end payload = configuration.serializer.new(notifier).as_json(root: false) Deliverable.new(token, payload, network) end MultipleDeliverables.new(deliverables) end |