lib/suj/pusher/apn_notification.rb in suj-pusher-0.2.0 vs lib/suj/pusher/apn_notification.rb in suj-pusher-0.2.3

- old
+ new

@@ -21,10 +21,14 @@ def data @data ||= encode_data end + def to_s + data + end + private def get_expiry if @ttl.to_i == 0 return 0 @@ -32,15 +36,34 @@ return Time.now.to_i + @ttl.to_i end end def encode_data - identifier = 0 - expiry = get_expiry - size = [payload].pack("a*").size - data_array = [1, identifier, expiry, 32, @token, size, payload] - info("PAYLOAD: #{data_array}") - data_array.pack("cNNnH*na*") + # identifier = 0 + # expiry = get_expiry + # size = [payload].pack("a*").size + # data_array = [1, identifier, expiry, 32, @token, size, payload] + # info("PAYLOAD: #{data_array}") + # data_array.pack("cNNnH*na*") + + items = [ + [1, 32, @token ], # token + [2, payload.bytesize, payload ], # payload + [3, 4, OpenSSL::Random::random_bytes(4) ], # random identifier + [4, 4, get_expiry ], # expiration date + [5, 1, 10 ] # high priority + ] + + info("PAYLOAD: #{items}") + + frame_data = + items[0].pack("CnH*") + + items[1].pack("CnA*") + + items[2].pack("CnA*") + + items[3].pack("CnN") + + items[4].pack("CnC") + + [2,frame_data.bytesize,frame_data].pack("CNA*") end end end end