Class: Neography::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/neography/connection.rb

Constant Summary collapse

USER_AGENT =
"Neography/#{Neography::VERSION}"
ACTIONS =
["get", "post", "put", "delete"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = ENV['NEO4J_URL'] || {}) ⇒ Connection

Returns a new instance of Connection.



15
16
17
18
19
20
21
# File 'lib/neography/connection.rb', line 15

def initialize(options = ENV['NEO4J_URL'] || {})
  config = merge_configuration(options)
  save_local_configuration(config)
  @client = HTTPClient.new
  @client.send_timeout = 1200 # 10 minutes
  @client.receive_timeout = 1200
end

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



8
9
10
# File 'lib/neography/connection.rb', line 8

def authentication
  @authentication
end

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/neography/connection.rb', line 8

def client
  @client
end

#cypher_pathObject

Returns the value of attribute cypher_path.



8
9
10
# File 'lib/neography/connection.rb', line 8

def cypher_path
  @cypher_path
end

#directoryObject

Returns the value of attribute directory.



8
9
10
# File 'lib/neography/connection.rb', line 8

def directory
  @directory
end

#gremlin_pathObject

Returns the value of attribute gremlin_path.



8
9
10
# File 'lib/neography/connection.rb', line 8

def gremlin_path
  @gremlin_path
end

#log_enabledObject

Returns the value of attribute log_enabled.



8
9
10
# File 'lib/neography/connection.rb', line 8

def log_enabled
  @log_enabled
end

#log_fileObject

Returns the value of attribute log_file.



8
9
10
# File 'lib/neography/connection.rb', line 8

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/neography/connection.rb', line 8

def logger
  @logger
end

#max_threadsObject

Returns the value of attribute max_threads.



8
9
10
# File 'lib/neography/connection.rb', line 8

def max_threads
  @max_threads
end

#parserObject

Returns the value of attribute parser.



8
9
10
# File 'lib/neography/connection.rb', line 8

def parser
  @parser
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/neography/connection.rb', line 8

def password
  @password
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/neography/connection.rb', line 8

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



8
9
10
# File 'lib/neography/connection.rb', line 8

def protocol
  @protocol
end

#serverObject

Returns the value of attribute server.



8
9
10
# File 'lib/neography/connection.rb', line 8

def server
  @server
end

#usernameObject

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



48
49
50
51
52
# File 'lib/neography/connection.rb', line 48

def authenticate(path)
  @client.set_auth(path, 
                   @authentication[@authentication.keys.first][:username], 
                   @authentication[@authentication.keys.first][:password]) unless @authentication.empty?
end

#configurationObject



30
31
32
# File 'lib/neography/connection.rb', line 30

def configuration
  @configuration ||= "#{@protocol}#{@server}:#{@port}#{@directory}/db/data"
end

#configure(protocol, server, port, directory) ⇒ Object



23
24
25
26
27
28
# File 'lib/neography/connection.rb', line 23

def configure(protocol, server, port, directory)
  @protocol = protocol
  @server = server
  @port = port
  @directory = directory
end

#merge_options(options) ⇒ Object



34
35
36
37
38
39
# File 'lib/neography/connection.rb', line 34

def merge_options(options)
  merged_options = options.merge!(@authentication)
  merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
  merged_options[:headers].merge!('X-Stream' => true) if merged_options[:headers]
  merged_options
end