Class: BMO::APNS::Notification::Payload
- Inherits:
-
Object
- Object
- BMO::APNS::Notification::Payload
- Defined in:
- lib/bmo/apns/notification.rb
Overview
The Payload contains the data sent to Apple
Defined Under Namespace
Classes: PayloadTooLarge
Constant Summary collapse
- MAX_BYTE_SIZE =
256
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Payload
constructor
A new instance of Payload.
- #to_package ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(data) ⇒ Payload
Returns a new instance of Payload.
47 48 49 |
# File 'lib/bmo/apns/notification.rb', line 47 def initialize(data) @data = Utils.coerce_to_symbols(data) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
45 46 47 |
# File 'lib/bmo/apns/notification.rb', line 45 def data @data end |
Instance Method Details
#to_package ⇒ Object
51 52 53 |
# File 'lib/bmo/apns/notification.rb', line 51 def to_package data.to_json.bytes.to_a.pack('C*') end |
#validate! ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/bmo/apns/notification.rb', line 55 def validate! if to_package.size > MAX_BYTE_SIZE str = <<-EOS Payload size should be less than #{Payload::MAX_BYTE_SIZE} bytes EOS fail PayloadTooLarge, str end true end |