Class: LeadZeppelin::APNS::Notification
- Inherits:
-
Object
- Object
- LeadZeppelin::APNS::Notification
- Defined in:
- lib/lead_zeppelin/apns/notification.rb
Instance Attribute Summary collapse
-
#device_token ⇒ Object
readonly
Returns the value of attribute device_token.
-
#expiry ⇒ Object
readonly
Returns the value of attribute expiry.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(device_token, message, opts = {}) ⇒ Notification
constructor
A new instance of Notification.
- #message_json ⇒ Object
- #packaged_token ⇒ Object
- #payload ⇒ Object
Constructor Details
#initialize(device_token, message, opts = {}) ⇒ Notification
Returns a new instance of Notification.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 6 def initialize(device_token, , opts={}) @device_token = device_token @opts = opts @identifier = @opts[:identifier] || SecureRandom.random_bytes(4) @identifier = @identifier.to_s @expiry = @opts[:expiry].nil? ? 1 : @opts[:expiry].to_i if opts[:raw] == true @message = elsif .is_a?(Hash) other = .delete(:other) @message = {aps: } @message.merge!(other) if other elsif .is_a?(String) @message = {aps: {alert: }} else raise ArgumentError, "notification message must be hash or string" end end |
Instance Attribute Details
#device_token ⇒ Object (readonly)
Returns the value of attribute device_token.
4 5 6 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 4 def device_token @device_token end |
#expiry ⇒ Object (readonly)
Returns the value of attribute expiry.
4 5 6 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 4 def expiry @expiry end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 4 def identifier @identifier end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 4 def opts @opts end |
Instance Method Details
#message_json ⇒ Object
36 37 38 39 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 36 def return @message if @opts[:raw] == true @message_json ||= MultiJson.encode @message end |
#packaged_token ⇒ Object
32 33 34 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 32 def packaged_token [device_token.gsub(/[\s|<|>]/,'')].pack('H*') end |
#payload ⇒ Object
28 29 30 |
# File 'lib/lead_zeppelin/apns/notification.rb', line 28 def payload [1, @identifier, @expiry, 0, 32, packaged_token, 0, .bytesize, ].pack("cA4Ncca*cca*") end |