Class: Neography::Connection
- Inherits:
-
Object
- Object
- Neography::Connection
- Defined in:
- lib/neography/connection.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#authentication ⇒ Object
readonly
Returns the value of attribute authentication.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cypher_path ⇒ Object
readonly
Returns the value of attribute cypher_path.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#gremlin_path ⇒ Object
readonly
Returns the value of attribute gremlin_path.
-
#http_receive_timeout ⇒ Object
readonly
Returns the value of attribute http_receive_timeout.
-
#http_send_timeout ⇒ Object
readonly
Returns the value of attribute http_send_timeout.
-
#log_enabled ⇒ Object
readonly
Returns the value of attribute log_enabled.
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_threads ⇒ Object
readonly
Returns the value of attribute max_threads.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Keeping backward compatability for folks who used “http://” syntax instead of “http”.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#slow_log_threshold ⇒ Object
readonly
Returns the value of attribute slow_log_threshold.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #authenticate(path = nil) ⇒ Object
- #configuration ⇒ Object
- #configure(protocol, server, port, directory) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #log(path, body) ⇒ Object
- #merge_options(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/neography/connection.rb', line 16 def initialize( = {}) config = merge_configuration() save_local_configuration(config) @client ||= Excon.new(config[:proxy] || "#{protocol}://#{@server}:#{@port}", :read_timeout => config[:http_receive_timeout], :write_timeout => config[:http_send_timeout], :persistent => config[:persistent], :user => config[:username], :password => config[:password]) #authenticate end |
Instance Attribute Details
#authentication ⇒ Object (readonly)
Returns the value of attribute authentication.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def authentication @authentication end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def client @client end |
#cypher_path ⇒ Object (readonly)
Returns the value of attribute cypher_path.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def cypher_path @cypher_path end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def directory @directory end |
#gremlin_path ⇒ Object (readonly)
Returns the value of attribute gremlin_path.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def gremlin_path @gremlin_path end |
#http_receive_timeout ⇒ Object (readonly)
Returns the value of attribute http_receive_timeout.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def http_receive_timeout @http_receive_timeout end |
#http_send_timeout ⇒ Object (readonly)
Returns the value of attribute http_send_timeout.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def http_send_timeout @http_send_timeout end |
#log_enabled ⇒ Object (readonly)
Returns the value of attribute log_enabled.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def log_enabled @log_enabled end |
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def log_file @log_file end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def logger @logger end |
#max_threads ⇒ Object (readonly)
Returns the value of attribute max_threads.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def max_threads @max_threads end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def parser @parser end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def port @port end |
#protocol ⇒ Object (readonly)
Keeping backward compatability for folks who used “http://” syntax instead of “http”
36 37 38 |
# File 'lib/neography/connection.rb', line 36 def protocol @protocol end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def proxy @proxy end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def server @server end |
#slow_log_threshold ⇒ Object (readonly)
Returns the value of attribute slow_log_threshold.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def slow_log_threshold @slow_log_threshold end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
8 9 10 |
# File 'lib/neography/connection.rb', line 8 def username @username end |
Instance Method Details
#authenticate(path = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/neography/connection.rb', line 93 def authenticate(path = nil) unless @authentication.empty? auth_type = @authentication.keys.first @client.set_auth( path, @authentication[auth_type][:username], @authentication[auth_type][:password] ) # Force http client to always send auth credentials without # waiting for WWW-Authenticate headers, thus saving one request # roundtrip for each URI. Only works for HTTP basic auth. @client.www_auth.basic_auth.challenge(configuration) if auth_type == 'basic_auth' end end |
#configuration ⇒ Object
40 41 42 |
# File 'lib/neography/connection.rb', line 40 def configuration @configuration ||= "#{protocol}://#{@server}:#{@port}#{@directory}" end |
#configure(protocol, server, port, directory) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/neography/connection.rb', line 28 def configure(protocol, server, port, directory) @protocol = protocol @server = server @port = port @directory = directory end |
#log(path, body) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/neography/connection.rb', line 81 def log(path, body) if @log_enabled start_time = Time.now response = yield time = ((Time.now - start_time) * 1000).round(2) @logger.info "[Neography::Query] #{path} #{body} [#{time}ms]" if time >= slow_log_threshold response else yield end end |
#merge_options(options) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/neography/connection.rb', line 44 def () = .merge!(@authentication) if [:headers] [:headers].merge!(@user_agent) [:headers].merge!('X-Stream' => true) unless [:headers].key?('X-Stream') [:headers].merge!(@max_execution_time) end end |