Class: AppleShove::APNS::NotifyConnection
- Inherits:
-
Connection
- Object
- Connection
- AppleShove::APNS::NotifyConnection
- Includes:
- Celluloid
- Defined in:
- lib/apple_shove/apns/notify_connection.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pending_notifications ⇒ Object
Returns the value of attribute pending_notifications.
Attributes inherited from Connection
Class Method Summary collapse
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(p12, sandbox) ⇒ NotifyConnection
constructor
A new instance of NotifyConnection.
- #send(notification) ⇒ Object
- #shutdown ⇒ Object
Methods inherited from Connection
#disconnect, #reconnect, #safe_last_used, #socket
Constructor Details
#initialize(p12, sandbox) ⇒ NotifyConnection
Returns a new instance of NotifyConnection.
11 12 13 14 15 16 17 18 19 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 11 def initialize(p12, sandbox) @name = self.class.generate_name(p12, sandbox) @last_message = nil @pending_notifications = 0 host = "gateway.#{sandbox ? 'sandbox.' : ''}push.apple.com" super host, 2195, p12 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 9 def name @name end |
#pending_notifications ⇒ Object
Returns the value of attribute pending_notifications.
8 9 10 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 8 def pending_notifications @pending_notifications end |
Class Method Details
.generate_name(p12, sandbox) ⇒ Object
21 22 23 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 21 def self.generate_name(p12, sandbox) Digest::SHA1.hexdigest("#{p12}#{sandbox}") end |
Instance Method Details
#connect ⇒ Object
27 28 29 30 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 27 def connect super @last_used = Time.now end |
#send(notification) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/apple_shove/apns/notify_connection.rb', line 32 def send(notification) = notification. begin if @last_used && Time.now - safe_last_used > CONFIG[:reconnect_timer] * 60 Logger.info("refreshing connection", self, notification) reconnect end socket.write rescue Exception => e handler = WriteExceptionHandler.new(e) Logger.warn(handler., self, notification) begin reconnect if handler.reconnect? socket.write @last_message if handler.rewrite? && @last_message rescue Exception => e Logger.warn("failed while trying to recover from write error", self, notification) end retry if handler.retry? else Logger.info("delivered notification", self, notification) @last_message = @last_used = Time.now end @pending_notifications -= 1 end |