Class: Grocer::SSLConnection
- Inherits:
-
Object
- Object
- Grocer::SSLConnection
- Extended by:
- Forwardable
- Defined in:
- lib/grocer/ssl_connection.rb
Instance Attribute Summary collapse
-
#certificate ⇒ Object
Returns the value of attribute certificate.
-
#gateway ⇒ Object
Returns the value of attribute gateway.
-
#passphrase ⇒ Object
Returns the value of attribute passphrase.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(options = {}) ⇒ SSLConnection
constructor
A new instance of SSLConnection.
- #reconnect ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SSLConnection
Returns a new instance of SSLConnection.
13 14 15 16 17 |
# File 'lib/grocer/ssl_connection.rb', line 13 def initialize( = {}) .each do |key, val| send("#{key}=", val) end end |
Instance Attribute Details
#certificate ⇒ Object
Returns the value of attribute certificate.
11 12 13 |
# File 'lib/grocer/ssl_connection.rb', line 11 def certificate @certificate end |
#gateway ⇒ Object
Returns the value of attribute gateway.
11 12 13 |
# File 'lib/grocer/ssl_connection.rb', line 11 def gateway @gateway end |
#passphrase ⇒ Object
Returns the value of attribute passphrase.
11 12 13 |
# File 'lib/grocer/ssl_connection.rb', line 11 def passphrase @passphrase end |
#port ⇒ Object
Returns the value of attribute port.
11 12 13 |
# File 'lib/grocer/ssl_connection.rb', line 11 def port @port end |
Instance Method Details
#connect ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/grocer/ssl_connection.rb', line 23 def connect context = OpenSSL::SSL::SSLContext.new if certificate if certificate.respond_to?(:read) cert_data = certificate.read certificate.rewind if certificate.respond_to?(:rewind) else cert_data = File.read(certificate) end context.key = OpenSSL::PKey::RSA.new(cert_data, passphrase) context.cert = OpenSSL::X509::Certificate.new(cert_data) end @sock = TCPSocket.new(gateway, port) @sock.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true @ssl = OpenSSL::SSL::SSLSocket.new(@sock, context) @ssl.sync = true @ssl.connect end |
#connected? ⇒ Boolean
19 20 21 |
# File 'lib/grocer/ssl_connection.rb', line 19 def connected? !@ssl.nil? end |
#disconnect ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/grocer/ssl_connection.rb', line 46 def disconnect @ssl.close if @ssl @ssl = nil @sock.close if @sock @sock = nil end |
#reconnect ⇒ Object
54 55 56 57 |
# File 'lib/grocer/ssl_connection.rb', line 54 def reconnect disconnect connect end |