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
- #get(data) ⇒ Object
-
#initialize(uri, options = {}) ⇒ Connection
constructor
options are: :read_timeout :open_timeout :verify_peer :proxy_addr :proxy_port :proxy_user :proxy_pass.
- #pem_file(file) ⇒ Object
- #post(data) ⇒ Object
- #use_ssl? ⇒ Boolean
Constructor Details
#initialize(uri, options = {}) ⇒ Connection
options are:
:read_timeout
:open_timeout
:verify_peer
:proxy_addr
:proxy_port
:proxy_user
:proxy_pass
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/network/connection.rb', line 37 def initialize(uri, = {}) @uri = URI.parse(uri) @read_timeout = [:read_timeout] || READ_TIMEOUT @open_timeout = [:open_timeout] || OPEN_TIMEOUT @verify_peer = [:verify_peer] || false @debugger_stream = nil @headers = {} @proxy_addr = [:proxy_addr] @proxy_port = [:proxy_port] @proxy_user = [:proxy_user] @proxy_pass = [:proxy_pass] 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
#get(data) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/network/connection.rb', line 62 def get(data) try_request do log_request(data, "GET") response = nil uri.query = (uri.select(:query) << data).join("&") ms = Benchmark.realtime do response = http.get(uri.request_uri) end log_response(response, ms) response end end |
#pem_file(file) ⇒ Object
79 80 81 |
# File 'lib/network/connection.rb', line 79 def pem_file(file) @pem = File.read(file) end |
#post(data) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/network/connection.rb', line 50 def post(data) try_request do log_request(data, "POST") response = nil ms = Benchmark.realtime do response = http.post(uri.request_uri, data, post_headers(data)) end log_response(response, ms) response end end |
#use_ssl? ⇒ Boolean
75 76 77 |
# File 'lib/network/connection.rb', line 75 def use_ssl? @uri.scheme == "https" end |