Class: ApplePush::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/apple-push/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_token, message) ⇒ Notification

Returns a new instance of Notification.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/apple-push/notification.rb', line 5

def initialize(device_token, message)
  if device_token
    self.device_token = device_token
  else
    raise "Invalid device token"
  end
  if message.is_a?(Hash)
    self.alert = message[:alert]
    self.badge = message[:badge]
    self.sound = message[:sound]
    self.other = message[:other]
  elsif message.is_a?(String)
    self.alert = message
  else
    raise "Notification message needs to be either a hash or a string"
  end
end

Instance Attribute Details

#alertObject

Returns the value of attribute alert.



3
4
5
# File 'lib/apple-push/notification.rb', line 3

def alert
  @alert
end

#badgeObject

Returns the value of attribute badge.



3
4
5
# File 'lib/apple-push/notification.rb', line 3

def badge
  @badge
end

#device_tokenObject

Returns the value of attribute device_token.



3
4
5
# File 'lib/apple-push/notification.rb', line 3

def device_token
  @device_token
end

#otherObject

Returns the value of attribute other.



3
4
5
# File 'lib/apple-push/notification.rb', line 3

def other
  @other
end

#soundObject

Returns the value of attribute sound.



3
4
5
# File 'lib/apple-push/notification.rb', line 3

def sound
  @sound
end

Instance Method Details

#to_sObject



31
32
33
34
35
# File 'lib/apple-push/notification.rb', line 31

def to_s
  dt = self.device_token
  pl = self.payload
  [0, 0, dt.size, dt, 0, pl.size, pl].pack("ccca*cca*")
end