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, options = {}) ⇒ 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
58 59 60 61 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 58 def initialize(tcpsock, sslsock) @tcpsock = tcpsock @sslsock = sslsock end |
Class Method Details
.host(sandbox) ⇒ String
Returns the URL to connect to.
50 51 52 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 50 def self.host(sandbox) sandbox ? APNS_SANDBOX_URL : APNS_PRODUCTION_URL end |
.open(cert, sandbox, pass = nil, options = {}) ⇒ APNSConnection
Opens a connection with APNS
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 32 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 = .fetch(:host, host(sandbox)) socket = Socket.tcp h, APNS_PORT, nil, nil, connect_timeout: .fetch(:connect_timeout, 30) ssl = OpenSSL::SSL::SSLSocket.new socket, ctx ssl.connect new socket, ssl end |
Instance Method Details
#close ⇒ Object
Closes the APNSConnection
64 65 66 67 |
# File 'lib/ruby-push-notifications/apns/apns_connection.rb', line 64 def close @sslsock.close @tcpsock.close end |