Class: APN::Feedback

Inherits:
Object
  • Object
show all
Includes:
Connection::Base
Defined in:
lib/apn/feedback.rb

Overview

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.

Instance Attribute Summary

Attributes included from Connection::Base

#logger, #opts

Instance Method Summary collapse

Methods included from Connection::Base

#initialize, #resque_log, #socket

Instance Method Details

#data(force = nil) ⇒ Object

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.



31
32
33
34
# File 'lib/apn/feedback.rb', line 31

def data(force = nil)
  @feedback = nil if force
  @feedback ||= receive
end

#inspectObject

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



42
43
44
# File 'lib/apn/feedback.rb', line 42

def inspect
  "#<#{self.class.name}: #{to_s}>"
end

#to_sObject

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



47
48
49
# File 'lib/apn/feedback.rb', line 47

def to_s
  "#{@socket ? 'Connected' : 'Connection not currently established'} to #{apn_host} on #{apn_port}"
end

#tokens(force = nil) ⇒ Object

Wrapper around data returning just an array of token strings.



37
38
39
# File 'lib/apn/feedback.rb', line 37

def tokens(force = nil)
  data(force).map(&:token)
end