Class: MobileNotify::Apns::Notification
- Inherits:
-
Object
- Object
- MobileNotify::Apns::Notification
- Defined in:
- lib/mobile_notify/apns/notification.rb
Direct Known Subclasses
Constant Summary collapse
- MAX_PAYLOAD_LENGTH =
256
Class Method Summary collapse
-
.parse(bitstring) ⇒ Notification
Counterpart of Notification#to_s - parses from binary string.
Instance Method Summary collapse
-
#initialize(device_token, payload) ⇒ Notification
constructor
Creates new notification with given token and payload APNs4r::Notification.new ‘e754dXXXX…’, { :aps => => “Hey, dude!”, :badge => 1, :custom_data => “asd” }.
-
#to_data ⇒ String
Converts to binary string wich can be writen directly into socket.
- #valid? ⇒ Boolean
Constructor Details
#initialize(device_token, payload) ⇒ Notification
Creates new notification with given token and payload APNs4r::Notification.new ‘e754dXXXX…’, { :aps => => “Hey, dude!”, :badge => 1, :custom_data => “asd” }
22 23 24 25 |
# File 'lib/mobile_notify/apns/notification.rb', line 22 def initialize(device_token, payload) @device_token = device_token.delete(' ') @payload = payload.kind_of?(Hash) ? payload.to_json : payload end |
Class Method Details
.parse(bitstring) ⇒ Notification
Counterpart of Notification#to_s - parses from binary string
12 13 14 15 |
# File 'lib/mobile_notify/apns/notification.rb', line 12 def self.parse(bitstring) command, tokenlen, device_token, payloadlen, payload = bitstring.unpack("CnH64na*") new(device_token, payload) end |
Instance Method Details
#to_data ⇒ String
Converts to binary string wich can be writen directly into socket
33 34 35 |
# File 'lib/mobile_notify/apns/notification.rb', line 33 def to_data [0, 32, @device_token, @payload.length, @payload ].pack("CnH*na*") end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/mobile_notify/apns/notification.rb', line 27 def valid? @payload.length <= MAX_PAYLOAD_LENGTH end |