Class: Network::Connection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  @uri = URI.parse(uri)
  @read_timeout = options[:read_timeout] || READ_TIMEOUT
  @open_timeout = options[:open_timeout] || OPEN_TIMEOUT
  @verify_peer  = options[:verify_peer] || false
  @debugger_stream = nil
  @headers = {}
  @proxy_addr = options[:proxy_addr]
  @proxy_port = options[:proxy_port]
  @proxy_user = options[:proxy_user]
  @proxy_pass = options[:proxy_pass]
end

Instance Attribute Details

#ca_fileObject

Returns the value of attribute ca_file.



19
20
21
# File 'lib/network/connection.rb', line 19

def ca_file
  @ca_file
end

#debugger_streamObject

Returns the value of attribute debugger_stream.



19
20
21
# File 'lib/network/connection.rb', line 19

def debugger_stream
  @debugger_stream
end

#headersObject

Returns the value of attribute headers.



19
20
21
# File 'lib/network/connection.rb', line 19

def headers
  @headers
end

#loggerObject

Returns the value of attribute logger.



19
20
21
# File 'lib/network/connection.rb', line 19

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



19
20
21
# File 'lib/network/connection.rb', line 19

def open_timeout
  @open_timeout
end

#pemObject (readonly)

Returns the value of attribute pem.



17
18
19
# File 'lib/network/connection.rb', line 17

def pem
  @pem
end

#read_timeoutObject

Returns the value of attribute read_timeout.



19
20
21
# File 'lib/network/connection.rb', line 19

def read_timeout
  @read_timeout
end

#request_filterObject

Returns the value of attribute request_filter.



19
20
21
# File 'lib/network/connection.rb', line 19

def request_filter
  @request_filter
end

#response_filterObject

Returns the value of attribute response_filter.



19
20
21
# File 'lib/network/connection.rb', line 19

def response_filter
  @response_filter
end

#senderObject

Returns the value of attribute sender.



19
20
21
# File 'lib/network/connection.rb', line 19

def sender
  @sender
end

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/network/connection.rb', line 17

def uri
  @uri
end

#verify_peerObject

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

Returns:

  • (Boolean)


75
76
77
# File 'lib/network/connection.rb', line 75

def use_ssl?
  @uri.scheme == "https"
end