Class: PushNotifier::APNS::Connection
- Inherits:
-
Object
- Object
- PushNotifier::APNS::Connection
- Defined in:
- lib/push_notifier/apns/connection.rb
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
Returns the value of attribute certificate.
-
#passphrase ⇒ Object
readonly
Returns the value of attribute passphrase.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(uri, certificate, passphrase) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(uri, certificate, passphrase) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 |
# File 'lib/push_notifier/apns/connection.rb', line 10 def initialize(uri, certificate, passphrase) @uri = uri @certificate = File.read(certificate) @passphrase = passphrase end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
8 9 10 |
# File 'lib/push_notifier/apns/connection.rb', line 8 def certificate @certificate end |
#passphrase ⇒ Object (readonly)
Returns the value of attribute passphrase.
8 9 10 |
# File 'lib/push_notifier/apns/connection.rb', line 8 def passphrase @passphrase end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
8 9 10 |
# File 'lib/push_notifier/apns/connection.rb', line 8 def socket @socket end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
8 9 10 |
# File 'lib/push_notifier/apns/connection.rb', line 8 def ssl @ssl end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/push_notifier/apns/connection.rb', line 8 def uri @uri end |
Instance Method Details
#close ⇒ Object
32 33 34 35 36 |
# File 'lib/push_notifier/apns/connection.rb', line 32 def close @ssl.close @socket.close @ssl, @socket = nil, nil end |
#open ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/push_notifier/apns/connection.rb', line 16 def open @socket = TCPSocket.new(@uri.host, @uri.port) ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.cert = OpenSSL::X509::Certificate.new @certificate ssl_context.key = OpenSSL::PKey::RSA.new @certificate, @passphrase @ssl = OpenSSL::SSL::SSLSocket.new @socket,ssl_context @ssl.connect end |
#write(data) ⇒ Object
29 30 31 |
# File 'lib/push_notifier/apns/connection.rb', line 29 def write(data) @ssl.write(data) end |