neography-down 1.6.4

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.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.project +12 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +4 -0
  6. data/CHANGELOG.md +939 -0
  7. data/CONTRIBUTORS +18 -0
  8. data/Gemfile +4 -0
  9. data/Guardfile +14 -0
  10. data/LICENSE +19 -0
  11. data/README.md +281 -0
  12. data/Rakefile +14 -0
  13. data/examples/facebook.rb +40 -0
  14. data/examples/facebook_v2.rb +25 -0
  15. data/examples/greatest.rb +43 -0
  16. data/examples/linkedin.rb +39 -0
  17. data/examples/linkedin_v2.rb +22 -0
  18. data/examples/traversal_example1.rb +65 -0
  19. data/examples/traversal_example2.rb +54 -0
  20. data/lib/neography.rb +45 -0
  21. data/lib/neography/config.rb +64 -0
  22. data/lib/neography/connection.rb +263 -0
  23. data/lib/neography/equal.rb +21 -0
  24. data/lib/neography/errors.rb +60 -0
  25. data/lib/neography/index.rb +52 -0
  26. data/lib/neography/multi_json_parser.rb +28 -0
  27. data/lib/neography/neography.rb +10 -0
  28. data/lib/neography/node.rb +63 -0
  29. data/lib/neography/node_path.rb +29 -0
  30. data/lib/neography/node_relationship.rb +37 -0
  31. data/lib/neography/node_traverser.rb +146 -0
  32. data/lib/neography/path_traverser.rb +100 -0
  33. data/lib/neography/property.rb +110 -0
  34. data/lib/neography/property_container.rb +28 -0
  35. data/lib/neography/railtie.rb +19 -0
  36. data/lib/neography/relationship.rb +78 -0
  37. data/lib/neography/relationship_traverser.rb +80 -0
  38. data/lib/neography/rest.rb +99 -0
  39. data/lib/neography/rest/batch.rb +414 -0
  40. data/lib/neography/rest/clean.rb +17 -0
  41. data/lib/neography/rest/constraints.rb +38 -0
  42. data/lib/neography/rest/cypher.rb +29 -0
  43. data/lib/neography/rest/extensions.rb +21 -0
  44. data/lib/neography/rest/gremlin.rb +20 -0
  45. data/lib/neography/rest/helpers.rb +96 -0
  46. data/lib/neography/rest/node_auto_indexes.rb +60 -0
  47. data/lib/neography/rest/node_indexes.rb +139 -0
  48. data/lib/neography/rest/node_labels.rb +49 -0
  49. data/lib/neography/rest/node_paths.rb +49 -0
  50. data/lib/neography/rest/node_properties.rb +52 -0
  51. data/lib/neography/rest/node_relationships.rb +33 -0
  52. data/lib/neography/rest/node_traversal.rb +25 -0
  53. data/lib/neography/rest/nodes.rb +94 -0
  54. data/lib/neography/rest/other_node_relationships.rb +38 -0
  55. data/lib/neography/rest/relationship_auto_indexes.rb +60 -0
  56. data/lib/neography/rest/relationship_indexes.rb +142 -0
  57. data/lib/neography/rest/relationship_properties.rb +52 -0
  58. data/lib/neography/rest/relationship_types.rb +11 -0
  59. data/lib/neography/rest/relationships.rb +16 -0
  60. data/lib/neography/rest/schema_indexes.rb +26 -0
  61. data/lib/neography/rest/spatial.rb +137 -0
  62. data/lib/neography/rest/transactions.rb +101 -0
  63. data/lib/neography/tasks.rb +207 -0
  64. data/lib/neography/version.rb +3 -0
  65. data/neography.gemspec +39 -0
  66. data/spec/integration/authorization_spec.rb +40 -0
  67. data/spec/integration/broken_spatial_spec.rb +28 -0
  68. data/spec/integration/index_spec.rb +71 -0
  69. data/spec/integration/neography_spec.rb +10 -0
  70. data/spec/integration/node_encoding_spec.rb +71 -0
  71. data/spec/integration/node_path_spec.rb +222 -0
  72. data/spec/integration/node_relationship_spec.rb +381 -0
  73. data/spec/integration/node_spec.rb +260 -0
  74. data/spec/integration/parsing_spec.rb +13 -0
  75. data/spec/integration/performance_spec.rb +17 -0
  76. data/spec/integration/relationship_spec.rb +37 -0
  77. data/spec/integration/rest_batch_no_streaming_spec.rb +41 -0
  78. data/spec/integration/rest_batch_spec.rb +604 -0
  79. data/spec/integration/rest_batch_streaming_spec.rb +51 -0
  80. data/spec/integration/rest_bulk_spec.rb +106 -0
  81. data/spec/integration/rest_constraints_spec.rb +72 -0
  82. data/spec/integration/rest_experimental_spec.rb +22 -0
  83. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  84. data/spec/integration/rest_header_spec.rb +15 -0
  85. data/spec/integration/rest_index_spec.rb +481 -0
  86. data/spec/integration/rest_labels_spec.rb +128 -0
  87. data/spec/integration/rest_node_spec.rb +274 -0
  88. data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
  89. data/spec/integration/rest_path_spec.rb +231 -0
  90. data/spec/integration/rest_plugin_spec.rb +177 -0
  91. data/spec/integration/rest_relationship_spec.rb +354 -0
  92. data/spec/integration/rest_relationship_types_spec.rb +18 -0
  93. data/spec/integration/rest_schema_index_spec.rb +32 -0
  94. data/spec/integration/rest_spatial_spec.rb +166 -0
  95. data/spec/integration/rest_transaction_spec.rb +166 -0
  96. data/spec/integration/rest_traverse_spec.rb +149 -0
  97. data/spec/integration/unmanaged_spec.rb +27 -0
  98. data/spec/matchers.rb +33 -0
  99. data/spec/neography_spec.rb +23 -0
  100. data/spec/spec_helper.rb +44 -0
  101. data/spec/unit/config_spec.rb +135 -0
  102. data/spec/unit/connection_spec.rb +284 -0
  103. data/spec/unit/node_spec.rb +100 -0
  104. data/spec/unit/properties_spec.rb +285 -0
  105. data/spec/unit/relationship_spec.rb +118 -0
  106. data/spec/unit/rest/batch_spec.rb +262 -0
  107. data/spec/unit/rest/clean_spec.rb +16 -0
  108. data/spec/unit/rest/constraints_spec.rb +45 -0
  109. data/spec/unit/rest/cypher_spec.rb +20 -0
  110. data/spec/unit/rest/extensions_spec.rb +28 -0
  111. data/spec/unit/rest/gremlin_spec.rb +25 -0
  112. data/spec/unit/rest/helpers_spec.rb +124 -0
  113. data/spec/unit/rest/labels_spec.rb +77 -0
  114. data/spec/unit/rest/node_auto_indexes_spec.rb +70 -0
  115. data/spec/unit/rest/node_indexes_spec.rb +140 -0
  116. data/spec/unit/rest/node_paths_spec.rb +77 -0
  117. data/spec/unit/rest/node_properties_spec.rb +79 -0
  118. data/spec/unit/rest/node_relationships_spec.rb +57 -0
  119. data/spec/unit/rest/node_traversal_spec.rb +35 -0
  120. data/spec/unit/rest/nodes_spec.rb +187 -0
  121. data/spec/unit/rest/relationship_auto_indexes_spec.rb +66 -0
  122. data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
  123. data/spec/unit/rest/relationship_properties_spec.rb +79 -0
  124. data/spec/unit/rest/relationship_types_spec.rb +15 -0
  125. data/spec/unit/rest/relationships_spec.rb +21 -0
  126. data/spec/unit/rest/schema_index_spec.rb +30 -0
  127. data/spec/unit/rest/transactions_spec.rb +43 -0
  128. metadata +372 -0
@@ -0,0 +1,414 @@
1
+ module Neography
2
+ class Rest
3
+ module Batch
4
+ include Neography::Rest::Helpers
5
+
6
+ def batch(*args)
7
+ do_batch(*args)
8
+ end
9
+
10
+ def batch_no_streaming(*args)
11
+ do_batch_no_streaming(*args)
12
+ end
13
+
14
+ private
15
+
16
+ def do_batch(*args)
17
+ @connection.post("/batch", compute_batch_options(*args))
18
+ end
19
+
20
+ def do_batch_no_streaming(*args)
21
+ options = compute_batch_options(*args)
22
+ options[:headers].merge!({ 'X-Stream' => false })
23
+ @connection.post("/batch", options)
24
+ end
25
+
26
+ def compute_batch_options(*args)
27
+ batch = []
28
+ Array(args).each_with_index do |c, i|
29
+ batch << {:id => i }.merge(get_batch(c))
30
+ end
31
+ {:body => batch.to_json, :headers => json_content_type}
32
+ end
33
+
34
+ def get_batch(args)
35
+ begin
36
+ send("batch_#{args[0]}".to_sym, *args[1..-1])
37
+ rescue
38
+ raise UnknownBatchOptionException.new("Unknown option #{args[0]} - #{args}")
39
+ end
40
+ end
41
+
42
+ # Nodes
43
+
44
+ def batch_get_node(id)
45
+ get "/node/%{id}" % {:id => get_id(id)}
46
+ end
47
+
48
+ def batch_delete_node(id)
49
+ delete "/node/%{id}" % {:id => get_id(id)}
50
+ end
51
+
52
+ def batch_create_node(body)
53
+ post "/node" do
54
+ body
55
+ end
56
+ end
57
+
58
+ # NodeIndexes
59
+
60
+ def batch_create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
61
+ config = {
62
+ :type => type,
63
+ :provider => provider
64
+ }
65
+ config.merge!(extra_config) unless extra_config.nil?
66
+ post "/index/node" do
67
+ { :name => name,
68
+ :config => config
69
+ }
70
+ end
71
+ end
72
+
73
+ def batch_drop_node_index(index)
74
+ delete "/index/node/%{index}?unique" % {:index => index}
75
+ end
76
+
77
+ def batch_create_unique_node(index, key, value, properties)
78
+ post "/index/node/%{index}?unique" % {:index => index} do
79
+ {
80
+ :key => key,
81
+ :value => value,
82
+ :properties => properties
83
+ }
84
+ end
85
+ end
86
+
87
+ def batch_create_or_fail_unique_node(index, key, value, properties = {})
88
+ post "/index/node/%{index}?uniqueness=%{function}" % {:index => index, :function => 'create_or_fail'} do
89
+ {
90
+ :key => key,
91
+ :value => value,
92
+ :properties => properties
93
+ }
94
+ end
95
+ end
96
+
97
+ def batch_add_node_to_index(index, key, value, id, unique = false)
98
+ path = unique ? "/index/node/%{index}?unique" % {:index => index} : "/index/node/%{index}" % {:index => index}
99
+ post path do
100
+ {
101
+ :uri => build_node_uri(id),
102
+ :key => key,
103
+ :value => value
104
+ }
105
+ end
106
+ end
107
+
108
+ def batch_get_node_index(index, key, value)
109
+ get "/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
110
+ end
111
+
112
+ def batch_remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
113
+ delete remove_from_index_path("node", index, key_or_id, value_or_id, id)
114
+ end
115
+
116
+ # NodeProperties
117
+
118
+ def batch_set_node_property(id, property)
119
+ put "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
120
+ property.values.first
121
+ end
122
+ end
123
+
124
+ def batch_reset_node_properties(id, body)
125
+ put "/node/%{id}/properties" % {:id => get_id(id)} do
126
+ body
127
+ end
128
+ end
129
+
130
+ def batch_remove_node_property(id, property)
131
+ delete "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}
132
+ end
133
+
134
+ # NodeLabel
135
+
136
+ def batch_add_label(id, body)
137
+ post build_node_uri(id) + "/labels" do
138
+ body
139
+ end
140
+ end
141
+
142
+ # NodeRelationships
143
+
144
+ def batch_get_node_relationships(id, direction = nil, types = nil)
145
+ if types.nil?
146
+ get "/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction || 'all'}
147
+ else
148
+ get "/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => Array(types).join('&')}
149
+ end
150
+ end
151
+
152
+ # Relationships
153
+
154
+ def batch_get_relationship(id)
155
+ get "/relationship/%{id}" % {:id => get_id(id)}
156
+ end
157
+
158
+ def batch_delete_relationship(id)
159
+ delete "/relationship/%{id}" % {:id => get_id(id)}
160
+ end
161
+
162
+ def batch_create_relationship(type, from, to, data = nil)
163
+ post build_node_uri(from) + "/relationships" do
164
+ {
165
+ :to => build_node_uri(to),
166
+ :type => type,
167
+ :data => data
168
+ }
169
+ end
170
+ end
171
+
172
+ # RelationshipIndexes
173
+
174
+ def batch_create_unique_relationship(index, key, value, type, from, to, props = nil)
175
+ post "/index/relationship/%{index}?unique" % {:index => index} do
176
+ {
177
+ :key => key,
178
+ :value => value,
179
+ :type => type,
180
+ :start => build_node_uri(from),
181
+ :end => build_node_uri(to),
182
+ :properties => props
183
+ }
184
+ end
185
+ end
186
+
187
+ def batch_add_relationship_to_index(index, key, value, id)
188
+ post "/index/relationship/%{index}" % {:index => index} do
189
+ {
190
+ :uri => build_relationship_uri(id),
191
+ :key => key,
192
+ :value => value
193
+ }
194
+ end
195
+ end
196
+
197
+ def batch_get_relationship_index(index, key, value)
198
+ get "/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
199
+ end
200
+
201
+ def batch_remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
202
+ delete remove_from_index_path("relationship", index, key_or_id, value_or_id, id)
203
+ end
204
+
205
+ # RelationshipProperties
206
+
207
+ def batch_set_relationship_property(id, property)
208
+ put "/relationship/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
209
+ property.values.first
210
+ end
211
+ end
212
+
213
+ def batch_reset_relationship_properties(id, body)
214
+ put build_relationship_uri(id) + "/properties" do
215
+ body
216
+ end
217
+ end
218
+
219
+ # Cypher
220
+
221
+ def batch_execute_query(query, params = nil)
222
+ request = post @connection.cypher_path do
223
+ {
224
+ :query => query
225
+ }
226
+ end
227
+
228
+ request[:body].merge!({ :params => params }) if params
229
+
230
+ request
231
+ end
232
+
233
+ # Gremlin
234
+
235
+ def batch_execute_script(script, params = nil)
236
+ post @connection.gremlin_path do
237
+ {
238
+ :script => script,
239
+ :params => params
240
+ }
241
+ end
242
+ end
243
+
244
+ # Similar between nodes and relationships
245
+
246
+ def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil)
247
+ if id
248
+ "/index/#{klass}/%{index}/%{key}/%{value}/%{id}" % {:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id)}
249
+ elsif value_or_id
250
+ "/index/#{klass}/%{index}/%{key}/%{id}" % {:index => index, :key => key_or_id, :id => get_id(value_or_id)}
251
+ else
252
+ "/index/#{klass}/%{index}/%{id}" % {:index => index, :id => get_id(key_or_id)}
253
+ end
254
+ end
255
+
256
+ # Spatial
257
+
258
+ def batch_get_spatial
259
+ get "/ext/SpatialPlugin"
260
+ end
261
+
262
+ def batch_add_point_layer(layer, lat = nil, lon = nil)
263
+ post "/ext/SpatialPlugin/graphdb/addSimplePointLayer" do
264
+ {
265
+ :layer => layer,
266
+ :lat => lat || "lat",
267
+ :lon => lon || "lon"
268
+ }
269
+ end
270
+ end
271
+
272
+ def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
273
+ post "/ext/SpatialPlugin/graphdb/addEditableLayer" do
274
+ {
275
+ :layer => layer,
276
+ :format => format,
277
+ :nodePropertyName => node_property_name
278
+ }
279
+ end
280
+ end
281
+
282
+ def batch_get_layer(layer)
283
+ post "/ext/SpatialPlugin/graphdb/getLayer" do
284
+ {
285
+ :layer => layer
286
+ }
287
+ end
288
+ end
289
+
290
+ def batch_add_geometry_to_layer(layer, geometry)
291
+ post "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" do
292
+ {
293
+ :layer => layer,
294
+ :geometry => geometry
295
+ }
296
+ end
297
+ end
298
+
299
+ def batch_edit_geometry_from_layer(layer, geometry, node)
300
+ post "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" do
301
+ {
302
+ :layer => layer,
303
+ :geometry => geometry,
304
+ :geometryNodeId => get_id(node)
305
+ }
306
+ end
307
+ end
308
+
309
+ def batch_add_node_to_layer(layer, node)
310
+ post "/ext/SpatialPlugin/graphdb/addNodeToLayer" do
311
+ {
312
+ :layer => layer,
313
+ :node => get_id(node)
314
+ }
315
+ end
316
+ end
317
+
318
+ def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
319
+ post "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" do
320
+ {
321
+ :layer => layer,
322
+ :minx => minx,
323
+ :maxx => maxx,
324
+ :miny => miny,
325
+ :maxy => maxy
326
+ }
327
+ end
328
+ end
329
+
330
+ def batch_find_geometries_within_distance(layer, pointx, pointy, distance)
331
+ post "/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" do
332
+ {
333
+ :layer => layer,
334
+ :pointX => pointx,
335
+ :pointY => pointy,
336
+ :distanceInKm => distance
337
+ }
338
+ end
339
+ end
340
+
341
+ def batch_create_spatial_index(name, type, lat, lon)
342
+ post "/index/node" do
343
+ {
344
+ :name => name,
345
+ :config => {
346
+ :provider => "spatial",
347
+ :geometry_type => type || "point",
348
+ :lat => lat || "lat",
349
+ :lon => lon || "lon"
350
+ }
351
+ }
352
+ end
353
+ end
354
+
355
+ def batch_add_node_to_spatial_index(index, id)
356
+ post "/index/node/%{index}" % {:index => index} do
357
+ {
358
+ :uri => build_node_uri(id),
359
+ :key => "k",
360
+ :value => "v"
361
+ }
362
+ end
363
+ end
364
+
365
+ def get(to, &block)
366
+ request "GET", to, &block
367
+ end
368
+
369
+ def delete(to, &block)
370
+ request "DELETE", to, &block
371
+ end
372
+
373
+ def post(to, &block)
374
+ request "POST", to, &block
375
+ end
376
+
377
+ def put(to, &block)
378
+ request "PUT", to, &block
379
+ end
380
+
381
+ def request(method, to, &block)
382
+ request = {
383
+ :method => method,
384
+ :to => to
385
+ }
386
+ request.merge!({ :body => yield }) if block_given?
387
+ request
388
+ end
389
+
390
+ # Helper methods
391
+
392
+ def build_node_uri(value)
393
+ build_uri(value, "node")
394
+ end
395
+
396
+ def build_relationship_uri(value)
397
+ build_uri(value, "relationship")
398
+ end
399
+
400
+ def build_uri(value, type)
401
+ path_or_variable(value, type) + "#{get_id(value)}"
402
+ end
403
+
404
+ def path_or_variable(value, type)
405
+ if value.is_a?(String) && value.start_with?("{")
406
+ ""
407
+ else
408
+ "/#{type}/"
409
+ end
410
+ end
411
+
412
+ end
413
+ end
414
+ end
@@ -0,0 +1,17 @@
1
+ module Neography
2
+ class Rest
3
+ module Clean
4
+ include Neography::Rest::Helpers
5
+
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
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module Neography
2
+ class Rest
3
+ module Constraints
4
+ include Neography::Rest::Helpers
5
+
6
+ def drop_constraint(label, property)
7
+ @connection.delete("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
8
+ end
9
+
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
16
+ end
17
+
18
+ def get_uniqueness(label)
19
+ @connection.get("/schema/constraint/%{label}/uniqueness/" % {:label => label})
20
+ end
21
+
22
+ def get_unique_constraint(label, property)
23
+ @connection.get("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
24
+ end
25
+
26
+ def create_unique_constraint(label, property)
27
+ options = {
28
+ :body => {
29
+ :property_keys => [property]
30
+ }.to_json,
31
+ :headers => json_content_type
32
+ }
33
+ @connection.post("/schema/constraint/%{label}/uniqueness/" % {:label => label}, options)
34
+ end
35
+
36
+ end
37
+ end
38
+ end