class EventMachine::ApnManager::Notification

Constants

DATA_MAX_BYTES

Attributes

expiry[RW]
identifier[RW]
token[R]

Public Class Methods

new(token, aps = {}, custom = {}, options = {}) click to toggle source
# File lib/em_apn_manager/notification.rb, line 13
def initialize(token, aps = {}, custom = {}, options = {})
  raise "Bad push token: #{token}" if token.nil? || (token.length != 64)

  @token  = token
  @aps    = aps
  @custom = custom

  self.identifier = options[:identifier] if options[:identifier]
  self.expiry = options[:expiry] if options[:expiry]
end

Public Instance Methods

data() click to toggle source

Documentation about this format is here: developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html

# File lib/em_apn_manager/notification.rb, line 30
def data
  identifier = @identifier || 0
  expiry     = @expiry || 0
  size = [payload].pack("a*").size
  data_array = [1, identifier, expiry, 32, token, size, payload]
  data_array.pack("cNNnH*na*")
end
identifier=(new_identifier) click to toggle source
# File lib/em_apn_manager/notification.rb, line 47
def identifier=(new_identifier)
  @identifier = new_identifier.to_i
end
payload() click to toggle source
# File lib/em_apn_manager/notification.rb, line 24
def payload
  Yajl::Encoder.encode(@custom.merge(:aps => @aps))
end
truncate_alert!() click to toggle source
# File lib/em_apn_manager/notification.rb, line 51
def truncate_alert!
  while data.size > DATA_MAX_BYTES && !@aps["alert"].nil? && @aps["alert"].size > 0
    @aps["alert"] = @aps["alert"][0..-2]
  end
end
validate!() click to toggle source
# File lib/em_apn_manager/notification.rb, line 38
def validate!
  if data.size > DATA_MAX_BYTES
    error = "max is #{DATA_MAX_BYTES} bytes, but got #{data.size}: #{payload.inspect}"
    raise PayloadTooLarge.new(error)
  else
    true
  end
end