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.



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

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



37
38
39
# File 'lib/bmo/gcm/notification.rb', line 37

def data
  @data
end

Instance Method Details

#to_packageObject



43
44
45
# File 'lib/bmo/gcm/notification.rb', line 43

def to_package
  data
end

#validate!Object



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

def validate!
  if to_package.to_json.bytesize > MAX_BYTE_SIZE
    str = <<-EOS
      Payload size should be less than #{Payload::MAX_BYTE_SIZE} bytes
    EOS
    fail PayloadTooLarge, str
  end
  true
end