Class: Pushable::Message
- Inherits:
-
Object
- Object
- Pushable::Message
- Defined in:
- app/models/pushable/message.rb
Direct Known Subclasses
Constant Summary collapse
- MAX_TOKENS_AT_ONCE =
999
Instance Method Summary collapse
- #alert ⇒ Object
- #badge ⇒ Object
- #enqueue(devices, payload) ⇒ Object
- #other ⇒ Object
- #send_to(pushable) ⇒ Object
- #sound ⇒ Object
Instance Method Details
#alert ⇒ Object
23 24 25 |
# File 'app/models/pushable/message.rb', line 23 def alert '' end |
#badge ⇒ Object
27 28 29 |
# File 'app/models/pushable/message.rb', line 27 def badge 1 end |
#enqueue(devices, payload) ⇒ Object
17 18 19 20 21 |
# File 'app/models/pushable/message.rb', line 17 def enqueue(devices, payload) devices.pluck(:id).each_slice(MAX_TOKENS_AT_ONCE) do |tokens| Pushable::Messenger.perform_later tokens, payload.deep_stringify_keys end end |
#other ⇒ Object
35 36 37 |
# File 'app/models/pushable/message.rb', line 35 def other {} end |
#send_to(pushable) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/pushable/message.rb', line 5 def send_to(pushable) if pushable.is_a? ActiveRecord::Relation enqueue Device.android.owned_by(pushable), format(:android) enqueue Device.ios.owned_by(pushable), format(:ios) elsif pushable.is_a?(ActiveRecord::Base) enqueue pushable.devices.android, format(:android) enqueue pushable.devices.ios, format(:ios) else raise ArgumentError.new('#send_to only accepts an ActiveRecord Relation or ActiveRecord object!') end end |
#sound ⇒ Object
31 32 33 |
# File 'app/models/pushable/message.rb', line 31 def sound 'default' end |