Class: Mameapns::Notification
- Inherits:
-
Object
- Object
- Mameapns::Notification
show all
- Includes:
- Options
- Defined in:
- lib/mameapns/notification.rb
Instance Method Summary
collapse
Methods included from Options
included, #initialize, #to_hash, #to_json
Instance Method Details
#as_json ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/mameapns/notification.rb', line 25
def as_json
json = {}
json['aps'] = {}
json['aps']['alert'] = alert if alert
json['aps']['badge'] = badge if badge
json['aps']['sound'] = sound if sound
json['aps'].merge!(attributes_for_device) if attributes_for_device
json
end
|
#device_token=(token) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/mameapns/notification.rb', line 17
def device_token=(token)
if !token.nil?
@device_token = token.gsub(/[ <>]/, "")
else
@device_token = nil
end
end
|
#payload ⇒ Object
35
36
37
|
# File 'lib/mameapns/notification.rb', line 35
def payload
as_json.to_json
end
|
#payload_size ⇒ Object
39
40
41
|
# File 'lib/mameapns/notification.rb', line 39
def payload_size
payload.bytesize
end
|
#to_binary ⇒ Object
43
44
45
|
# File 'lib/mameapns/notification.rb', line 43
def to_binary
[1, identifier, expiry, 0, 32, device_token, 0, payload_size, payload].pack("cNNccH*cca*")
end
|