neography 0.0.31 → 1.0.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.
- data/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/CONTRIBUTORS +2 -1
- data/README.md +247 -0
- data/Rakefile +1 -2
- data/lib/neography/config.rb +48 -16
- data/lib/neography/connection.rb +151 -0
- data/lib/neography/errors.rb +42 -0
- data/lib/neography/node.rb +17 -14
- data/lib/neography/node_relationship.rb +3 -1
- data/lib/neography/node_traverser.rb +24 -20
- data/lib/neography/property.rb +31 -28
- data/lib/neography/property_container.rb +1 -1
- data/lib/neography/relationship.rb +16 -19
- data/lib/neography/rest/auto_indexes.rb +64 -0
- data/lib/neography/rest/batch.rb +262 -0
- data/lib/neography/rest/clean.rb +19 -0
- data/lib/neography/rest/cypher.rb +24 -0
- data/lib/neography/rest/gremlin.rb +24 -0
- data/lib/neography/rest/helpers.rb +26 -0
- data/lib/neography/rest/indexes.rb +97 -0
- data/lib/neography/rest/node_auto_indexes.rb +14 -0
- data/lib/neography/rest/node_indexes.rb +35 -0
- data/lib/neography/rest/node_paths.rb +57 -0
- data/lib/neography/rest/node_properties.rb +11 -0
- data/lib/neography/rest/node_relationships.rb +53 -0
- data/lib/neography/rest/node_traversal.rb +81 -0
- data/lib/neography/rest/nodes.rb +102 -0
- data/lib/neography/rest/paths.rb +36 -0
- data/lib/neography/rest/properties.rb +56 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
- data/lib/neography/rest/relationship_indexes.rb +35 -0
- data/lib/neography/rest/relationship_properties.rb +11 -0
- data/lib/neography/rest/relationships.rb +23 -0
- data/lib/neography/rest.rb +285 -615
- data/lib/neography/tasks.rb +1 -1
- data/lib/neography/version.rb +1 -1
- data/lib/neography.rb +13 -2
- data/neography.gemspec +8 -8
- data/spec/integration/authorization_spec.rb +2 -2
- data/spec/integration/index_spec.rb +4 -4
- data/spec/integration/neography_spec.rb +2 -2
- data/spec/integration/node_path_spec.rb +2 -2
- data/spec/integration/node_relationship_spec.rb +5 -3
- data/spec/integration/node_spec.rb +20 -19
- data/spec/integration/parsing_spec.rb +2 -2
- data/spec/integration/relationship_spec.rb +2 -2
- data/spec/integration/rest_batch_spec.rb +28 -28
- data/spec/integration/rest_bulk_spec.rb +2 -2
- data/spec/integration/rest_experimental_spec.rb +2 -2
- data/spec/integration/rest_gremlin_fail_spec.rb +2 -2
- data/spec/integration/rest_header_spec.rb +4 -9
- data/spec/integration/rest_index_spec.rb +21 -1
- data/spec/integration/rest_node_spec.rb +58 -44
- data/spec/integration/rest_path_spec.rb +5 -5
- data/spec/integration/rest_plugin_spec.rb +8 -2
- data/spec/integration/rest_relationship_spec.rb +35 -30
- data/spec/integration/rest_traverse_spec.rb +2 -2
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +19 -1
- data/spec/unit/config_spec.rb +46 -0
- data/spec/unit/connection_spec.rb +205 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +136 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +243 -0
- data/spec/unit/rest/clean_spec.rb +17 -0
- data/spec/unit/rest/cypher_spec.rb +21 -0
- data/spec/unit/rest/gremlin_spec.rb +26 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/node_indexes_spec.rb +126 -0
- data/spec/unit/rest/node_paths_spec.rb +80 -0
- data/spec/unit/rest/node_properties_spec.rb +80 -0
- data/spec/unit/rest/node_relationships_spec.rb +78 -0
- data/spec/unit/rest/node_traversal_spec.rb +128 -0
- data/spec/unit/rest/nodes_spec.rb +188 -0
- data/spec/unit/rest/paths_spec.rb +69 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +128 -0
- data/spec/unit/rest/relationship_properties_spec.rb +80 -0
- data/spec/unit/rest/relationships_spec.rb +22 -0
- metadata +86 -19
- data/Gemfile.lock +0 -44
- data/README.rdoc +0 -420
|
@@ -59,16 +59,18 @@ module Neography
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def filter(body)
|
|
62
|
-
@filter =
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
@filter = {
|
|
63
|
+
"language" => "javascript",
|
|
64
|
+
"body" => body
|
|
65
|
+
}
|
|
65
66
|
self
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
def prune(body)
|
|
69
|
-
@prune =
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
@prune = {
|
|
71
|
+
"language" => "javascript",
|
|
72
|
+
"body" => body
|
|
73
|
+
}
|
|
72
74
|
self
|
|
73
75
|
end
|
|
74
76
|
|
|
@@ -79,9 +81,10 @@ module Neography
|
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
def include_start_node
|
|
82
|
-
@filter =
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
@filter = {
|
|
85
|
+
"language" => "builtin",
|
|
86
|
+
"name" => "all"
|
|
87
|
+
}
|
|
85
88
|
self
|
|
86
89
|
end
|
|
87
90
|
|
|
@@ -108,13 +111,14 @@ module Neography
|
|
|
108
111
|
end
|
|
109
112
|
|
|
110
113
|
def iterator
|
|
111
|
-
options =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
options["
|
|
117
|
-
options["
|
|
114
|
+
options = {
|
|
115
|
+
"order" => @order,
|
|
116
|
+
"uniqueness" => @uniqueness,
|
|
117
|
+
"relationships" => @relationships
|
|
118
|
+
}
|
|
119
|
+
options["prune evaluator"] = @prune unless @prune.nil?
|
|
120
|
+
options["return filter"] = @filter unless @filter.nil?
|
|
121
|
+
options["depth"] = @depth unless @depth.nil?
|
|
118
122
|
|
|
119
123
|
if @relationships[0]["type"].empty?
|
|
120
124
|
rels = @from.neo_server.get_node_relationships(@from, @relationships[0]["direction"])
|
|
@@ -124,11 +128,11 @@ module Neography
|
|
|
124
128
|
when "out"
|
|
125
129
|
rels.collect { |r| @from.neo_server.get_node(r["end"]) } #.uniq
|
|
126
130
|
else
|
|
127
|
-
rels.collect { |r|
|
|
131
|
+
rels.collect { |r|
|
|
128
132
|
if @from.neo_id == r["start"].split('/').last
|
|
129
|
-
@from.neo_server.get_node(r["end"])
|
|
133
|
+
@from.neo_server.get_node(r["end"])
|
|
130
134
|
else
|
|
131
|
-
@from.neo_server.get_node(r["start"])
|
|
135
|
+
@from.neo_server.get_node(r["start"])
|
|
132
136
|
end
|
|
133
137
|
} #.uniq
|
|
134
138
|
end
|
|
@@ -139,4 +143,4 @@ module Neography
|
|
|
139
143
|
|
|
140
144
|
end
|
|
141
145
|
|
|
142
|
-
end
|
|
146
|
+
end
|
data/lib/neography/property.rb
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
module Neography
|
|
2
2
|
module Property
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
def [](key)
|
|
5
|
+
key = key.to_sym
|
|
6
6
|
return unless respond_to?(key)
|
|
7
7
|
@table[key]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def []=(key, value)
|
|
11
|
-
|
|
11
|
+
key = key.to_sym
|
|
12
|
+
k_str = key.to_s
|
|
12
13
|
if value.nil?
|
|
13
14
|
if self.is_a? Neography::Node
|
|
14
|
-
neo_server.remove_node_properties(self.neo_id, [
|
|
15
|
+
neo_server.remove_node_properties(self.neo_id, [k_str])
|
|
15
16
|
else
|
|
16
|
-
neo_server.remove_relationship_properties(self.neo_id, [
|
|
17
|
+
neo_server.remove_relationship_properties(self.neo_id, [k_str])
|
|
17
18
|
end
|
|
18
19
|
else
|
|
19
20
|
if self.is_a? Neography::Node
|
|
20
|
-
neo_server.set_node_properties(self.neo_id, {
|
|
21
|
+
neo_server.set_node_properties(self.neo_id, {k_str => value})
|
|
21
22
|
else
|
|
22
|
-
neo_server.set_relationship_properties(self.neo_id, {
|
|
23
|
+
neo_server.set_relationship_properties(self.neo_id, {k_str => value})
|
|
23
24
|
end
|
|
24
|
-
new_ostruct_member(
|
|
25
|
+
new_ostruct_member(key) unless self.respond_to?(key)
|
|
25
26
|
end
|
|
26
27
|
@table[key] = value
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
def new_ostruct_member(name)
|
|
31
|
+
name = name.to_sym
|
|
32
|
+
unless self.respond_to?(name)
|
|
33
|
+
meta = class << self; self; end
|
|
34
|
+
meta.send(:define_method, name) { @table[name] }
|
|
35
|
+
meta.send(:define_method, "#{name}=") do |value|
|
|
36
|
+
@table[name] = value
|
|
37
|
+
self[name.to_sym] = value
|
|
38
|
+
end
|
|
38
39
|
end
|
|
40
|
+
name
|
|
39
41
|
end
|
|
40
|
-
name
|
|
41
|
-
end
|
|
42
42
|
|
|
43
|
+
def method_missing(method_sym, *arguments, &block)
|
|
44
|
+
if (method_sym.to_s =~ /=$/) != nil
|
|
45
|
+
new_ostruct_member(method_sym.to_s.chomp("="))
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
# We just defined the getter/setter above, but we haven't actually
|
|
48
|
+
# applied them yet.
|
|
49
|
+
self.send(method_sym, *arguments)
|
|
50
|
+
else
|
|
51
|
+
super
|
|
52
|
+
end
|
|
53
|
+
end
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
self.send(method_sym, *arguments)
|
|
51
|
-
else
|
|
52
|
-
super
|
|
55
|
+
def attributes
|
|
56
|
+
@table.keys
|
|
53
57
|
end
|
|
54
|
-
end
|
|
55
58
|
|
|
56
59
|
end
|
|
57
|
-
end
|
|
60
|
+
end
|
|
@@ -8,7 +8,7 @@ module Neography
|
|
|
8
8
|
|
|
9
9
|
class << self
|
|
10
10
|
|
|
11
|
-
def create(type, from_node, to_node, props=nil)
|
|
11
|
+
def create(type, from_node, to_node, props = nil)
|
|
12
12
|
rel = Neography::Relationship.new(from_node.neo_server.create_relationship(type, from_node, to_node, props))
|
|
13
13
|
rel.start_node = from_node
|
|
14
14
|
rel.end_node = to_node
|
|
@@ -16,17 +16,14 @@ module Neography
|
|
|
16
16
|
rel
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def load(
|
|
20
|
-
|
|
21
|
-
rel = !args[0].is_a?(Neography::Rest) && args[0] || args[1]
|
|
19
|
+
def load(rel, db = Neography::Rest.new)
|
|
20
|
+
raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest)
|
|
22
21
|
|
|
23
|
-
# a db instance can be given, it is the first argument or the second
|
|
24
|
-
db = (args[0].is_a?(Neography::Rest) && args[0]) || args[1] || Neography::Rest.new
|
|
25
22
|
rel = db.get_relationship(rel)
|
|
26
|
-
|
|
27
|
-
rel = Neography::Relationship.new(rel)
|
|
28
|
-
rel.start_node = Neography::Node.load(rel.start_node, db)
|
|
29
|
-
rel.end_node = Neography::Node.load(rel.end_node, db)
|
|
23
|
+
if rel
|
|
24
|
+
rel = Neography::Relationship.new(rel)
|
|
25
|
+
rel.start_node = Neography::Node.load(rel.start_node, db)
|
|
26
|
+
rel.end_node = Neography::Node.load(rel.end_node, db)
|
|
30
27
|
end
|
|
31
28
|
rel
|
|
32
29
|
end
|
|
@@ -39,26 +36,26 @@ module Neography
|
|
|
39
36
|
@rel_type = hash["type"]
|
|
40
37
|
neo_server = server
|
|
41
38
|
end
|
|
42
|
-
|
|
39
|
+
|
|
43
40
|
def neo_server
|
|
44
41
|
@neo_server ||= self.start_node.neo_server
|
|
45
42
|
end
|
|
46
|
-
|
|
43
|
+
|
|
47
44
|
def neo_server=(server)
|
|
48
45
|
@neo_server = server
|
|
49
46
|
end
|
|
50
47
|
|
|
51
48
|
def del
|
|
52
|
-
|
|
49
|
+
start_node.neo_server.delete_relationship(neo_id)
|
|
53
50
|
end
|
|
54
51
|
|
|
55
52
|
def exist?
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
begin
|
|
54
|
+
start_node.neo_server.get_relationship(neo_id)
|
|
55
|
+
true
|
|
56
|
+
rescue Neography::RelationshipNotFoundException
|
|
57
|
+
false
|
|
58
|
+
end
|
|
62
59
|
end
|
|
63
60
|
|
|
64
61
|
def other_node(node)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
class AutoIndexes
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
@connection = connection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get(key, value)
|
|
11
|
+
index = @connection.get(key_value_path(:key => key, :value => value)) || []
|
|
12
|
+
return nil if index.empty?
|
|
13
|
+
index
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def find_or_query(key_or_query, value = nil)
|
|
17
|
+
if value
|
|
18
|
+
index = find(key_or_query, value)
|
|
19
|
+
else
|
|
20
|
+
index = query(key_or_query)
|
|
21
|
+
end
|
|
22
|
+
return nil if index.empty?
|
|
23
|
+
index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def find(key, value)
|
|
27
|
+
@connection.get(key_value_path(:key => key, :value => value)) || []
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query(query_expression)
|
|
31
|
+
@connection.get(query_index_path(:query => query_expression)) || []
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def status
|
|
35
|
+
@connection.get(index_status_path)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def status=(value)
|
|
39
|
+
options = {
|
|
40
|
+
:body => value.to_json,
|
|
41
|
+
:headers => json_content_type
|
|
42
|
+
}
|
|
43
|
+
@connection.put(index_status_path, options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def properties
|
|
47
|
+
@connection.get(index_properties_path)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def add_property(property)
|
|
51
|
+
options = {
|
|
52
|
+
:body => property,
|
|
53
|
+
:headers => json_content_type
|
|
54
|
+
}
|
|
55
|
+
@connection.post(index_properties_path, options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def remove_property(property)
|
|
59
|
+
@connection.delete(index_property_path(:property => property))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
class Batch
|
|
4
|
+
extend Neography::Rest::Paths
|
|
5
|
+
include Neography::Rest::Helpers
|
|
6
|
+
|
|
7
|
+
add_path :batch, "/batch"
|
|
8
|
+
|
|
9
|
+
def initialize(connection)
|
|
10
|
+
@connection = connection
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def execute(*args)
|
|
14
|
+
batch({'Accept' => 'application/json;stream=true'}, *args)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def not_streaming(*args)
|
|
18
|
+
batch({}, *args)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def batch(accept_header, *args)
|
|
24
|
+
batch = []
|
|
25
|
+
Array(args).each_with_index do |c, i|
|
|
26
|
+
batch << {:id => i }.merge(get_batch(c))
|
|
27
|
+
end
|
|
28
|
+
options = {
|
|
29
|
+
:body => batch.to_json,
|
|
30
|
+
:headers => json_content_type.merge(accept_header)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@connection.post(batch_path, options)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_batch(args)
|
|
37
|
+
if respond_to?(args[0].to_sym, true)
|
|
38
|
+
send(args[0].to_sym, *args[1..-1])
|
|
39
|
+
else
|
|
40
|
+
raise "Unknown option #{args[0]}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Nodes
|
|
45
|
+
|
|
46
|
+
def get_node(id)
|
|
47
|
+
get Nodes.base_path(:id => get_id(id))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def delete_node(id)
|
|
51
|
+
delete Nodes.base_path(:id => get_id(id))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def create_node(body)
|
|
55
|
+
post Nodes.index_path do
|
|
56
|
+
body
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# NodeIndexes
|
|
61
|
+
|
|
62
|
+
def create_unique_node(index, key, value, properties)
|
|
63
|
+
post NodeIndexes.unique_path(:index => index) do
|
|
64
|
+
{
|
|
65
|
+
:key => key,
|
|
66
|
+
:value => value,
|
|
67
|
+
:properties => properties
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def add_node_to_index(index, key, value, id)
|
|
73
|
+
post NodeIndexes.base_path(:index => index) do
|
|
74
|
+
{
|
|
75
|
+
:uri => build_node_uri(id),
|
|
76
|
+
:key => key,
|
|
77
|
+
:value => value
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def get_node_index(index, key, value)
|
|
83
|
+
get NodeIndexes.key_value_path(:index => index, :key => key, :value => value)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
|
|
87
|
+
delete remove_from_index_path(NodeIndexes, index, key_or_id, value_or_id, id)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# NodeProperties
|
|
91
|
+
|
|
92
|
+
def set_node_property(id, property)
|
|
93
|
+
put NodeProperties.single_path(:id => get_id(id), :property => property.keys.first) do
|
|
94
|
+
property.values.first
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def reset_node_properties(id, body)
|
|
99
|
+
put NodeProperties.all_path(:id => get_id(id)) do
|
|
100
|
+
body
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# NodeRelationships
|
|
105
|
+
|
|
106
|
+
def get_node_relationships(id, direction = nil)
|
|
107
|
+
get NodeRelationships.direction_path(:id => get_id(id), :direction => direction || 'all')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Relationships
|
|
111
|
+
|
|
112
|
+
def get_relationship(id)
|
|
113
|
+
get Relationships.base_path(:id => get_id(id))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def delete_relationship(id)
|
|
117
|
+
delete Relationships.base_path(:id => get_id(id))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def create_relationship(type, from, to, data)
|
|
121
|
+
post build_node_uri(from) + "/relationships" do
|
|
122
|
+
{
|
|
123
|
+
:to => build_node_uri(to),
|
|
124
|
+
:type => type,
|
|
125
|
+
:data => data
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# RelationshipIndexes
|
|
131
|
+
|
|
132
|
+
def create_unique_relationship(index, key, value, type, from, to)
|
|
133
|
+
post RelationshipIndexes.unique_path(:index => index) do
|
|
134
|
+
{
|
|
135
|
+
:key => key,
|
|
136
|
+
:value => value,
|
|
137
|
+
:type => type,
|
|
138
|
+
:start => build_node_uri(from),
|
|
139
|
+
:end => build_node_uri(to)
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def add_relationship_to_index(index, key, value, id)
|
|
145
|
+
post RelationshipIndexes.base_path(:index => index) do
|
|
146
|
+
{
|
|
147
|
+
:uri => build_relationship_uri(id),
|
|
148
|
+
:key => key,
|
|
149
|
+
:value => value
|
|
150
|
+
}
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def get_relationship_index(index, key, value)
|
|
155
|
+
get RelationshipIndexes.key_value_path(:index => index, :key => key, :value => value)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
|
|
159
|
+
delete remove_from_index_path(RelationshipIndexes, index, key_or_id, value_or_id, id)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# RelationshipProperties
|
|
163
|
+
|
|
164
|
+
def set_relationship_property(id, property)
|
|
165
|
+
put RelationshipProperties.single_path(:id => get_id(id), :property => property.keys.first) do
|
|
166
|
+
property.values.first
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def reset_relationship_properties(id, body)
|
|
171
|
+
put build_relationship_uri(id) + "/properties" do
|
|
172
|
+
body
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Cypher
|
|
177
|
+
|
|
178
|
+
def execute_query(query, params = nil)
|
|
179
|
+
request = post @connection.cypher_path do
|
|
180
|
+
{
|
|
181
|
+
:query => query
|
|
182
|
+
}
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
request[:body].merge!({ :params => params }) if params
|
|
186
|
+
|
|
187
|
+
request
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Gremlin
|
|
191
|
+
|
|
192
|
+
def execute_script(script, params = nil)
|
|
193
|
+
post @connection.gremlin_path do
|
|
194
|
+
{
|
|
195
|
+
:script => script,
|
|
196
|
+
:params => params
|
|
197
|
+
}
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Similar between nodes and relationships
|
|
202
|
+
|
|
203
|
+
def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil)
|
|
204
|
+
if id
|
|
205
|
+
klass.value_path(:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id))
|
|
206
|
+
elsif value_or_id
|
|
207
|
+
klass.key_path(:index => index, :key => key_or_id, :id => get_id(value_or_id))
|
|
208
|
+
else
|
|
209
|
+
klass.id_path(:index => index, :id => get_id(key_or_id))
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def get(to, &block)
|
|
214
|
+
request "GET", to, &block
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def delete(to, &block)
|
|
218
|
+
request "DELETE", to, &block
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def post(to, &block)
|
|
222
|
+
request "POST", to, &block
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def put(to, &block)
|
|
226
|
+
request "PUT", to, &block
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def request(method, to, &block)
|
|
230
|
+
request = {
|
|
231
|
+
:method => method,
|
|
232
|
+
:to => to
|
|
233
|
+
}
|
|
234
|
+
request.merge!({ :body => yield }) if block_given?
|
|
235
|
+
request
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Helper methods
|
|
239
|
+
|
|
240
|
+
def build_node_uri(value)
|
|
241
|
+
build_uri(value, "node")
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def build_relationship_uri(value)
|
|
245
|
+
build_uri(value, "relationship")
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def build_uri(value, type)
|
|
249
|
+
path_or_variable(value, type) + "#{get_id(value)}"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def path_or_variable(value, type)
|
|
253
|
+
if value.is_a?(String) && value.start_with?("{")
|
|
254
|
+
""
|
|
255
|
+
else
|
|
256
|
+
"/#{type}/"
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
class Clean
|
|
4
|
+
extend Neography::Rest::Paths
|
|
5
|
+
include Neography::Rest::Helpers
|
|
6
|
+
|
|
7
|
+
add_path :clean, "/cleandb/secret-key"
|
|
8
|
+
|
|
9
|
+
def initialize(connection)
|
|
10
|
+
@connection = connection
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def execute
|
|
14
|
+
@connection.delete(clean_path)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
class Cypher
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
@connection = connection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def query(query, parameters = {})
|
|
11
|
+
options = {
|
|
12
|
+
:body => {
|
|
13
|
+
:query => query,
|
|
14
|
+
:params => parameters
|
|
15
|
+
}.to_json,
|
|
16
|
+
:headers => json_content_type.merge({'Accept' => 'application/json;stream=true'})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@connection.post(@connection.cypher_path, options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
class Gremlin
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def initialize(connection)
|
|
7
|
+
@connection = connection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def execute(script, parameters = {})
|
|
11
|
+
options = {
|
|
12
|
+
:body => {
|
|
13
|
+
:script => script,
|
|
14
|
+
:params => parameters,
|
|
15
|
+
}.to_json,
|
|
16
|
+
:headers => json_content_type
|
|
17
|
+
}
|
|
18
|
+
result = @connection.post(@connection.gremlin_path, options)
|
|
19
|
+
result == "null" ? nil : result
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module Helpers
|
|
4
|
+
|
|
5
|
+
def get_id(id)
|
|
6
|
+
case id
|
|
7
|
+
when Array
|
|
8
|
+
get_id(id.first)
|
|
9
|
+
when Hash
|
|
10
|
+
id["self"].split('/').last
|
|
11
|
+
when String
|
|
12
|
+
id.split('/').last
|
|
13
|
+
when Neography::Node, Neography::Relationship
|
|
14
|
+
id.neo_id
|
|
15
|
+
else
|
|
16
|
+
id
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def json_content_type
|
|
21
|
+
{'Content-Type' => 'application/json'}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|