Class: Push::MessageApns
- Inherits:
-
Message
- Object
- Message
- Push::MessageApns
- Defined in:
- lib/push/message_apns.rb
Constant Summary collapse
- SELECT_TIMEOUT =
0.2- ERROR_TUPLE_BYTES =
6- APN_ERRORS =
{ 1 => "Processing error", 2 => "Missing device token", 3 => "Missing topic", 4 => "Missing payload", 5 => "Missing token size", 6 => "Missing topic size", 7 => "Missing payload size", 8 => "Invalid token", 255 => "None (unknown error)" }
Instance Method Summary collapse
- #alert ⇒ Object
- #alert=(alert) ⇒ Object
- #attributes_for_device ⇒ Object
- #attributes_for_device=(attrs) ⇒ Object
- #payload ⇒ Object
- #payload_size ⇒ Object
-
#to_message(options = {}) ⇒ Object
This method conforms to the enhanced binary format.
- #use_connection ⇒ Object
Instance Method Details
#alert ⇒ Object
42 43 44 45 |
# File 'lib/push/message_apns.rb', line 42 def alert string_or_json = properties[:alert] MultiJson.load(string_or_json) rescue string_or_json end |
#alert=(alert) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/push/message_apns.rb', line 34 def alert=(alert) if alert.is_a?(Hash) properties[:alert] = MultiJson.dump(alert) else properties[:alert] = alert end end |
#attributes_for_device ⇒ Object
30 31 32 |
# File 'lib/push/message_apns.rb', line 30 def attributes_for_device MultiJson.load(properties[:attributes_for_device]) if properties[:attributes_for_device] end |
#attributes_for_device=(attrs) ⇒ Object
25 26 27 28 |
# File 'lib/push/message_apns.rb', line 25 def attributes_for_device=(attrs) raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash) properties[:attributes_for_device] = MultiJson.dump(attrs) end |
#payload ⇒ Object
58 59 60 |
# File 'lib/push/message_apns.rb', line 58 def payload MultiJson.dump(as_json) end |
#payload_size ⇒ Object
62 63 64 |
# File 'lib/push/message_apns.rb', line 62 def payload_size payload.bytesize end |
#to_message(options = {}) ⇒ Object
This method conforms to the enhanced binary format. developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
49 50 51 52 |
# File 'lib/push/message_apns.rb', line 49 def ( = {}) id_for_pack = [:for_validation] ? 0 : id [1, id_for_pack, expiry, 0, 32, device, payload_size, payload].pack("cNNccH*na*") end |
#use_connection ⇒ Object
54 55 56 |
# File 'lib/push/message_apns.rb', line 54 def use_connection Push::Daemon::ApnsSupport::ConnectionApns end |