Class: Pling::APN::Feedback

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/pling/apn/feedback.rb

Overview

Instances of this class can be used to retrieve device identifiers that have been marked invalid. This should be done on a regular basis since Apple will ban you if you continue to send push notifications to invalid devices.

The only operation supported by instances of this class is #get. The method simply returns a list of the identifieres that have been marked invalid since you last called this method.

Examples:


feedback = Pling::APN::Feedback.new(:certificate => '/path/to/certificate.pem')
tokens = feedback.get

tokens.each do |token|
  # process token
end

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Feedback

Creates a new instance of this class and establishes a connection to Apple’s Push Notification Service, retrieves a list of invalid device identifiers and then closes the connection, since Apple closes it on their side.

For testing purposes, you should use Apple’s sandbox feedback service feedback.sandbox.push.apple.com. In order to do this, you have to specify the optional :host parameter when creating instances of this class.

Examples:


Pling::APN::Feedback.new(
  :certificate => '/path/to/certificate.pem',
  :host => 'feedback.push.apple.com',
  :port => 2196
)

Parameters:

  • configuration (Hash)

    Parameters to control the connection configuration

Options Hash (configuration):

  • :certificate (#to_s)

    Path to PEM certificate file (Required)

  • :host (String)

    Host to connect to (Default: feedback.push.apple.com)

  • :port (Integer)

    Port to connect to (Default: 2196)



50
51
52
# File 'lib/pling/apn/feedback.rb', line 50

def initialize(configuration)
  setup_configuration(configuration, :require => :certificate)
end

Instance Method Details

#getArray<String>

Retrieves all device identifiers that have been marked invalid since the method has been called last.

Returns:

  • (Array<String>)

    The list of invalid device identifiers



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pling/apn/feedback.rb', line 60

def get
  tokens = []
  while line = connection.gets
    _, length = line.unpack("Nn")
    break if length.nil?

    tokens << line.unpack("x6H#{length << 1}").first
  end
  connection.close
  tokens
end