neography 1.3.14 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/neography/rest.rb +29 -472
- data/lib/neography/rest/batch.rb +80 -87
- data/lib/neography/rest/clean.rb +8 -10
- data/lib/neography/rest/constraints.rb +15 -25
- data/lib/neography/rest/cypher.rb +2 -6
- data/lib/neography/rest/extensions.rb +4 -8
- data/lib/neography/rest/gremlin.rb +2 -6
- data/lib/neography/rest/helpers.rb +58 -0
- data/lib/neography/rest/node_auto_indexes.rb +54 -8
- data/lib/neography/rest/node_indexes.rb +92 -17
- data/lib/neography/rest/node_labels.rb +15 -26
- data/lib/neography/rest/node_paths.rb +8 -16
- data/lib/neography/rest/node_properties.rb +45 -4
- data/lib/neography/rest/node_relationships.rb +8 -17
- data/lib/neography/rest/node_traversal.rb +7 -63
- data/lib/neography/rest/nodes.rb +21 -29
- data/lib/neography/rest/other_node_relationships.rb +6 -13
- data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
- data/lib/neography/rest/relationship_indexes.rb +104 -14
- data/lib/neography/rest/relationship_properties.rb +45 -4
- data/lib/neography/rest/relationship_types.rb +4 -11
- data/lib/neography/rest/relationships.rb +6 -13
- data/lib/neography/rest/schema_indexes.rb +8 -16
- data/lib/neography/rest/spatial.rb +16 -33
- data/lib/neography/rest/transactions.rb +25 -26
- data/lib/neography/tasks.rb +2 -2
- data/lib/neography/version.rb +1 -1
- data/spec/unit/rest/batch_spec.rb +49 -50
- data/spec/unit/rest/clean_spec.rb +3 -4
- data/spec/unit/rest/constraints_spec.rb +12 -13
- data/spec/unit/rest/cypher_spec.rb +3 -4
- data/spec/unit/rest/extensions_spec.rb +5 -6
- data/spec/unit/rest/gremlin_spec.rb +5 -6
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +21 -22
- data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/node_indexes_spec.rb +42 -43
- data/spec/unit/rest/node_paths_spec.rb +10 -13
- data/spec/unit/rest/node_properties_spec.rb +22 -23
- data/spec/unit/rest/node_relationships_spec.rb +18 -39
- data/spec/unit/rest/node_traversal_spec.rb +4 -97
- data/spec/unit/rest/nodes_spec.rb +47 -48
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
- data/spec/unit/rest/relationship_properties_spec.rb +22 -23
- data/spec/unit/rest/relationship_types_spec.rb +3 -4
- data/spec/unit/rest/relationships_spec.rb +5 -6
- data/spec/unit/rest/schema_index_spec.rb +7 -8
- data/spec/unit/rest/transactions_spec.rb +10 -11
- metadata +27 -31
- data/lib/neography/rest/auto_indexes.rb +0 -64
- data/lib/neography/rest/indexes.rb +0 -102
- data/lib/neography/rest/paths.rb +0 -46
- data/lib/neography/rest/properties.rb +0 -56
- data/spec/unit/rest/paths_spec.rb +0 -69
@@ -1,13 +1,9 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
3
|
+
module Cypher
|
4
4
|
include Neography::Rest::Helpers
|
5
5
|
|
6
|
-
def
|
7
|
-
@connection ||= connection
|
8
|
-
end
|
9
|
-
|
10
|
-
def query(query, parameters = {}, cypher_options = nil)
|
6
|
+
def execute_query(query, parameters = {}, cypher_options = nil)
|
11
7
|
options = {
|
12
8
|
:body => {
|
13
9
|
:query => query,
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
3
|
+
module Extensions
|
4
4
|
include Neography::Rest::Helpers
|
5
|
-
|
6
|
-
def
|
7
|
-
@connection ||= connection
|
8
|
-
end
|
9
|
-
|
10
|
-
def get(path)
|
5
|
+
|
6
|
+
def get_extension(path)
|
11
7
|
@connection.get(path)
|
12
8
|
end
|
13
9
|
|
14
|
-
def
|
10
|
+
def post_extension(path, body = {}, headers = nil)
|
15
11
|
options = {
|
16
12
|
:body => headers.nil? ? body.to_json : body,
|
17
13
|
:headers => headers || json_content_type.merge({'Accept' => 'application/json;stream=true'})
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
3
|
+
module Gremlin
|
4
4
|
include Neography::Rest::Helpers
|
5
5
|
|
6
|
-
def
|
7
|
-
@connection ||= connection
|
8
|
-
end
|
9
|
-
|
10
|
-
def execute(script, parameters = {})
|
6
|
+
def execute_script(script, parameters = {})
|
11
7
|
options = {
|
12
8
|
:body => {
|
13
9
|
:script => script,
|
@@ -32,6 +32,64 @@ module Neography
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def encode(value)
|
36
|
+
CGI.escape(value.to_s).gsub("+", "%20")
|
37
|
+
end
|
38
|
+
|
39
|
+
def escape(value)
|
40
|
+
if value.class == String
|
41
|
+
"%22"+encode(value.to_s)+"%22";
|
42
|
+
else
|
43
|
+
encode(value.to_s)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_order(order)
|
48
|
+
case order
|
49
|
+
when :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide"
|
50
|
+
"breadth first"
|
51
|
+
else
|
52
|
+
"depth first"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_uniqueness(uniqueness)
|
57
|
+
case uniqueness
|
58
|
+
when :nodeglobal, "node global", "nodeglobal", "node_global"
|
59
|
+
"node global"
|
60
|
+
when :nodepath, "node path", "nodepath", "node_path"
|
61
|
+
"node path"
|
62
|
+
when :noderecent, "node recent", "noderecent", "node_recent"
|
63
|
+
"node recent"
|
64
|
+
when :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global"
|
65
|
+
"relationship global"
|
66
|
+
when :relationshippath, "relationship path", "relationshippath", "relationship_path"
|
67
|
+
"relationship path"
|
68
|
+
when :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent"
|
69
|
+
"relationship recent"
|
70
|
+
else
|
71
|
+
"none"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def parse_depth(depth)
|
76
|
+
return nil if depth.nil?
|
77
|
+
return 1 if depth.to_i == 0
|
78
|
+
depth.to_i
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse_type(type)
|
82
|
+
case type
|
83
|
+
when :relationship, "relationship", :relationships, "relationships"
|
84
|
+
"relationship"
|
85
|
+
when :path, "path", :paths, "paths"
|
86
|
+
"path"
|
87
|
+
when :fullpath, "fullpath", :fullpaths, "fullpaths"
|
88
|
+
"fullpath"
|
89
|
+
else
|
90
|
+
"node"
|
91
|
+
end
|
92
|
+
end
|
35
93
|
|
36
94
|
end
|
37
95
|
end
|
@@ -1,13 +1,59 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module NodeAutoIndexes
|
4
|
+
|
5
|
+
def get_node_auto_index(key, value)
|
6
|
+
index = @connection.get("/index/auto/node/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
7
|
+
return nil if index.empty?
|
8
|
+
index
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_node_auto_index(key_or_query, value = nil)
|
12
|
+
if value
|
13
|
+
index = find_node_auto_index_by_value(key_or_query, value)
|
14
|
+
else
|
15
|
+
index = query_node_auto_index(key_or_query)
|
16
|
+
end
|
17
|
+
return nil if index.empty?
|
18
|
+
index
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_node_auto_index_by_value(key, value)
|
22
|
+
@connection.get("/index/auto/node/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_node_auto_index(query_expression)
|
26
|
+
@connection.get("/index/auto/node/?query=%{query}" % {:query => query_expression}) || []
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_node_auto_index_status
|
30
|
+
@connection.get("/index/auto/node/status")
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_node_auto_index_status(value = true)
|
34
|
+
options = {
|
35
|
+
:body => value.to_json,
|
36
|
+
:headers => json_content_type
|
37
|
+
}
|
38
|
+
@connection.put("/index/auto/node/status", options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_node_auto_index_properties
|
42
|
+
@connection.get("/index/auto/node/properties")
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_node_auto_index_property(property)
|
46
|
+
options = {
|
47
|
+
:body => property,
|
48
|
+
:headers => json_content_type
|
49
|
+
}
|
50
|
+
@connection.post("/index/auto/node/properties", options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_node_auto_index_property(property)
|
54
|
+
@connection.delete("/index/auto/node/properties/%{property}" % {:property => property})
|
55
|
+
end
|
56
|
+
|
11
57
|
|
12
58
|
end
|
13
59
|
end
|
@@ -1,24 +1,99 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module NodeIndexes
|
5
4
|
include Neography::Rest::Helpers
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
def list_node_indexes
|
7
|
+
@connection.get("/index/node")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_node_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/node", options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_node_auto_index(type = "exact", provider = "lucene")
|
28
|
+
create_node_index("node_auto_index", type, provider)
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_node_to_index(index, key, value, id, unique = false)
|
32
|
+
options = {
|
33
|
+
:body => (
|
34
|
+
{ :uri => @connection.configuration + "/node/#{get_id(id)}",
|
35
|
+
:key => key,
|
36
|
+
:value => value
|
37
|
+
}
|
38
|
+
).to_json,
|
39
|
+
:headers => json_content_type
|
40
|
+
}
|
41
|
+
path = unique ? "/index/node/%{index}?unique" % {:index => index} : "/index/node/%{index}" % {:index => index}
|
42
|
+
@connection.post(path, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_node_index(index, key, value)
|
46
|
+
index = @connection.get("/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
47
|
+
return nil if index.empty?
|
48
|
+
index
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_node_index(index, key_or_query, value = nil)
|
52
|
+
if value
|
53
|
+
index = find_node_index_by_key_value(index, key_or_query, value)
|
54
|
+
else
|
55
|
+
index = find_node_index_by_query(index, key_or_query)
|
56
|
+
end
|
57
|
+
return nil if index.empty?
|
58
|
+
index
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_node_index_by_key_value(index, key, value)
|
62
|
+
@connection.get("/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_node_index_by_query(index, query)
|
66
|
+
@connection.get("/index/node/%{index}?query=%{query}" % {:index => index, :query => encode(query)}) || []
|
67
|
+
end
|
68
|
+
|
69
|
+
# Mimick original neography API in Rest class.
|
70
|
+
def remove_node_from_index(index, id_or_key, id_or_value = nil, id = nil)
|
71
|
+
if id
|
72
|
+
remove_node_index_by_value(index, id, id_or_key, id_or_value)
|
73
|
+
elsif id_or_value
|
74
|
+
remove_node_index_by_key(index, id_or_value, id_or_key)
|
75
|
+
else
|
76
|
+
remove_node_index_by_id(index, id_or_key)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_node_index_by_id(index, id)
|
81
|
+
@connection.delete("/index/node/%{index}/%{id}" % {:index => index, :id => get_id(id)})
|
82
|
+
end
|
83
|
+
|
84
|
+
def remove_node_index_by_key(index, id, key)
|
85
|
+
@connection.delete("/index/node/%{index}/%{key}/%{id}" % {:index => index, :id => get_id(id), :key => key})
|
86
|
+
end
|
87
|
+
|
88
|
+
def remove_node_index_by_value(index, id, key, value)
|
89
|
+
@connection.delete("/index/node/%{index}/%{key}/%{value}/%{id}" % {:index => index, :id => get_id(id), :key => key, :value => encode(value)})
|
90
|
+
end
|
16
91
|
|
17
|
-
def
|
18
|
-
|
92
|
+
def drop_node_index(index)
|
93
|
+
@connection.delete("/index/node/%{index}" % {:index => index})
|
19
94
|
end
|
20
95
|
|
21
|
-
def
|
96
|
+
def create_unique_node(index, key, value, properties = {})
|
22
97
|
options = {
|
23
98
|
:body => (
|
24
99
|
{ :properties => properties,
|
@@ -28,10 +103,10 @@ module Neography
|
|
28
103
|
).to_json,
|
29
104
|
:headers => json_content_type
|
30
105
|
}
|
31
|
-
@connection.post(
|
106
|
+
@connection.post("/index/node/%{index}?unique" % {:index => index}, options)
|
32
107
|
end
|
33
108
|
|
34
|
-
def
|
109
|
+
def get_or_create_unique_node(index, key, value, properties = {})
|
35
110
|
options = {
|
36
111
|
:body => (
|
37
112
|
{ :properties => properties,
|
@@ -41,7 +116,7 @@ module Neography
|
|
41
116
|
).to_json,
|
42
117
|
:headers => json_content_type
|
43
118
|
}
|
44
|
-
@connection.post(
|
119
|
+
@connection.post("/index/node/%{index}?uniqueness=%{function}" % {:index => index, :function => 'get_or_create'}, options)
|
45
120
|
|
46
121
|
end
|
47
122
|
|
@@ -1,57 +1,46 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module NodeLabels
|
5
4
|
include Neography::Rest::Helpers
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
add_path :nodes, "/label/:label/nodes"
|
10
|
-
add_path :find, "/label/:label/nodes?:property=:value"
|
11
|
-
add_path :delete, "/node/:id/labels/:label"
|
12
|
-
|
13
|
-
def initialize(connection)
|
14
|
-
@connection ||= connection
|
15
|
-
end
|
16
|
-
|
17
|
-
def list
|
18
|
-
@connection.get(base_path)
|
6
|
+
def list_labels
|
7
|
+
@connection.get("/labels")
|
19
8
|
end
|
20
9
|
|
21
|
-
def
|
22
|
-
@connection.get(
|
10
|
+
def get_node_labels(id)
|
11
|
+
@connection.get("/node/%{id}/labels" % {:id => get_id(id)})
|
23
12
|
end
|
24
13
|
|
25
|
-
def
|
26
|
-
@connection.get(
|
14
|
+
def get_nodes_labeled(label)
|
15
|
+
@connection.get("/label/%{label}/nodes" % {:label => label})
|
27
16
|
end
|
28
17
|
|
29
|
-
def
|
30
|
-
@connection.get(
|
18
|
+
def find_nodes_labeled(label, hash)
|
19
|
+
@connection.get("/label/%{label}/nodes?%{property}=%{value}" % {:label => label, :property => hash.keys.first, :value => escape(hash.values.first)})
|
31
20
|
end
|
32
21
|
|
33
|
-
def
|
22
|
+
def add_label(id, label)
|
34
23
|
options = {
|
35
24
|
:body => (
|
36
25
|
label
|
37
26
|
).to_json,
|
38
27
|
:headers => json_content_type
|
39
28
|
}
|
40
|
-
@connection.post(
|
29
|
+
@connection.post("/node/%{id}/labels" % {:id => get_id(id)}, options)
|
41
30
|
end
|
42
31
|
|
43
|
-
def
|
32
|
+
def set_label(id, label)
|
44
33
|
options = {
|
45
34
|
:body => (
|
46
35
|
Array(label)
|
47
36
|
).to_json,
|
48
37
|
:headers => json_content_type
|
49
38
|
}
|
50
|
-
@connection.put(
|
39
|
+
@connection.put("/node/%{id}/labels" % {:id => get_id(id)}, options)
|
51
40
|
end
|
52
41
|
|
53
|
-
def
|
54
|
-
@connection.delete(
|
42
|
+
def delete_label(id, label)
|
43
|
+
@connection.delete("/node/%{id}/labels/%{label}" % {:id => get_id(id), :label => label})
|
55
44
|
end
|
56
45
|
|
57
46
|
|
@@ -1,29 +1,21 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module NodePaths
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
add_path :all, "/node/:id/paths"
|
9
|
-
|
10
|
-
def initialize(connection)
|
11
|
-
@connection ||= connection
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(from, to, relationships, depth = 1, algorithm = "shortestPath")
|
5
|
+
|
6
|
+
def get_path(from, to, relationships, depth = 1, algorithm = "shortestPath")
|
15
7
|
options = path_options(to, relationships, depth, algorithm)
|
16
|
-
@connection.post(
|
8
|
+
@connection.post("/node/%{id}/path" % {:id => get_id(from)}, options) || {}
|
17
9
|
end
|
18
10
|
|
19
|
-
def
|
11
|
+
def get_paths(from, to, relationships, depth = 1, algorithm = "allPaths")
|
20
12
|
options = path_options(to, relationships, depth, algorithm)
|
21
|
-
@connection.post(
|
13
|
+
@connection.post("/node/%{id}/paths" % {:id => get_id(from)}, options) || []
|
22
14
|
end
|
23
15
|
|
24
|
-
def
|
16
|
+
def get_shortest_weighted_path(from, to, relationships, weight_attribute = "weight", depth = 1, algorithm = "dijkstra")
|
25
17
|
options = path_options(to, relationships, depth, algorithm, { :cost_property => weight_attribute })
|
26
|
-
@connection.post(
|
18
|
+
@connection.post("/node/%{id}/paths" % {:id => get_id(from)}, options) || {}
|
27
19
|
end
|
28
20
|
|
29
21
|
private
|
@@ -1,10 +1,51 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
|
3
|
+
module NodeProperties
|
4
|
+
|
5
|
+
def set_node_properties(id, properties)
|
6
|
+
properties.each do |property, value|
|
7
|
+
options = { :body => value.to_json, :headers => json_content_type }
|
8
|
+
@connection.put("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset_node_properties(id, properties)
|
13
|
+
options = { :body => properties.to_json, :headers => json_content_type }
|
14
|
+
@connection.put("/node/%{id}/properties" % {:id => get_id(id)}, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_node_properties(id, *properties)
|
18
|
+
if properties.none?
|
19
|
+
@connection.get("/node/%{id}/properties" % {:id => get_id(id)})
|
20
|
+
else
|
21
|
+
get_each_node_properties(id, *properties)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_each_node_properties(id, *properties)
|
26
|
+
retrieved_properties = properties.flatten.inject({}) do |memo, property|
|
27
|
+
value = @connection.get("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property})
|
28
|
+
memo[property] = value unless value.nil?
|
29
|
+
memo
|
30
|
+
end
|
31
|
+
return nil if retrieved_properties.empty?
|
32
|
+
retrieved_properties
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_node_properties(id, *properties)
|
36
|
+
if properties.none?
|
37
|
+
@connection.delete("/node/%{id}/properties" % {:id => get_id(id)})
|
38
|
+
else
|
39
|
+
remove_each_node_properties(id, *properties)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_each_node_properties(id, *properties)
|
44
|
+
properties.flatten.each do |property|
|
45
|
+
@connection.delete("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property})
|
46
|
+
end
|
47
|
+
end
|
5
48
|
|
6
|
-
add_path :all, "/node/:id/properties"
|
7
|
-
add_path :single, "/node/:id/properties/:property"
|
8
49
|
|
9
50
|
end
|
10
51
|
end
|