class APN::Feedback

When supplied with the certificate path and the desired environment, connects to the APN Feedback Service and returns any response as an array of APN::FeedbackItem elements.

See README for usage and details.

Public Class Methods

new(options = {}) click to toggle source
# File lib/apn/feedback.rb, line 24
def initialize(options = {})
  @apn_host, @apn_port = options[:host], options[:port]
end

Public Instance Methods

data(force = nil) click to toggle source

Returns array of APN::FeedbackItem elements read from Apple. Connects to Apple once and caches the data, continues to returns cached data unless called with data(true), which clears the existing feedback array. Note that once you force resetting the cache you loose all previous feedback, so be sure you've already processed it.

# File lib/apn/feedback.rb, line 32
def data(force = nil)
  @feedback = nil if force
  @feedback ||= receive
end
inspect() click to toggle source

Prettify to return meaningful status information when printed. Can't add these directly to connection/base, because Resque depends on decoding to_s

# File lib/apn/feedback.rb, line 43
def inspect
  "#<#{self.class.name}: #{to_s}>"
end
to_s() click to toggle source

Prettify to return meaningful status information when printed. Can't add these directly to connection/base, because Resque depends on decoding to_s

# File lib/apn/feedback.rb, line 48
def to_s
  "#{@client ? 'Connected' : 'Connection not currently established'} to #{host} on #{port}"
end
tokens(force = nil) click to toggle source

Wrapper around data returning just an array of token strings.

# File lib/apn/feedback.rb, line 38
def tokens(force = nil)
  data(force).map(&:token)
end

Protected Instance Methods

client() click to toggle source
# File lib/apn/feedback.rb, line 64
def client
  @client ||= APN::Client.new(host: host,
                              port: port,
                              certificate: APN.certificate,
                              password: APN.password)
end
host() click to toggle source
# File lib/apn/feedback.rb, line 71
def host
  @apn_host || "feedback.push.apple.com"
end
port() click to toggle source
# File lib/apn/feedback.rb, line 75
def port
  @apn_port || 2196
end
receive() click to toggle source

Connects to Apple's Feedback Service and checks if there's anything there for us. Returns an array of APN::FeedbackItem pairs

# File lib/apn/feedback.rb, line 56
def receive
  feedbacks = []
  while f = client.feedback
    feedbacks << f
  end
  return feedbacks
end