Class: Houston::Connection
- Inherits:
-
Object
- Object
- Houston::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/houston/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.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(uri, certificate, passphrase) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
- #open? ⇒ Boolean
Constructor Details
#initialize(uri, certificate, passphrase) ⇒ Connection
Returns a new instance of Connection.
27 28 29 30 31 |
# File 'lib/houston/connection.rb', line 27 def initialize(uri, certificate, passphrase) @uri = URI(uri) @certificate = certificate.to_s @passphrase = passphrase.to_s unless passphrase.nil? end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
12 13 14 |
# File 'lib/houston/connection.rb', line 12 def certificate @certificate end |
#passphrase ⇒ Object (readonly)
Returns the value of attribute passphrase.
12 13 14 |
# File 'lib/houston/connection.rb', line 12 def passphrase @passphrase end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
12 13 14 |
# File 'lib/houston/connection.rb', line 12 def socket @socket end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
12 13 14 |
# File 'lib/houston/connection.rb', line 12 def ssl @ssl end |
Class Method Details
.open(uri, certificate, passphrase) {|connection| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/houston/connection.rb', line 15 def open(uri, certificate, passphrase) return unless block_given? connection = new(uri, certificate, passphrase) connection.open yield connection connection.close end |
Instance Method Details
#close ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/houston/connection.rb', line 51 def close return false if closed? @ssl.close @ssl = nil @socket.close @socket = nil end |
#closed? ⇒ Boolean
61 62 63 |
# File 'lib/houston/connection.rb', line 61 def closed? not open? end |
#open ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/houston/connection.rb', line 33 def open return false if open? @socket = TCPSocket.new(@uri.host, @uri.port) context = OpenSSL::SSL::SSLContext.new context.key = OpenSSL::PKey::RSA.new(@certificate, @passphrase) context.cert = OpenSSL::X509::Certificate.new(@certificate) @ssl = OpenSSL::SSL::SSLSocket.new(@socket, context) @ssl.sync = true @ssl.connect end |
#open? ⇒ Boolean
47 48 49 |
# File 'lib/houston/connection.rb', line 47 def open? not (@ssl && @socket).nil? end |