Class: BMO::GCM::Notification::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/bmo/gcm/notification.rb

Overview

The Payload contains the data sent to Apple

Defined Under Namespace

Classes: PayloadTooLarge

Constant Summary collapse

MAX_BYTE_SIZE =
4096

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Payload

Returns a new instance of Payload.



41
42
43
# File 'lib/bmo/gcm/notification.rb', line 41

def initialize(data)
  @data = Utils.coerce_to_symbols(data)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



39
40
41
# File 'lib/bmo/gcm/notification.rb', line 39

def data
  @data
end

Instance Method Details

#to_packageObject



45
46
47
# File 'lib/bmo/gcm/notification.rb', line 45

def to_package
  data
end

#validate!Object



49
50
51
52
53
54
55
56
57
# File 'lib/bmo/gcm/notification.rb', line 49

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