Class: APNS::Notification
- Inherits:
-
Object
- Object
- APNS::Notification
- Defined in:
- lib/pushmeup/apns/notification.rb
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#device_token ⇒ Object
Returns the value of attribute device_token.
-
#other ⇒ Object
Returns the value of attribute other.
-
#sound ⇒ Object
Returns the value of attribute sound.
Instance Method Summary collapse
-
#initialize(device_token, message) ⇒ Notification
constructor
A new instance of Notification.
- #packaged_message ⇒ Object
- #packaged_notification ⇒ Object
- #packaged_token ⇒ Object
Constructor Details
#initialize(device_token, message) ⇒ Notification
Returns a new instance of Notification.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pushmeup/apns/notification.rb', line 5 def initialize(device_token, ) self.device_token = device_token if .is_a?(Hash) self.alert = [:alert] self.badge = [:badge] self.sound = [:sound] self.other = [:other] elsif .is_a?(String) self.alert = else raise "Notification needs to have either a hash or string" end end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
3 4 5 |
# File 'lib/pushmeup/apns/notification.rb', line 3 def alert @alert end |
#badge ⇒ Object
Returns the value of attribute badge.
3 4 5 |
# File 'lib/pushmeup/apns/notification.rb', line 3 def badge @badge end |
#device_token ⇒ Object
Returns the value of attribute device_token.
3 4 5 |
# File 'lib/pushmeup/apns/notification.rb', line 3 def device_token @device_token end |
#other ⇒ Object
Returns the value of attribute other.
3 4 5 |
# File 'lib/pushmeup/apns/notification.rb', line 3 def other @other end |
#sound ⇒ Object
Returns the value of attribute sound.
3 4 5 |
# File 'lib/pushmeup/apns/notification.rb', line 3 def sound @sound end |
Instance Method Details
#packaged_message ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/pushmeup/apns/notification.rb', line 29 def aps = {'aps'=> {} } aps['aps']['alert'] = self.alert if self.alert aps['aps']['badge'] = self.badge if self.badge aps['aps']['sound'] = self.sound if self.sound aps.merge!(self.other) if self.other aps.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")} end |
#packaged_notification ⇒ Object
19 20 21 22 23 |
# File 'lib/pushmeup/apns/notification.rb', line 19 def packaged_notification pt = self.packaged_token pm = self. [0, 0, 32, pt, 0, pm.bytesize, pm].pack("ccca*cca*") end |
#packaged_token ⇒ Object
25 26 27 |
# File 'lib/pushmeup/apns/notification.rb', line 25 def packaged_token [device_token.gsub(/[\s|<|>]/,'')].pack('H*') end |