Class: BMO::APNS::Notification

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

Overview

The Notification Class handles all the packaging logic

Defined Under Namespace

Classes: DeviceToken, Payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_token, payload) ⇒ Notification

Returns a new instance of Notification.



11
12
13
14
# File 'lib/bmo/apns/notification.rb', line 11

def initialize(device_token, payload)
  @device_token = DeviceToken.new(device_token)
  @payload      = Payload.new(payload)
end

Instance Attribute Details

#device_tokenObject (readonly)

Returns the value of attribute device_token.



9
10
11
# File 'lib/bmo/apns/notification.rb', line 9

def device_token
  @device_token
end

#payloadObject (readonly)

Returns the value of attribute payload.



9
10
11
# File 'lib/bmo/apns/notification.rb', line 9

def payload
  @payload
end

Instance Method Details

#to_packageObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bmo/apns/notification.rb', line 16

def to_package
  payload_packaged      = payload.to_package
  device_token_packaged = device_token.to_package
  [
    0, 0,
    device_token_packaged.size,
    device_token_packaged,
    0,
    payload_packaged.size,
    payload_packaged
  ].pack('ccca*cca*')
end

#validate!Object



29
30
31
32
# File 'lib/bmo/apns/notification.rb', line 29

def validate!
  device_token.validate!
  payload.validate!
end