class Grocer::SSLConnection
Attributes
certificate[RW]
gateway[RW]
passphrase[RW]
port[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/grocer/ssl_connection.rb, line 13 def initialize(options = {}) options.each do |key, val| send("#{key}=", val) end end
Public Instance Methods
connect()
click to toggle source
# 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?()
click to toggle source
# File lib/grocer/ssl_connection.rb, line 19 def connected? !@ssl.nil? end
disconnect()
click to toggle source
# File lib/grocer/ssl_connection.rb, line 46 def disconnect @ssl.close if @ssl @ssl = nil @sock.close if @sock @sock = nil end
reconnect()
click to toggle source
# File lib/grocer/ssl_connection.rb, line 54 def reconnect disconnect connect end