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,22 +1,15 @@
1
1
  module Neography
2
2
  class Rest
3
- class Batch
4
- extend Neography::Rest::Paths
3
+ module Batch
5
4
  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(*args)
5
+
6
+ def batch(*args)
7
+ do_batch(*args)
15
8
  end
16
9
 
17
10
  private
18
11
 
19
- def batch(*args)
12
+ def do_batch(*args)
20
13
  batch = []
21
14
  Array(args).each_with_index do |c, i|
22
15
  batch << {:id => i }.merge(get_batch(c))
@@ -25,54 +18,54 @@ module Neography
25
18
  :body => batch.to_json,
26
19
  :headers => json_content_type
27
20
  }
28
- @connection.post(batch_path, options)
21
+ @connection.post("/batch", options)
29
22
  end
30
23
 
31
24
  def get_batch(args)
32
- if respond_to?(args[0].to_sym, true)
33
- send(args[0].to_sym, *args[1..-1])
25
+ if args[0].class == Symbol
26
+ send(("batch_" + args[0].to_s).to_sym, *args[1..-1])
34
27
  else
35
- raise "Unknown option #{args[0]}"
28
+ raise "Unknown option #{args[0]} - #{args}"
36
29
  end
37
30
  end
38
31
 
39
32
  # Nodes
40
33
 
41
- def get_node(id)
42
- get Nodes.base_path(:id => get_id(id))
34
+ def batch_get_node(id)
35
+ get "/node/%{id}" % {:id => get_id(id)}
43
36
  end
44
37
 
45
- def delete_node(id)
46
- delete Nodes.base_path(:id => get_id(id))
38
+ def batch_delete_node(id)
39
+ delete "/node/%{id}" % {:id => get_id(id)}
47
40
  end
48
41
 
49
- def create_node(body)
50
- post Nodes.index_path do
42
+ def batch_create_node(body)
43
+ post "/node" do
51
44
  body
52
45
  end
53
46
  end
54
47
 
55
48
  # NodeIndexes
56
49
 
57
- def create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
50
+ def batch_create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
58
51
  config = {
59
52
  :type => type,
60
53
  :provider => provider
61
54
  }
62
55
  config.merge!(extra_config) unless extra_config.nil?
63
- post NodeIndexes.all_path do
56
+ post "/index/node" do
64
57
  { :name => name,
65
58
  :config => config
66
59
  }
67
60
  end
68
61
  end
69
62
 
70
- def drop_node_index(index)
71
- delete NodeIndexes.unique_path(:index => index)
63
+ def batch_drop_node_index(index)
64
+ delete "/index/node/%{index}?unique" % {:index => index}
72
65
  end
73
66
 
74
- def create_unique_node(index, key, value, properties)
75
- post NodeIndexes.unique_path(:index => index) do
67
+ def batch_create_unique_node(index, key, value, properties)
68
+ post "/index/node/%{index}?unique" % {:index => index} do
76
69
  {
77
70
  :key => key,
78
71
  :value => value,
@@ -81,8 +74,8 @@ module Neography
81
74
  end
82
75
  end
83
76
 
84
- def add_node_to_index(index, key, value, id, unique = false)
85
- path = unique ? NodeIndexes.unique_path(:index => index) : NodeIndexes.base_path(:index => index)
77
+ def batch_add_node_to_index(index, key, value, id, unique = false)
78
+ path = unique ? "/index/node/%{index}?unique" % {:index => index} : "/index/node/%{index}" % {:index => index}
86
79
  post path do
87
80
  {
88
81
  :uri => build_node_uri(id),
@@ -92,35 +85,35 @@ module Neography
92
85
  end
93
86
  end
94
87
 
95
- def get_node_index(index, key, value)
96
- get NodeIndexes.key_value_path(:index => index, :key => key, :value => value)
88
+ def batch_get_node_index(index, key, value)
89
+ get "/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
97
90
  end
98
91
 
99
- def remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
100
- delete remove_from_index_path(NodeIndexes, index, key_or_id, value_or_id, id)
92
+ def batch_remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
93
+ delete remove_from_index_path("node", index, key_or_id, value_or_id, id)
101
94
  end
102
95
 
103
96
  # NodeProperties
104
97
 
105
- def set_node_property(id, property)
106
- put NodeProperties.single_path(:id => get_id(id), :property => property.keys.first) do
98
+ def batch_set_node_property(id, property)
99
+ put "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
107
100
  property.values.first
108
101
  end
109
102
  end
110
103
 
111
- def reset_node_properties(id, body)
112
- put NodeProperties.all_path(:id => get_id(id)) do
104
+ def batch_reset_node_properties(id, body)
105
+ put "/node/%{id}/properties" % {:id => get_id(id)} do
113
106
  body
114
107
  end
115
108
  end
116
109
 
117
- def remove_node_property(id, property)
118
- delete NodeProperties.single_path(:id => get_id(id), :property => property)
110
+ def batch_remove_node_property(id, property)
111
+ delete "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}
119
112
  end
120
113
 
121
114
  # NodeLabel
122
115
 
123
- def add_label(id, body)
116
+ def batch_add_label(id, body)
124
117
  post build_node_uri(id) + "/labels" do
125
118
  body
126
119
  end
@@ -128,25 +121,25 @@ module Neography
128
121
 
129
122
  # NodeRelationships
130
123
 
131
- def get_node_relationships(id, direction = nil, types = nil)
124
+ def batch_get_node_relationships(id, direction = nil, types = nil)
132
125
  if types.nil?
133
- get NodeRelationships.direction_path(:id => get_id(id), :direction => direction || 'all')
126
+ get "/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction || 'all'}
134
127
  else
135
- get NodeRelationships.type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))
128
+ get "/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => Array(types).join('&')}
136
129
  end
137
130
  end
138
131
 
139
132
  # Relationships
140
133
 
141
- def get_relationship(id)
142
- get Relationships.base_path(:id => get_id(id))
134
+ def batch_get_relationship(id)
135
+ get "/relationship/%{id}" % {:id => get_id(id)}
143
136
  end
144
137
 
145
- def delete_relationship(id)
146
- delete Relationships.base_path(:id => get_id(id))
138
+ def batch_delete_relationship(id)
139
+ delete "/relationship/%{id}" % {:id => get_id(id)}
147
140
  end
148
141
 
149
- def create_relationship(type, from, to, data = nil)
142
+ def batch_create_relationship(type, from, to, data = nil)
150
143
  post build_node_uri(from) + "/relationships" do
151
144
  {
152
145
  :to => build_node_uri(to),
@@ -158,8 +151,8 @@ module Neography
158
151
 
159
152
  # RelationshipIndexes
160
153
 
161
- def create_unique_relationship(index, key, value, type, from, to, props = nil)
162
- post RelationshipIndexes.unique_path(:index => index) do
154
+ def batch_create_unique_relationship(index, key, value, type, from, to, props = nil)
155
+ post "/index/relationship/%{index}?unique" % {:index => index} do
163
156
  {
164
157
  :key => key,
165
158
  :value => value,
@@ -171,8 +164,8 @@ module Neography
171
164
  end
172
165
  end
173
166
 
174
- def add_relationship_to_index(index, key, value, id)
175
- post RelationshipIndexes.base_path(:index => index) do
167
+ def batch_add_relationship_to_index(index, key, value, id)
168
+ post "/index/relationship/%{index}" % {:index => index} do
176
169
  {
177
170
  :uri => build_relationship_uri(id),
178
171
  :key => key,
@@ -181,23 +174,23 @@ module Neography
181
174
  end
182
175
  end
183
176
 
184
- def get_relationship_index(index, key, value)
185
- get RelationshipIndexes.key_value_path(:index => index, :key => key, :value => value)
177
+ def batch_get_relationship_index(index, key, value)
178
+ get "/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
186
179
  end
187
180
 
188
- def remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
189
- delete remove_from_index_path(RelationshipIndexes, index, key_or_id, value_or_id, id)
181
+ def batch_remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
182
+ delete remove_from_index_path("relationship", index, key_or_id, value_or_id, id)
190
183
  end
191
184
 
192
185
  # RelationshipProperties
193
186
 
194
- def set_relationship_property(id, property)
195
- put RelationshipProperties.single_path(:id => get_id(id), :property => property.keys.first) do
187
+ def batch_set_relationship_property(id, property)
188
+ put "/relationship/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
196
189
  property.values.first
197
190
  end
198
191
  end
199
192
 
200
- def reset_relationship_properties(id, body)
193
+ def batch_reset_relationship_properties(id, body)
201
194
  put build_relationship_uri(id) + "/properties" do
202
195
  body
203
196
  end
@@ -205,7 +198,7 @@ module Neography
205
198
 
206
199
  # Cypher
207
200
 
208
- def execute_query(query, params = nil)
201
+ def batch_execute_query(query, params = nil)
209
202
  request = post @connection.cypher_path do
210
203
  {
211
204
  :query => query
@@ -219,7 +212,7 @@ module Neography
219
212
 
220
213
  # Gremlin
221
214
 
222
- def execute_script(script, params = nil)
215
+ def batch_execute_script(script, params = nil)
223
216
  post @connection.gremlin_path do
224
217
  {
225
218
  :script => script,
@@ -232,22 +225,22 @@ module Neography
232
225
 
233
226
  def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil)
234
227
  if id
235
- klass.value_path(:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id))
228
+ "/index/#{klass}/%{index}/%{key}/%{value}/%{id}" % {:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id)}
236
229
  elsif value_or_id
237
- klass.key_path(:index => index, :key => key_or_id, :id => get_id(value_or_id))
230
+ "/index/#{klass}/%{index}/%{key}/%{id}" % {:index => index, :key => key_or_id, :id => get_id(value_or_id)}
238
231
  else
239
- klass.id_path(:index => index, :id => get_id(key_or_id))
232
+ "/index/#{klass}/%{index}/%{id}" % {:index => index, :id => get_id(key_or_id)}
240
233
  end
241
234
  end
242
235
 
243
236
  # Spatial
244
237
 
245
- def get_spatial
246
- get Spatial.index_path
238
+ def batch_get_spatial
239
+ get "/ext/SpatialPlugin"
247
240
  end
248
241
 
249
- def add_point_layer(layer, lat = nil, lon = nil)
250
- post Spatial.add_simple_point_layer_path do
242
+ def batch_add_point_layer(layer, lat = nil, lon = nil)
243
+ post "/ext/SpatialPlugin/graphdb/addSimplePointLayer" do
251
244
  {
252
245
  :layer => layer,
253
246
  :lat => lat || "lat",
@@ -256,8 +249,8 @@ module Neography
256
249
  end
257
250
  end
258
251
 
259
- def add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
260
- post Spatial.add_editable_layer_path do
252
+ def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
253
+ post "/ext/SpatialPlugin/graphdb/addEditableLayer" do
261
254
  {
262
255
  :layer => layer,
263
256
  :format => format,
@@ -266,16 +259,16 @@ module Neography
266
259
  end
267
260
  end
268
261
 
269
- def get_layer(layer)
270
- post Spatial.get_layer_path do
262
+ def batch_get_layer(layer)
263
+ post "/ext/SpatialPlugin/graphdb/getLayer" do
271
264
  {
272
265
  :layer => layer
273
266
  }
274
267
  end
275
268
  end
276
269
 
277
- def add_geometry_to_layer(layer, geometry)
278
- post Spatial.add_geometry_to_layer_path do
270
+ def batch_add_geometry_to_layer(layer, geometry)
271
+ post "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" do
279
272
  {
280
273
  :layer => layer,
281
274
  :geometry => geometry
@@ -283,8 +276,8 @@ module Neography
283
276
  end
284
277
  end
285
278
 
286
- def edit_geometry_from_layer(layer, geometry, node)
287
- post Spatial.edit_geometry_from_layer_path do
279
+ def batch_edit_geometry_from_layer(layer, geometry, node)
280
+ post "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" do
288
281
  {
289
282
  :layer => layer,
290
283
  :geometry => geometry,
@@ -293,8 +286,8 @@ module Neography
293
286
  end
294
287
  end
295
288
 
296
- def add_node_to_layer(layer, node)
297
- post Spatial.add_node_to_layer_path do
289
+ def batch_add_node_to_layer(layer, node)
290
+ post "/ext/SpatialPlugin/graphdb/addNodeToLayer" do
298
291
  {
299
292
  :layer => layer,
300
293
  :node => get_id(node)
@@ -302,8 +295,8 @@ module Neography
302
295
  end
303
296
  end
304
297
 
305
- def find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
306
- post Spatial.find_geometries_in_bbox_path do
298
+ def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
299
+ post "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" do
307
300
  {
308
301
  :layer => layer,
309
302
  :minx => minx,
@@ -314,8 +307,8 @@ module Neography
314
307
  end
315
308
  end
316
309
 
317
- def find_geometries_within_distance(layer, pointx, pointy, distance)
318
- post Spatial.find_geometries_within_distance_path do
310
+ def batch_find_geometries_within_distance(layer, pointx, pointy, distance)
311
+ post "/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" do
319
312
  {
320
313
  :layer => layer,
321
314
  :pointX => pointx,
@@ -325,8 +318,8 @@ module Neography
325
318
  end
326
319
  end
327
320
 
328
- def create_spatial_index(name, type, lat, lon)
329
- post NodeIndexes.all_path do
321
+ def batch_create_spatial_index(name, type, lat, lon)
322
+ post "/index/node" do
330
323
  {
331
324
  :name => name,
332
325
  :config => {
@@ -339,8 +332,8 @@ module Neography
339
332
  end
340
333
  end
341
334
 
342
- def add_node_to_spatial_index(index, id)
343
- post NodeIndexes.base_path(:index => index) do
335
+ def batch_add_node_to_spatial_index(index, id)
336
+ post "/index/node/%{index}" % {:index => index} do
344
337
  {
345
338
  :uri => build_node_uri(id),
346
339
  :key => "k",
@@ -1,17 +1,15 @@
1
1
  module Neography
2
2
  class Rest
3
- class Clean
4
- extend Neography::Rest::Paths
3
+ module Clean
5
4
  include Neography::Rest::Helpers
6
5
 
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)
6
+ def clean_database(sanity_check = "not_really")
7
+ if sanity_check == "yes_i_really_want_to_clean_the_database"
8
+ @connection.delete("/cleandb/secret-key")
9
+ true
10
+ else
11
+ false
12
+ end
15
13
  end
16
14
 
17
15
  end
@@ -1,46 +1,36 @@
1
1
  module Neography
2
2
  class Rest
3
- class Constraints
4
- extend Neography::Rest::Paths
3
+ module Constraints
5
4
  include Neography::Rest::Helpers
6
-
7
- add_path :base, "/schema/constraint/"
8
- add_path :label, "/schema/constraint/:label"
9
- add_path :uniqueness, "/schema/constraint/:label/uniqueness/"
10
- add_path :unique, "/schema/constraint/:label/uniqueness/:property"
11
-
12
- def initialize(connection)
13
- @connection ||= connection
14
- end
15
-
16
- def drop(label, property)
17
- @connection.delete(unique_path(:label => label, :property => property))
18
- end
19
-
20
- def list
21
- @connection.get(base_path)
5
+
6
+ def drop_constraint(label, property)
7
+ @connection.delete("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
22
8
  end
23
9
 
24
- def get(label)
25
- @connection.get(label_path(:label => label))
10
+ def get_constraints(label=nil)
11
+ #if label.nil?
12
+ # @connection.get(base_path)
13
+ #else
14
+ @connection.get("/schema/constraint/%{label}" % {:label => label})
15
+ #end
26
16
  end
27
17
 
28
18
  def get_uniqueness(label)
29
- @connection.get(uniqueness_path(:label => label))
19
+ @connection.get("/schema/constraint/%{label}/uniqueness/" % {:label => label})
30
20
  end
31
21
 
32
- def get_unique(label, property)
33
- @connection.get(unique_path(:label => label, :property => property))
22
+ def get_unique_constraint(label, property)
23
+ @connection.get("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
34
24
  end
35
25
 
36
- def create_unique(label, property)
26
+ def create_unique_constraint(label, property)
37
27
  options = {
38
28
  :body => {
39
29
  :property_keys => [property]
40
30
  }.to_json,
41
31
  :headers => json_content_type
42
32
  }
43
- @connection.post(uniqueness_path(:label => label), options)
33
+ @connection.post("/schema/constraint/%{label}/uniqueness/" % {:label => label}, options)
44
34
  end
45
35
 
46
36
  end