Class: Imobile::PushNotificationsContext
- Inherits:
-
Object
- Object
- Imobile::PushNotificationsContext
- Defined in:
- lib/imobile/push_notification.rb
Overview
Carries state for delivering batched notifications.
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
The APNs client certificate.
-
#socket ⇒ Object
readonly
The raw SSL connection to the APNs.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the APNs connection.
-
#closed? ⇒ Boolean
True if the context’s APNs connection is closed.
-
#finalize ⇒ Object
Called when the context is garbage-collected.
-
#initialize(path_or_certificate) ⇒ PushNotificationsContext
constructor
Creates a push context for a fixed Apple Push Notifications server.
-
#push(notification) ⇒ Object
Sends a notification via this context’s APNs connection.
Constructor Details
#initialize(path_or_certificate) ⇒ PushNotificationsContext
Creates a push context for a fixed Apple Push Notifications server.
Args:
path_or_certificate:: see Imobile.push_notification
101 102 103 104 105 |
# File 'lib/imobile/push_notification.rb', line 101 def initialize(path_or_certificate) @certificate = PushNotifications.read_certificate path_or_certificate @socket = PushNotifications.apns_socket @certificate, :push @closed = false end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
The APNs client certificate.
116 117 118 |
# File 'lib/imobile/push_notification.rb', line 116 def certificate @certificate end |
#socket ⇒ Object (readonly)
The raw SSL connection to the APNs.
114 115 116 |
# File 'lib/imobile/push_notification.rb', line 114 def socket @socket end |
Instance Method Details
#close ⇒ Object
Closes the APNs connection. The context is unusable afterwards.
108 109 110 111 |
# File 'lib/imobile/push_notification.rb', line 108 def close @socket.close unless @closed @closed = true end |
#closed? ⇒ Boolean
True if the context’s APNs connection is closed.
119 120 121 |
# File 'lib/imobile/push_notification.rb', line 119 def closed? @closed end |
#finalize ⇒ Object
Called when the context is garbage-collected.
Closes the APNs connection, if it wasn’t already closed.
126 127 128 |
# File 'lib/imobile/push_notification.rb', line 126 def finalize close unless @closed end |
#push(notification) ⇒ Object
Sends a notification via this context’s APNs connection.
Args:
notification:: see Imobile.push_notification
Raises a RuntimeError if the context’s APNs connection was closed.
92 93 94 95 |
# File 'lib/imobile/push_notification.rb', line 92 def push(notification) raise "The context's APNs connection was closed" if @closed @socket.write PushNotifications.encode_notification(notification) end |