Class: Grocer::Notification

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload = {}) ⇒ Notification

Returns a new instance of Notification.



9
10
11
12
13
14
15
# File 'lib/grocer/notification.rb', line 9

def initialize(payload = {})
  @identifier = 0

  payload.each do |key, val|
    send("#{key}=", val)
  end
end

Instance Attribute Details

#alertObject

Returns the value of attribute alert.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def alert
  @alert
end

#badgeObject

Returns the value of attribute badge.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def badge
  @badge
end

#customObject

Returns the value of attribute custom.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def custom
  @custom
end

#device_tokenObject

Returns the value of attribute device_token.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def device_token
  @device_token
end

#expiryObject

Returns the value of attribute expiry.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def expiry
  @expiry
end

#identifierObject

Returns the value of attribute identifier.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def identifier
  @identifier
end

#soundObject

Returns the value of attribute sound.



6
7
8
# File 'lib/grocer/notification.rb', line 6

def sound
  @sound
end

Instance Method Details

#to_bytesObject



17
18
19
20
21
22
# File 'lib/grocer/notification.rb', line 17

def to_bytes
  validate_payload
  payload = encoded_payload

  [1, identifier, expiry_epoch_time, device_token_length, sanitized_device_token, payload.length].pack('CNNnH64n') << payload
end