Class: ApnsSimple::Notification

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

Constant Summary collapse

PAYLOAD_MAX_BYTESIZE =
2048

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, custom_payload = {}) ⇒ Notification

Returns a new instance of Notification.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apns_simple/notification.rb', line 11

def initialize(options, custom_payload = {})
  token = options.fetch(:token)
  alert = options[:alert]
  badge = options[:badge]
  sound = options[:sound]
  content_available = options[:content_available]

  payload_hash = { aps: {} }
  payload_hash[:aps][:alert] = alert if alert
  payload_hash[:aps][:badge] = badge if badge
  payload_hash[:aps][:sound] = sound if sound
  payload_hash[:aps]['content-available'] = 1 if content_available
  payload_hash.merge! custom_payload

  token_item = pack_token_item(token)
  payload_item = pack_payload_item(payload_hash)
  frame = compose_frame(token_item, payload_item)
  @payload = pack_frame(frame)
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

#error_codeObject

Returns the value of attribute error_code.



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

def error_code
  @error_code
end

#error_messageObject

Returns the value of attribute error_message.



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

def error_message
  @error_message
end

#payloadObject (readonly)

Returns the value of attribute payload.



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

def payload
  @payload
end