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.
12 13 14 15 16 |
# File 'lib/grocer/ssl_connection.rb', line 12 def initialize( = {}) .each do |key, val| send("#{key}=", val) end end |
Instance Attribute Details
#certificate ⇒ Object
Returns the value of attribute certificate.
10 11 12 |
# File 'lib/grocer/ssl_connection.rb', line 10 def certificate @certificate end |
#gateway ⇒ Object
Returns the value of attribute gateway.
10 11 12 |
# File 'lib/grocer/ssl_connection.rb', line 10 def gateway @gateway end |
#passphrase ⇒ Object
Returns the value of attribute passphrase.
10 11 12 |
# File 'lib/grocer/ssl_connection.rb', line 10 def passphrase @passphrase end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/grocer/ssl_connection.rb', line 10 def port @port end |
Instance Method Details
#connect ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/grocer/ssl_connection.rb', line 22 def connect context = OpenSSL::SSL::SSLContext.new if certificate cert_data = File.read(certificate) context.key = OpenSSL::PKey::RSA.new(cert_data, passphrase) context.cert = OpenSSL::X509::Certificate.new(cert_data) end @sock = TCPSocket.new(gateway, port) @ssl = OpenSSL::SSL::SSLSocket.new(@sock, context) @ssl.sync = true @ssl.connect end |
#connected? ⇒ Boolean
18 19 20 |
# File 'lib/grocer/ssl_connection.rb', line 18 def connected? !@ssl.nil? end |
#disconnect ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/grocer/ssl_connection.rb', line 37 def disconnect @ssl.close if @ssl @ssl = nil @sock.close if @sock @sock = nil end |
#reconnect ⇒ Object
45 46 47 48 |
# File 'lib/grocer/ssl_connection.rb', line 45 def reconnect disconnect connect end |