Class: EventMachine::APNS::Notification
- Inherits:
-
Object
- Object
- EventMachine::APNS::Notification
- Defined in:
- lib/em-apns/notification.rb
Defined Under Namespace
Classes: PayloadTooLarge
Constant Summary collapse
- DATA_MAX_BYTES =
256
Instance Attribute Summary collapse
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#data ⇒ Object
Documentation about this format is here: developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html.
-
#initialize(token, aps = {}, custom = {}, options = {}) ⇒ Notification
constructor
A new instance of Notification.
- #payload ⇒ Object
- #truncate_alert! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(token, aps = {}, custom = {}, options = {}) ⇒ Notification
Returns a new instance of Notification.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/em-apns/notification.rb', line 13 def initialize(token, aps = {}, custom = {}, = {}) raise "Bad push token: #{token}" if token.nil? || (token.length != 64) @token = token @aps = aps @custom = custom self.identifier = [:identifier] if [:identifier] self.expiry = [:expiry] if [:expiry] end |
Instance Attribute Details
#expiry ⇒ Object
Returns the value of attribute expiry.
11 12 13 |
# File 'lib/em-apns/notification.rb', line 11 def expiry @expiry end |
#identifier ⇒ Object
Returns the value of attribute identifier.
11 12 13 |
# File 'lib/em-apns/notification.rb', line 11 def identifier @identifier end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
10 11 12 |
# File 'lib/em-apns/notification.rb', line 10 def token @token end |
Instance Method Details
#data ⇒ Object
Documentation about this format is here: developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html
30 31 32 33 34 35 36 |
# File 'lib/em-apns/notification.rb', line 30 def data identifier = @identifier || 0 expiry = @expiry || 0 size = [payload].pack("a*").size data_array = [1, identifier, expiry, 32, token, size, payload] data_array.pack("cNNnH*na*") end |
#payload ⇒ Object
24 25 26 |
# File 'lib/em-apns/notification.rb', line 24 def payload @custom.merge(:aps => @aps).to_json end |
#truncate_alert! ⇒ Object
51 52 53 54 55 |
# File 'lib/em-apns/notification.rb', line 51 def truncate_alert! while data.size > DATA_MAX_BYTES && !@aps["alert"].nil? && @aps["alert"].size > 0 @aps["alert"] = @aps["alert"][0..-2] end end |
#validate! ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/em-apns/notification.rb', line 38 def validate! if data.size > DATA_MAX_BYTES error = "max is #{DATA_MAX_BYTES} bytes, but got #{data.size}: #{payload.inspect}" raise PayloadTooLarge.new(error) else true end end |