Class: RubyPushNotifications::APNS::APNSConnection
- Inherits:
-
Object
- Object
- RubyPushNotifications::APNS::APNSConnection
- Extended by:
- Forwardable
- Defined in:
- lib/ruby-push-notifications/apns/apns_connection.rb
Overview
This class encapsulates a connection with APNS.
Constant Summary collapse
- APNS_SANDBOX_URL =
'gateway.sandbox.push.apple.com'- APNS_PRODUCTION_URL =
'gateway.push.apple.com'- APNS_PORT =
2195
Class Method Summary collapse
-
.host(sandbox) ⇒ String
Returns the URL to connect to.
-
.open(cert, sandbox, pass = nil) ⇒ APNSConnection
Opens a connection with APNS.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the APNSConnection.
-
#initialize(tcpsock, sslsock) ⇒ APNSConnection
constructor
Initializes the APNSConnection.
Constructor Details
#initialize(tcpsock, sslsock) ⇒ APNSConnection
Initializes the APNSConnection
56 57 58 59 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 56 def initialize(tcpsock, sslsock) @tcpsock = tcpsock @sslsock = sslsock end |
Class Method Details
.host(sandbox) ⇒ String
Returns the URL to connect to.
48 49 50 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 48 def self.host(sandbox) sandbox ? APNS_SANDBOX_URL : APNS_PRODUCTION_URL end |
.open(cert, sandbox, pass = nil) ⇒ APNSConnection
Opens a connection with APNS
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 30 def self.open(cert, sandbox, pass = nil) ctx = OpenSSL::SSL::SSLContext.new ctx.key = OpenSSL::PKey::RSA.new cert, pass ctx.cert = OpenSSL::X509::Certificate.new cert h = host sandbox socket = TCPSocket.new h, APNS_PORT ssl = OpenSSL::SSL::SSLSocket.new socket, ctx ssl.connect new socket, ssl end |
Instance Method Details
#close ⇒ Object
Closes the APNSConnection
62 63 64 65 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 62 def close @sslsock.close @tcpsock.close end |