Class: Pushr::MessageApns
- Inherits:
-
Message
- Object
- Message
- Pushr::MessageApns
- Defined in:
- lib/pushr/message_apns.rb
Constant Summary collapse
- POSTFIX =
'apns'
Instance Attribute Summary collapse
-
#attributes_for_device ⇒ Object
Returns the value of attribute attributes_for_device.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#category ⇒ Object
Returns the value of attribute category.
-
#content_available ⇒ Object
Returns the value of attribute content_available.
-
#device ⇒ Object
Returns the value of attribute device.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#sound ⇒ Object
Returns the value of attribute sound.
Instance Method Summary collapse
- #alert ⇒ Object
- #alert=(alert) ⇒ Object
- #id ⇒ Object
- #payload ⇒ Object
- #payload_size ⇒ Object
- #to_hash ⇒ Object
- #to_message ⇒ Object
Instance Attribute Details
#attributes_for_device ⇒ Object
Returns the value of attribute attributes_for_device.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def attributes_for_device @attributes_for_device end |
#badge ⇒ Object
Returns the value of attribute badge.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def badge @badge end |
#category ⇒ Object
Returns the value of attribute category.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def category @category end |
#content_available ⇒ Object
Returns the value of attribute content_available.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def content_available @content_available end |
#device ⇒ Object
Returns the value of attribute device.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def device @device end |
#expiry ⇒ Object
Returns the value of attribute expiry.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def expiry @expiry end |
#priority ⇒ Object
Returns the value of attribute priority.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def priority @priority end |
#sound ⇒ Object
Returns the value of attribute sound.
5 6 7 |
# File 'lib/pushr/message_apns.rb', line 5 def sound @sound end |
Instance Method Details
#alert ⇒ Object
22 23 24 25 26 27 |
# File 'lib/pushr/message_apns.rb', line 22 def alert string_or_json = @alert return MultiJson.load(string_or_json) rescue return string_or_json end |
#alert=(alert) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/pushr/message_apns.rb', line 14 def alert=(alert) if alert.is_a?(Hash) @alert = MultiJson.dump(alert) else @alert = alert end end |
#id ⇒ Object
29 30 31 |
# File 'lib/pushr/message_apns.rb', line 29 def id @id ||= OpenSSL::Random.random_bytes(4) end |
#payload ⇒ Object
43 44 45 |
# File 'lib/pushr/message_apns.rb', line 43 def payload MultiJson.dump(as_json) end |
#payload_size ⇒ Object
47 48 49 |
# File 'lib/pushr/message_apns.rb', line 47 def payload_size payload.bytesize end |
#to_hash ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/pushr/message_apns.rb', line 51 def to_hash hsh = { type: self.class.to_s, app: app, device: device, alert: alert, badge: badge, sound: sound, expiry: expiry, category: category, attributes_for_device: attributes_for_device, priority: priority, content_available: content_available } hsh[Pushr::Core.external_id_tag] = external_id if external_id hsh end |
#to_message ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/pushr/message_apns.rb', line 33 def data = '' data << [1, [device].pack('H*').bytesize, [device].pack('H*')].pack('CnA*') data << [2, payload.bytesize, payload].pack('CnA*') data << [3, id.bytesize, id].pack('CnA*') data << [4, 4, expiry].pack('CnN') data << [5, 1, priority].pack('CnC') ([2, data.bytesize].pack('CN') + data) end |