Class: Neography::Connection

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

Constant Summary collapse

USER_AGENT =
"Neography/#{Neography::VERSION}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Connection.



12
13
14
15
16
# File 'lib/neography/connection.rb', line 12

def initialize(options = ENV['NEO4J_URL'] || {})
  config = merge_configuration(options)
  save_local_configuration(config)
  @client = HTTPClient.new
end

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



5
6
7
# File 'lib/neography/connection.rb', line 5

def authentication
  @authentication
end

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/neography/connection.rb', line 5

def client
  @client
end

#cypher_pathObject

Returns the value of attribute cypher_path.



5
6
7
# File 'lib/neography/connection.rb', line 5

def cypher_path
  @cypher_path
end

#directoryObject

Returns the value of attribute directory.



5
6
7
# File 'lib/neography/connection.rb', line 5

def directory
  @directory
end

#gremlin_pathObject

Returns the value of attribute gremlin_path.



5
6
7
# File 'lib/neography/connection.rb', line 5

def gremlin_path
  @gremlin_path
end

#log_enabledObject

Returns the value of attribute log_enabled.



5
6
7
# File 'lib/neography/connection.rb', line 5

def log_enabled
  @log_enabled
end

#log_fileObject

Returns the value of attribute log_file.



5
6
7
# File 'lib/neography/connection.rb', line 5

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/neography/connection.rb', line 5

def logger
  @logger
end

#max_threadsObject

Returns the value of attribute max_threads.



5
6
7
# File 'lib/neography/connection.rb', line 5

def max_threads
  @max_threads
end

#parserObject

Returns the value of attribute parser.



5
6
7
# File 'lib/neography/connection.rb', line 5

def parser
  @parser
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/neography/connection.rb', line 5

def password
  @password
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/neography/connection.rb', line 5

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



5
6
7
# File 'lib/neography/connection.rb', line 5

def protocol
  @protocol
end

#serverObject

Returns the value of attribute server.



5
6
7
# File 'lib/neography/connection.rb', line 5

def server
  @server
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/neography/connection.rb', line 5

def username
  @username
end

Instance Method Details

#authenticate(path) ⇒ Object



55
56
57
58
59
# File 'lib/neography/connection.rb', line 55

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

#configurationObject



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

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

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



18
19
20
21
22
23
# File 'lib/neography/connection.rb', line 18

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

#delete(path, options = {}) ⇒ Object



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

def delete(path, options={})
  authenticate(configuration + path)
  evaluate_response(@client.delete(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

#get(path, options = {}) ⇒ Object



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

def get(path, options={})
  authenticate(configuration + path)
  evaluate_response(@client.get(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

#merge_options(options) ⇒ Object



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

def merge_options(options)
  merged_options = options.merge!(@authentication)#.merge!(@parser)
  merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
  merged_options
end

#post(path, options = {}) ⇒ Object



40
41
42
43
# File 'lib/neography/connection.rb', line 40

def post(path, options={})
  authenticate(configuration + path)
  evaluate_response(@client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

#put(path, options = {}) ⇒ Object



45
46
47
48
# File 'lib/neography/connection.rb', line 45

def put(path, options={})
  authenticate(configuration + path)
  evaluate_response(@client.put(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end