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) ⇒ 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_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

#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

Returns:

  • (Boolean)


50
51
52
# File 'lib/network/connection.rb', line 50

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