Class: BMO::APNS::Notification::Payload

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject (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_packageObject



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