Class: IORequest::SSLSockets::Client
- Inherits:
-
Object
- Object
- IORequest::SSLSockets::Client
- Defined in:
- lib/io_request/connection/ssl_sockets.rb
Overview
SSL socket client.
Instance Method Summary collapse
-
#connect(host = 'localhost', port = 8000) ⇒ Object
Connect to server.
- #connected? ⇒ Boolean
-
#disconnect ⇒ Object
Closes connection to server.
-
#initialize(authorizer: Authorizer.empty, certificate: nil, key: nil, &requests_handler) ⇒ Client
constructor
Initialize new client.
-
#request(*args, **options, &block) ⇒ Object
Wrapper over Client#request.
Constructor Details
#initialize(authorizer: Authorizer.empty, certificate: nil, key: nil, &requests_handler) ⇒ Client
Initialize new client.
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/io_request/connection/ssl_sockets.rb', line 112 def initialize( authorizer: Authorizer.empty, certificate: nil, key: nil, &requests_handler ) @authorizer = @requests_handler = requests_handler @client = nil initialize_ssl_context(certificate, key) end |
Instance Method Details
#connect(host = 'localhost', port = 8000) ⇒ Object
Connect to server.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/io_request/connection/ssl_sockets.rb', line 133 def connect(host = 'localhost', port = 8000) socket = TCPSocket.new(host, port) ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, @ctx) ssl_socket.sync_close = true ssl_socket.connect @client = IORequest::Client.new authorizer: @authorizer begin @client.open read_write: ssl_socket @client.on_request(&@requests_handler) @client.on_close do @client = nil end rescue StandardError ssl_socket.close @client = nil end end |
#connected? ⇒ Boolean
126 127 128 |
# File 'lib/io_request/connection/ssl_sockets.rb', line 126 def connected? !@client.nil? end |
#disconnect ⇒ Object
Closes connection to server.
154 155 156 157 158 159 |
# File 'lib/io_request/connection/ssl_sockets.rb', line 154 def disconnect return unless defined?(@client) && !@client.nil? @client.close @client = nil end |
#request(*args, **options, &block) ⇒ Object
Wrapper over Client#request
162 163 164 |
# File 'lib/io_request/connection/ssl_sockets.rb', line 162 def request(*args, **, &block) @client.request(*args, **, &block) end |