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
# File lib/apn/feedback.rb, line 24 def initialize(options = {}) @apn_host, @apn_port = options[:host], options[:port] end
Public Instance Methods
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
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
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
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
# File lib/apn/feedback.rb, line 64 def client @client ||= APN::Client.new(host: host, port: port, certificate: APN.certificate, password: APN.password) end
# File lib/apn/feedback.rb, line 71 def host @apn_host || "feedback.push.apple.com" end
# File lib/apn/feedback.rb, line 75 def port @apn_port || 2196 end
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