Class: ApnsSimple::Notification
- Inherits:
-
Object
- Object
- ApnsSimple::Notification
- Defined in:
- lib/apns_simple/notification.rb
Constant Summary collapse
- PAYLOAD_MAX_BYTESIZE =
2048
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
-
#initialize(options, custom_payload = {}) ⇒ Notification
constructor
A new instance of Notification.
Constructor Details
#initialize(options, custom_payload = {}) ⇒ Notification
Returns a new instance of Notification.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apns_simple/notification.rb', line 11 def initialize(, custom_payload = {}) token = .fetch(:token) alert = [:alert] badge = [:badge] sound = [:sound] || 'default' content_available = [:content_available] payload_hash = { aps: {} } payload_hash[:aps][:alert] = alert if alert payload_hash[:aps][:badge] = badge if badge payload_hash[:aps][:sound] = sound if sound payload_hash[:aps]['content-available'] = 1 if content_available payload_hash.merge! custom_payload packed_token = [token.gsub(/[<\s>]/,'')].pack('H*') = payload_hash.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")} payload_size = .bytesize if payload_size > PAYLOAD_MAX_BYTESIZE self.error = true self. = "Payload size is #{payload_size} bytes but maximum #{PAYLOAD_MAX_BYTESIZE} bytes allowed." end self.payload = [0, 0, 32, packed_token, 0, payload_size, ].pack("ccca*cca*") end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/apns_simple/notification.rb', line 9 def error @error end |
#error_code ⇒ Object
Returns the value of attribute error_code.
9 10 11 |
# File 'lib/apns_simple/notification.rb', line 9 def error_code @error_code end |
#error_message ⇒ Object
Returns the value of attribute error_message.
9 10 11 |
# File 'lib/apns_simple/notification.rb', line 9 def @error_message end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'lib/apns_simple/notification.rb', line 8 def payload @payload end |