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