Class: APNS::Notification
- Inherits:
-
Object
- Object
- APNS::Notification
- Includes:
- ActiveModel::Model
- Defined in:
- lib/mercurius/apns/notification.rb
Constant Summary collapse
- MAX_PAYLOAD_BYTES =
2048
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#other ⇒ Object
Returns the value of attribute other.
-
#sound ⇒ Object
Returns the value of attribute sound.
Instance Method Summary collapse
- #==(that) ⇒ Object
-
#initialize(attributes = {}) ⇒ Notification
constructor
A new instance of Notification.
- #pack(device_token) ⇒ Object
- #package_device_token(device_token) ⇒ Object
- #packaged_message ⇒ Object
- #payload ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Notification
Returns a new instance of Notification.
10 11 12 13 |
# File 'lib/mercurius/apns/notification.rb', line 10 def initialize(attributes = {}) @attributes = attributes super end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
7 8 9 |
# File 'lib/mercurius/apns/notification.rb', line 7 def alert @alert end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/mercurius/apns/notification.rb', line 8 def attributes @attributes end |
#badge ⇒ Object
Returns the value of attribute badge.
7 8 9 |
# File 'lib/mercurius/apns/notification.rb', line 7 def badge @badge end |
#other ⇒ Object
Returns the value of attribute other.
7 8 9 |
# File 'lib/mercurius/apns/notification.rb', line 7 def other @other end |
#sound ⇒ Object
Returns the value of attribute sound.
7 8 9 |
# File 'lib/mercurius/apns/notification.rb', line 7 def sound @sound end |
Instance Method Details
#==(that) ⇒ Object
38 39 40 |
# File 'lib/mercurius/apns/notification.rb', line 38 def ==(that) attributes == that.attributes end |
#pack(device_token) ⇒ Object
24 25 26 |
# File 'lib/mercurius/apns/notification.rb', line 24 def pack(device_token) [0, 0, 32, package_device_token(device_token), 0, .bytesize, ].pack("ccca*cca*") end |
#package_device_token(device_token) ⇒ Object
28 29 30 |
# File 'lib/mercurius/apns/notification.rb', line 28 def package_device_token(device_token) [device_token.gsub(/[\s|<|>]/,'')].pack('H*') end |
#packaged_message ⇒ Object
32 33 34 35 36 |
# File 'lib/mercurius/apns/notification.rb', line 32 def { aps: payload }.to_json.gsub(/\\u([\da-fA-F]{4})/) do |m| [$1].pack("H*").unpack("n*").pack("U*") end end |
#payload ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/mercurius/apns/notification.rb', line 15 def payload { alert: alert, badge: badge, sound: sound, other: other }.compact end |
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/mercurius/apns/notification.rb', line 42 def valid? .bytesize <= MAX_PAYLOAD_BYTES end |