Class: APNS::Notification

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/mercurius/apns/notification.rb

Constant Summary collapse

MAX_PAYLOAD_BYTES =
2048

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Notification

Returns a new instance of Notification.



12
13
14
15
# File 'lib/mercurius/apns/notification.rb', line 12

def initialize(attributes = {})
  @attributes = attributes
  super
end

Instance Attribute Details

#alertObject

Returns the value of attribute alert.



7
8
9
# File 'lib/mercurius/apns/notification.rb', line 7

def alert
  @alert
end

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/mercurius/apns/notification.rb', line 8

def attributes
  @attributes
end

#badgeObject

Returns the value of attribute badge.



7
8
9
# File 'lib/mercurius/apns/notification.rb', line 7

def badge
  @badge
end

#content_availableObject

Returns the value of attribute content_available.



7
8
9
# File 'lib/mercurius/apns/notification.rb', line 7

def content_available
  @content_available
end

#otherObject

Returns the value of attribute other.



7
8
9
# File 'lib/mercurius/apns/notification.rb', line 7

def other
  @other
end

#soundObject

Returns the value of attribute sound.



7
8
9
# File 'lib/mercurius/apns/notification.rb', line 7

def sound
  @sound
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/mercurius/apns/notification.rb', line 35

def ==(other)
  attributes == other.attributes
end

#pack(device_token) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mercurius/apns/notification.rb', line 27

def pack(device_token)
  data = [
    package_device_token(device_token),
    packaged_payload
  ].compact.join
  [2, data.bytes.count, data].pack 'cNa*'
end

#payloadObject



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

def payload
  {
    'alert' => alert,
    'badge' => badge,
    'sound' => sound,
    'other' => other,
    'content-available' => content_available
  }.compact
end