neography 1.3.14 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neography/rest.rb +29 -472
  3. data/lib/neography/rest/batch.rb +80 -87
  4. data/lib/neography/rest/clean.rb +8 -10
  5. data/lib/neography/rest/constraints.rb +15 -25
  6. data/lib/neography/rest/cypher.rb +2 -6
  7. data/lib/neography/rest/extensions.rb +4 -8
  8. data/lib/neography/rest/gremlin.rb +2 -6
  9. data/lib/neography/rest/helpers.rb +58 -0
  10. data/lib/neography/rest/node_auto_indexes.rb +54 -8
  11. data/lib/neography/rest/node_indexes.rb +92 -17
  12. data/lib/neography/rest/node_labels.rb +15 -26
  13. data/lib/neography/rest/node_paths.rb +8 -16
  14. data/lib/neography/rest/node_properties.rb +45 -4
  15. data/lib/neography/rest/node_relationships.rb +8 -17
  16. data/lib/neography/rest/node_traversal.rb +7 -63
  17. data/lib/neography/rest/nodes.rb +21 -29
  18. data/lib/neography/rest/other_node_relationships.rb +6 -13
  19. data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
  20. data/lib/neography/rest/relationship_indexes.rb +104 -14
  21. data/lib/neography/rest/relationship_properties.rb +45 -4
  22. data/lib/neography/rest/relationship_types.rb +4 -11
  23. data/lib/neography/rest/relationships.rb +6 -13
  24. data/lib/neography/rest/schema_indexes.rb +8 -16
  25. data/lib/neography/rest/spatial.rb +16 -33
  26. data/lib/neography/rest/transactions.rb +25 -26
  27. data/lib/neography/tasks.rb +2 -2
  28. data/lib/neography/version.rb +1 -1
  29. data/spec/unit/rest/batch_spec.rb +49 -50
  30. data/spec/unit/rest/clean_spec.rb +3 -4
  31. data/spec/unit/rest/constraints_spec.rb +12 -13
  32. data/spec/unit/rest/cypher_spec.rb +3 -4
  33. data/spec/unit/rest/extensions_spec.rb +5 -6
  34. data/spec/unit/rest/gremlin_spec.rb +5 -6
  35. data/spec/unit/rest/helpers_spec.rb +124 -0
  36. data/spec/unit/rest/labels_spec.rb +21 -22
  37. data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
  38. data/spec/unit/rest/node_indexes_spec.rb +42 -43
  39. data/spec/unit/rest/node_paths_spec.rb +10 -13
  40. data/spec/unit/rest/node_properties_spec.rb +22 -23
  41. data/spec/unit/rest/node_relationships_spec.rb +18 -39
  42. data/spec/unit/rest/node_traversal_spec.rb +4 -97
  43. data/spec/unit/rest/nodes_spec.rb +47 -48
  44. data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
  45. data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
  46. data/spec/unit/rest/relationship_properties_spec.rb +22 -23
  47. data/spec/unit/rest/relationship_types_spec.rb +3 -4
  48. data/spec/unit/rest/relationships_spec.rb +5 -6
  49. data/spec/unit/rest/schema_index_spec.rb +7 -8
  50. data/spec/unit/rest/transactions_spec.rb +10 -11
  51. metadata +27 -31
  52. data/lib/neography/rest/auto_indexes.rb +0 -64
  53. data/lib/neography/rest/indexes.rb +0 -102
  54. data/lib/neography/rest/paths.rb +0 -46
  55. data/lib/neography/rest/properties.rb +0 -56
  56. data/spec/unit/rest/paths_spec.rb +0 -69
@@ -1,18 +1,9 @@
1
1
  module Neography
2
2
  class Rest
3
- class NodeRelationships
4
- extend Neography::Rest::Paths
3
+ module NodeRelationships
5
4
  include Neography::Rest::Helpers
6
-
7
- add_path :base, "/node/:id/relationships"
8
- add_path :direction, "/node/:id/relationships/:direction"
9
- add_path :type, "/node/:id/relationships/:direction/:types"
10
-
11
- def initialize(connection)
12
- @connection ||= connection
13
- end
14
-
15
- def create(type, from, to, properties = nil)
5
+
6
+ def create_relationship(type, from, to, properties = nil)
16
7
  options = {
17
8
  :body => {
18
9
  :to => @connection.configuration + "/node/#{get_id(to)}",
@@ -21,16 +12,16 @@ module Neography
21
12
  }.to_json,
22
13
  :headers => json_content_type }
23
14
 
24
- @connection.post(base_path(:id => get_id(from)), options)
15
+ @connection.post("/node/%{id}/relationships" % {:id => get_id(from)}, options)
25
16
  end
26
-
27
- def get(id, direction = nil, types = nil)
17
+
18
+ def get_node_relationships(id, direction = nil, types = nil)
28
19
  direction = parse_direction(direction)
29
20
 
30
21
  if types.nil?
31
- node_relationships = @connection.get(direction_path(:id => get_id(id), :direction => direction)) || []
22
+ node_relationships = @connection.get("/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction}) || []
32
23
  else
33
- node_relationships = @connection.get(type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || []
24
+ node_relationships = @connection.get("/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => encode(Array(types).join('&'))}) || []
34
25
  end
35
26
 
36
27
  return [] if node_relationships.empty?
@@ -1,79 +1,23 @@
1
1
  module Neography
2
2
  class Rest
3
- class NodeTraversal
4
- extend Neography::Rest::Paths
3
+ module NodeTraversal
5
4
  include Neography::Rest::Helpers
6
-
7
- add_path :traversal, "/node/:id/traverse/:type"
8
-
9
- def initialize(connection)
10
- @connection ||= connection
11
- end
12
-
5
+
13
6
  def traverse(id, return_type, description)
14
7
  options = { :body => {
15
- "order" => get_order(description["order"]),
16
- "uniqueness" => get_uniqueness(description["uniqueness"]),
8
+ "order" => parse_order(description["order"]),
9
+ "uniqueness" => parse_uniqueness(description["uniqueness"]),
17
10
  "relationships" => description["relationships"],
18
11
  "prune_evaluator" => description["prune evaluator"],
19
12
  "return_filter" => description["return filter"],
20
- "max_depth" => get_depth(description["depth"])
13
+ "max_depth" => parse_depth(description["depth"])
21
14
  }.to_json,
22
15
  :headers => json_content_type
23
16
  }
24
17
 
25
- type = get_type(return_type)
26
-
27
- @connection.post(traversal_path(:id => get_id(id), :type => type), options) || []
28
- end
29
-
30
- private
31
-
32
- def get_order(order)
33
- case order
34
- when :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide"
35
- "breadth first"
36
- else
37
- "depth first"
38
- end
39
- end
40
-
41
- def get_uniqueness(uniqueness)
42
- case uniqueness
43
- when :nodeglobal, "node global", "nodeglobal", "node_global"
44
- "node global"
45
- when :nodepath, "node path", "nodepath", "node_path"
46
- "node path"
47
- when :noderecent, "node recent", "noderecent", "node_recent"
48
- "node recent"
49
- when :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global"
50
- "relationship global"
51
- when :relationshippath, "relationship path", "relationshippath", "relationship_path"
52
- "relationship path"
53
- when :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent"
54
- "relationship recent"
55
- else
56
- "none"
57
- end
58
- end
59
-
60
- def get_depth(depth)
61
- return nil if depth.nil?
62
- return 1 if depth.to_i == 0
63
- depth.to_i
64
- end
18
+ type = parse_type(return_type)
65
19
 
66
- def get_type(type)
67
- case type
68
- when :relationship, "relationship", :relationships, "relationships"
69
- "relationship"
70
- when :path, "path", :paths, "paths"
71
- "path"
72
- when :fullpath, "fullpath", :fullpaths, "fullpaths"
73
- "fullpath"
74
- else
75
- "node"
76
- end
20
+ @connection.post("/node/%{id}/traverse/%{type}" % {:id => get_id(id), :type => type}, options) || []
77
21
  end
78
22
 
79
23
  end
@@ -1,67 +1,59 @@
1
1
  module Neography
2
2
  class Rest
3
- class Nodes
4
- extend Neography::Rest::Paths
3
+ module Nodes
5
4
  include Neography::Rest::Helpers
6
5
 
7
- add_path :index, "/node"
8
- add_path :base, "/node/:id"
9
-
10
- def initialize(connection)
11
- @connection ||= connection
12
- end
13
-
14
- def get(id)
15
- @connection.get(base_path(:id => get_id(id)))
6
+ def get_node(id)
7
+ @connection.get("/node/%{id}" % {:id => get_id(id)})
16
8
  end
17
9
 
18
- def get_each(*nodes)
10
+ def get_nodes(*nodes)
19
11
  gotten_nodes = []
20
12
  Array(nodes).flatten.each do |node|
21
- gotten_nodes << get(node)
13
+ gotten_nodes << get_node(node)
22
14
  end
23
15
  gotten_nodes
24
16
  end
25
17
 
26
- def root
18
+ def get_root
27
19
  root_node = @connection.get('/')["reference_node"]
28
- @connection.get(base_path(:id => get_id(root_node)))
20
+ @connection.get("/node/%{id}" % {:id => get_id(root_node)})
29
21
  end
30
22
 
31
- def create(*args)
23
+ def create_node(*args)
32
24
  if args[0].respond_to?(:each_pair) && args[0]
33
- create_with_attributes(args[0])
25
+ create_node_with_attributes(args[0])
34
26
  else
35
- create_empty
27
+ create_empty_node
36
28
  end
37
29
  end
38
30
 
39
- def create_with_attributes(attributes)
31
+ def create_node_with_attributes(attributes)
40
32
  options = {
41
33
  :body => attributes.delete_if { |k, v| v.nil? }.to_json,
42
34
  :headers => json_content_type
43
35
  }
44
- @connection.post(index_path, options)
36
+ @connection.post("/node", options)
45
37
  end
46
38
 
47
- def create_empty
48
- @connection.post(index_path)
39
+ def create_empty_node
40
+ @connection.post("/node")
49
41
  end
50
42
 
51
- def delete(id)
52
- @connection.delete(base_path(:id => get_id(id)))
43
+ def delete_node(id)
44
+ @connection.delete("/node/%{id}" % {:id => get_id(id)})
53
45
  end
54
46
 
55
- def create_multiple(nodes)
47
+ def create_nodes(nodes)
56
48
  nodes = Array.new(nodes) if nodes.kind_of? Fixnum
57
49
  created_nodes = []
58
50
  nodes.each do |node|
59
- created_nodes << create(node)
51
+ created_nodes << create_node(node)
60
52
  end
61
53
  created_nodes
62
54
  end
63
55
 
64
- def create_multiple_threaded(nodes)
56
+ def create_nodes_threaded(nodes)
65
57
  nodes = Array.new(nodes) if nodes.kind_of? Fixnum
66
58
 
67
59
  node_queue = Queue.new
@@ -77,12 +69,12 @@ module Neography
77
69
  until node_queue.empty? do
78
70
  node = node_queue.pop
79
71
  if node.respond_to?(:each_pair)
80
- responses.push( @connection.post(index_path, {
72
+ responses.push( @connection.post("/node", {
81
73
  :body => node.to_json,
82
74
  :headers => json_content_type
83
75
  } ) )
84
76
  else
85
- responses.push( @connection.post(index_path) )
77
+ responses.push( @connection.post("/node") )
86
78
  end
87
79
  end
88
80
  self.join
@@ -1,16 +1,9 @@
1
1
  module Neography
2
2
  class Rest
3
- class OtherNodeRelationships
4
- extend Neography::Rest::Paths
3
+ module OtherNodeRelationships
5
4
  include Neography::Rest::Helpers
6
-
7
- add_path :base, "/node/:id/traverse/relationship"
8
-
9
- def initialize(connection)
10
- @connection ||= connection
11
- end
12
-
13
- def get(id, other_id, direction = "all", types = [nil])
5
+
6
+ def get_node_relationships_to(id, other_id, direction = "all", types = [nil] )
14
7
 
15
8
  body = case parse_direction(direction)
16
9
  when "all"
@@ -21,9 +14,9 @@ module Neography
21
14
  "position.length() > 0 && position.lastRelationship().getEndNode().getId() == " + get_id(other_id)
22
15
  end
23
16
 
24
- relationships = {:relationships => types.map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }
17
+ relationships = {:relationships => Array(types).map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }
25
18
 
26
- if types.first.nil?
19
+ if Array(types).first.nil?
27
20
  relationships = {}
28
21
  end
29
22
 
@@ -37,7 +30,7 @@ module Neography
37
30
  :headers => json_content_type
38
31
  }
39
32
 
40
- @connection.post(base_path(:id => get_id(id)), options) || []
33
+ @connection.post("/node/%{id}/traverse/relationship" % {:id => get_id(id)}, options) || []
41
34
  end
42
35
 
43
36
  end
@@ -1,13 +1,59 @@
1
1
  module Neography
2
2
  class Rest
3
- class RelationshipAutoIndexes < AutoIndexes
4
- extend Neography::Rest::Paths
5
-
6
- add_path :key_value, "/index/auto/relationship/:key/:value"
7
- add_path :query_index, "/index/auto/relationship/?query=:query"
8
- add_path :index_status, "/index/auto/relationship/status"
9
- add_path :index_properties, "/index/auto/relationship/properties"
10
- add_path :index_property, "/index/auto/relationship/properties/:property"
3
+ module RelationshipAutoIndexes
4
+
5
+ def get_relationship_auto_index(key, value)
6
+ index = @connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
7
+ return nil if index.empty?
8
+ index
9
+ end
10
+
11
+ def find_relationship_auto_index(key_or_query, value = nil)
12
+ if value
13
+ index = find_relationship_auto_index_by_value(key_or_query, value)
14
+ else
15
+ index = query_relationship_auto_index(key_or_query)
16
+ end
17
+ return nil if index.empty?
18
+ index
19
+ end
20
+
21
+ def find_relationship_auto_index_by_value(key, value)
22
+ @connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
23
+ end
24
+
25
+ def query_relationship_auto_index(query_expression)
26
+ @connection.get("/index/auto/relationship/?query=%{query}" % {:query => query_expression}) || []
27
+ end
28
+
29
+ def get_relationship_auto_index_status
30
+ @connection.get("/index/auto/relationship/status")
31
+ end
32
+
33
+ def set_relationship_auto_index_status(value = true)
34
+ options = {
35
+ :body => value.to_json,
36
+ :headers => json_content_type
37
+ }
38
+ @connection.put("/index/auto/relationship/status", options)
39
+ end
40
+
41
+ def get_relationship_auto_index_properties
42
+ @connection.get("/index/auto/relationship/properties")
43
+ end
44
+
45
+ def add_relationship_auto_index_property(property)
46
+ options = {
47
+ :body => property,
48
+ :headers => json_content_type
49
+ }
50
+ @connection.post("/index/auto/relationship/properties", options)
51
+ end
52
+
53
+ def remove_relationship_auto_index_property(property)
54
+ @connection.delete("/index/auto/relationship/properties/%{property}" % {:property => property})
55
+ end
56
+
11
57
 
12
58
  end
13
59
  end
@@ -1,23 +1,99 @@
1
1
  module Neography
2
2
  class Rest
3
- class RelationshipIndexes < Indexes
4
- extend Neography::Rest::Paths
3
+ module RelationshipIndexes
5
4
  include Neography::Rest::Helpers
6
5
 
7
- add_path :all, "/index/relationship"
8
- add_path :base, "/index/relationship/:index"
9
- add_path :unique, "/index/relationship/:index?unique"
10
- add_path :id, "/index/relationship/:index/:id"
11
- add_path :key, "/index/relationship/:index/:key/:id"
12
- add_path :value, "/index/relationship/:index/:key/:value/:id"
13
- add_path :key_value, "/index/relationship/:index/:key/:value"
14
- add_path :query, "/index/relationship/:index?query=:query"
6
+ def list_relationship_indexes
7
+ @connection.get("/index/relationship")
8
+ end
9
+
10
+ def create_relationship_index(name, type = "exact", provider = "lucene", extra_config = nil)
11
+ config = {
12
+ :type => type,
13
+ :provider => provider
14
+ }
15
+ config.merge!(extra_config) unless extra_config.nil?
16
+ options = {
17
+ :body => (
18
+ { :name => name,
19
+ :config => config
20
+ }
21
+ ).to_json,
22
+ :headers => json_content_type
23
+ }
24
+ @connection.post("/index/relationship", options)
25
+ end
26
+
27
+ def create_relationship_auto_index(type = "exact", provider = "lucene")
28
+ create_relationship_index("relationship_auto_index", type, provider)
29
+ end
15
30
 
16
- def initialize(connection)
17
- super(connection, :relationship)
31
+ def add_relationship_to_index(index, key, value, id, unique = false)
32
+ options = {
33
+ :body => (
34
+ { :uri => @connection.configuration + "/relationship/#{get_id(id)}",
35
+ :key => key,
36
+ :value => value
37
+ }
38
+ ).to_json,
39
+ :headers => json_content_type
40
+ }
41
+ path = unique ? "/index/relationship/%{index}?unique" % {:index => index} : "/index/relationship/%{index}" % {:index => index}
42
+ @connection.post(path, options)
18
43
  end
19
44
 
20
- def create_unique(index, key, value, type, from, to, props = nil)
45
+ def get_relationship_index(index, key, value)
46
+ index = @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
47
+ return nil if index.empty?
48
+ index
49
+ end
50
+
51
+ def find_relationship_index(index, key_or_query, value = nil)
52
+ if value
53
+ index = find_relationship_index_by_key_value(index, key_or_query, value)
54
+ else
55
+ index = find_relationship_index_by_query(index, key_or_query)
56
+ end
57
+ return nil if index.empty?
58
+ index
59
+ end
60
+
61
+ def find_relationship_index_by_key_value(index, key, value)
62
+ @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
63
+ end
64
+
65
+ def find_relationship_index_by_query(index, query)
66
+ @connection.get("/index/relationship/%{index}?query=%{query}" % {:index => index, :query => encode(query)}) || []
67
+ end
68
+
69
+ # Mimick original neography API in Rest class.
70
+ def remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil)
71
+ if id
72
+ remove_relationship_index_by_value(index, id, id_or_key, id_or_value)
73
+ elsif id_or_value
74
+ remove_relationship_index_by_key(index, id_or_value, id_or_key)
75
+ else
76
+ remove_relationship_index_by_id(index, id_or_key)
77
+ end
78
+ end
79
+
80
+ def remove_relationship_index_by_id(index, id)
81
+ @connection.delete("/index/relationship/%{index}/%{id}" % {:index => index, :id => get_id(id)})
82
+ end
83
+
84
+ def remove_relationship_index_by_key(index, id, key)
85
+ @connection.delete("/index/relationship/%{index}/%{key}/%{id}" % {:index => index, :id => get_id(id), :key => key})
86
+ end
87
+
88
+ def remove_relationship_index_by_value(index, id, key, value)
89
+ @connection.delete("/index/relationship/%{index}/%{key}/%{value}/%{id}" % {:index => index, :id => get_id(id), :key => key, :value => encode(value)})
90
+ end
91
+
92
+ def drop_relationship_index(index)
93
+ @connection.delete("/index/relationship/%{index}" % {:index => index})
94
+ end
95
+
96
+ def create_unique_relationship(index, key, value, type, from, to, props = nil)
21
97
  body = {
22
98
  :key => key,
23
99
  :value => value,
@@ -28,7 +104,21 @@ module Neography
28
104
  }
29
105
  options = { :body => body.to_json, :headers => json_content_type }
30
106
 
31
- @connection.post(unique_path(:index => index), options)
107
+ @connection.post("/index/relationship/%{index}?unique" % {:index => index}, options)
108
+ end
109
+
110
+ def get_or_create_unique_relationship(index, key, value, properties = {})
111
+ options = {
112
+ :body => (
113
+ { :properties => properties,
114
+ :key => key,
115
+ :value => value
116
+ }
117
+ ).to_json,
118
+ :headers => json_content_type
119
+ }
120
+ @connection.post("/index/relationship/%{index}?uniqueness=%{function}" % {:index => index, :function => 'get_or_create'}, options)
121
+
32
122
  end
33
123
 
34
124
  end