Class: Network::Connection
- Inherits:
-
Object
- Object
- Network::Connection
- Defined in:
- lib/network/connection.rb
Constant Summary collapse
- READ_TIMEOUT =
60
- OPEN_TIMEOUT =
30
- VERIFY_NONE =
OpenSSL::SSL::VERIFY_NONE
- VERIFY_PEER =
OpenSSL::SSL::VERIFY_PEER
Instance Attribute Summary collapse
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#debugger_stream ⇒ Object
Returns the value of attribute debugger_stream.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#pem ⇒ Object
readonly
Returns the value of attribute pem.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#request_filter ⇒ Object
Returns the value of attribute request_filter.
-
#response_filter ⇒ Object
Returns the value of attribute response_filter.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
Instance Method Summary collapse
-
#initialize(uri) ⇒ Connection
constructor
A new instance of Connection.
- #pem_file(file) ⇒ Object
- #post(data) ⇒ Object
- #use_ssl? ⇒ Boolean
Constructor Details
#initialize(uri) ⇒ Connection
Returns a new instance of Connection.
29 30 31 32 33 34 35 36 |
# File 'lib/network/connection.rb', line 29 def initialize(uri) @uri = URI.parse(uri) @read_timeout = READ_TIMEOUT @open_timeout = OPEN_TIMEOUT @verify_peer = false @debugger_stream = nil @headers = {} end |
Instance Attribute Details
#ca_file ⇒ Object
Returns the value of attribute ca_file.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def ca_file @ca_file end |
#debugger_stream ⇒ Object
Returns the value of attribute debugger_stream.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def debugger_stream @debugger_stream end |
#headers ⇒ Object
Returns the value of attribute headers.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def headers @headers end |
#logger ⇒ Object
Returns the value of attribute logger.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def open_timeout @open_timeout end |
#pem ⇒ Object (readonly)
Returns the value of attribute pem.
17 18 19 |
# File 'lib/network/connection.rb', line 17 def pem @pem end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def read_timeout @read_timeout end |
#request_filter ⇒ Object
Returns the value of attribute request_filter.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def request_filter @request_filter end |
#response_filter ⇒ Object
Returns the value of attribute response_filter.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def response_filter @response_filter end |
#sender ⇒ Object
Returns the value of attribute sender.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def sender @sender end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
17 18 19 |
# File 'lib/network/connection.rb', line 17 def uri @uri end |
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
19 20 21 |
# File 'lib/network/connection.rb', line 19 def verify_peer @verify_peer end |
Instance Method Details
#pem_file(file) ⇒ Object
54 55 56 |
# File 'lib/network/connection.rb', line 54 def pem_file(file) @pem = File.read(file) end |
#post(data) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/network/connection.rb', line 38 def post(data) try_request do log_request(data) response = nil ms = Benchmark.realtime do response = http.post(uri.path, data, post_headers(data)) end log_response(response, ms) response end end |
#use_ssl? ⇒ Boolean
50 51 52 |
# File 'lib/network/connection.rb', line 50 def use_ssl? @uri.scheme == "https" end |