neography-calamitates 1.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +15 -0
  2. data/.project +12 -0
  3. data/.travis.yml +4 -0
  4. data/CONTRIBUTORS +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +19 -0
  7. data/README.md +261 -0
  8. data/Rakefile +14 -0
  9. data/examples/facebook.rb +40 -0
  10. data/examples/facebook_v2.rb +25 -0
  11. data/examples/greatest.rb +43 -0
  12. data/examples/linkedin.rb +39 -0
  13. data/examples/linkedin_v2.rb +22 -0
  14. data/examples/traversal_example1.rb +65 -0
  15. data/examples/traversal_example2.rb +54 -0
  16. data/lib/neography.rb +45 -0
  17. data/lib/neography/config.rb +52 -0
  18. data/lib/neography/connection.rb +203 -0
  19. data/lib/neography/equal.rb +21 -0
  20. data/lib/neography/errors.rb +45 -0
  21. data/lib/neography/index.rb +52 -0
  22. data/lib/neography/multi_json_parser.rb +28 -0
  23. data/lib/neography/neography.rb +10 -0
  24. data/lib/neography/node.rb +53 -0
  25. data/lib/neography/node_path.rb +29 -0
  26. data/lib/neography/node_relationship.rb +37 -0
  27. data/lib/neography/node_traverser.rb +146 -0
  28. data/lib/neography/path_traverser.rb +100 -0
  29. data/lib/neography/property.rb +61 -0
  30. data/lib/neography/property_container.rb +29 -0
  31. data/lib/neography/railtie.rb +19 -0
  32. data/lib/neography/relationship.rb +70 -0
  33. data/lib/neography/relationship_traverser.rb +80 -0
  34. data/lib/neography/rest.rb +470 -0
  35. data/lib/neography/rest/auto_indexes.rb +64 -0
  36. data/lib/neography/rest/batch.rb +277 -0
  37. data/lib/neography/rest/clean.rb +19 -0
  38. data/lib/neography/rest/cypher.rb +33 -0
  39. data/lib/neography/rest/extensions.rb +25 -0
  40. data/lib/neography/rest/gremlin.rb +24 -0
  41. data/lib/neography/rest/helpers.rb +38 -0
  42. data/lib/neography/rest/indexes.rb +100 -0
  43. data/lib/neography/rest/node_auto_indexes.rb +14 -0
  44. data/lib/neography/rest/node_indexes.rb +50 -0
  45. data/lib/neography/rest/node_labels.rb +60 -0
  46. data/lib/neography/rest/node_paths.rb +57 -0
  47. data/lib/neography/rest/node_properties.rb +11 -0
  48. data/lib/neography/rest/node_relationships.rb +42 -0
  49. data/lib/neography/rest/node_traversal.rb +81 -0
  50. data/lib/neography/rest/nodes.rb +102 -0
  51. data/lib/neography/rest/other_node_relationships.rb +48 -0
  52. data/lib/neography/rest/paths.rb +36 -0
  53. data/lib/neography/rest/properties.rb +56 -0
  54. data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
  55. data/lib/neography/rest/relationship_indexes.rb +35 -0
  56. data/lib/neography/rest/relationship_properties.rb +11 -0
  57. data/lib/neography/rest/relationship_types.rb +18 -0
  58. data/lib/neography/rest/relationships.rb +23 -0
  59. data/lib/neography/rest/schema_indexes.rb +34 -0
  60. data/lib/neography/rest/transactions.rb +102 -0
  61. data/lib/neography/tasks.rb +158 -0
  62. data/lib/neography/version.rb +3 -0
  63. data/neography.gemspec +32 -0
  64. data/spec/integration/authorization_spec.rb +48 -0
  65. data/spec/integration/index_spec.rb +70 -0
  66. data/spec/integration/neography_spec.rb +10 -0
  67. data/spec/integration/node_encoding_spec.rb +71 -0
  68. data/spec/integration/node_path_spec.rb +222 -0
  69. data/spec/integration/node_relationship_spec.rb +381 -0
  70. data/spec/integration/node_spec.rb +251 -0
  71. data/spec/integration/parsing_spec.rb +13 -0
  72. data/spec/integration/performance_spec.rb +17 -0
  73. data/spec/integration/relationship_spec.rb +37 -0
  74. data/spec/integration/rest_batch_spec.rb +512 -0
  75. data/spec/integration/rest_batch_streaming_spec.rb +32 -0
  76. data/spec/integration/rest_bulk_spec.rb +106 -0
  77. data/spec/integration/rest_experimental_spec.rb +22 -0
  78. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  79. data/spec/integration/rest_header_spec.rb +14 -0
  80. data/spec/integration/rest_index_spec.rb +468 -0
  81. data/spec/integration/rest_labels_spec.rb +128 -0
  82. data/spec/integration/rest_node_spec.rb +274 -0
  83. data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
  84. data/spec/integration/rest_path_spec.rb +231 -0
  85. data/spec/integration/rest_plugin_spec.rb +177 -0
  86. data/spec/integration/rest_relationship_spec.rb +354 -0
  87. data/spec/integration/rest_relationship_types_spec.rb +18 -0
  88. data/spec/integration/rest_schema_index_spec.rb +32 -0
  89. data/spec/integration/rest_transaction_spec.rb +166 -0
  90. data/spec/integration/rest_traverse_spec.rb +149 -0
  91. data/spec/matchers.rb +33 -0
  92. data/spec/neography_spec.rb +23 -0
  93. data/spec/spec_helper.rb +45 -0
  94. data/spec/unit/config_spec.rb +46 -0
  95. data/spec/unit/connection_spec.rb +211 -0
  96. data/spec/unit/node_spec.rb +100 -0
  97. data/spec/unit/properties_spec.rb +140 -0
  98. data/spec/unit/relationship_spec.rb +118 -0
  99. data/spec/unit/rest/batch_spec.rb +243 -0
  100. data/spec/unit/rest/clean_spec.rb +17 -0
  101. data/spec/unit/rest/cypher_spec.rb +21 -0
  102. data/spec/unit/rest/extensions_spec.rb +29 -0
  103. data/spec/unit/rest/gremlin_spec.rb +26 -0
  104. data/spec/unit/rest/labels_spec.rb +73 -0
  105. data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
  106. data/spec/unit/rest/node_indexes_spec.rb +141 -0
  107. data/spec/unit/rest/node_paths_spec.rb +80 -0
  108. data/spec/unit/rest/node_properties_spec.rb +80 -0
  109. data/spec/unit/rest/node_relationships_spec.rb +78 -0
  110. data/spec/unit/rest/node_traversal_spec.rb +128 -0
  111. data/spec/unit/rest/nodes_spec.rb +188 -0
  112. data/spec/unit/rest/paths_spec.rb +69 -0
  113. data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
  114. data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
  115. data/spec/unit/rest/relationship_properties_spec.rb +80 -0
  116. data/spec/unit/rest/relationship_types_spec.rb +16 -0
  117. data/spec/unit/rest/relationships_spec.rb +22 -0
  118. data/spec/unit/rest/schema_index_spec.rb +31 -0
  119. data/spec/unit/rest/transactions_spec.rb +44 -0
  120. metadata +372 -0
@@ -0,0 +1,38 @@
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
+ def parse_direction(direction)
25
+ case direction
26
+ when :incoming, "incoming", :in, "in"
27
+ "in"
28
+ when :outgoing, "outgoing", :out, "out"
29
+ "out"
30
+ else
31
+ "all"
32
+ end
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,100 @@
1
+ module Neography
2
+ class Rest
3
+ class Indexes
4
+ include Neography::Rest::Helpers
5
+
6
+ def initialize(connection, index_type)
7
+ @connection = connection
8
+ @index_type = index_type
9
+ end
10
+
11
+ def list
12
+ @connection.get(all_path)
13
+ end
14
+
15
+ def create(name, type = "exact", provider = "lucene")
16
+ options = {
17
+ :body => (
18
+ { :name => name,
19
+ :config => {
20
+ :type => type,
21
+ :provider => provider
22
+ }
23
+ }
24
+ ).to_json,
25
+ :headers => json_content_type
26
+ }
27
+ @connection.post(all_path, options)
28
+ end
29
+
30
+ def create_auto(type = "exact", provider = "lucene")
31
+ create("#{@index_type}_auto_index", type, provider)
32
+ end
33
+
34
+ def add(index, key, value, id, unique = false)
35
+ options = {
36
+ :body => (
37
+ { :uri => @connection.configuration + "/#{@index_type}/#{get_id(id)}",
38
+ :key => key,
39
+ :value => value
40
+ }
41
+ ).to_json,
42
+ :headers => json_content_type
43
+ }
44
+ path = unique ? unique_path(:index => index) : base_path(:index => index)
45
+ @connection.post(path, options)
46
+ end
47
+
48
+ def get(index, key, value)
49
+ index = @connection.get(key_value_path(:index => index, :key => key, :value => value)) || []
50
+ return nil if index.empty?
51
+ index
52
+ end
53
+
54
+ def find(index, key_or_query, value = nil)
55
+ if value
56
+ index = find_by_key_value(index, key_or_query, value)
57
+ else
58
+ index = find_by_query(index, key_or_query)
59
+ end
60
+ return nil if index.empty?
61
+ index
62
+ end
63
+
64
+ def find_by_key_value(index, key, value)
65
+ @connection.get(key_value_path(:index => index, :key => key, :value => value)) || []
66
+ end
67
+
68
+ def find_by_query(index, query)
69
+ @connection.get(query_path(:index => index, :query => query)) || []
70
+ end
71
+
72
+ # Mimick original neography API in Rest class.
73
+ def remove(index, id_or_key, id_or_value = nil, id = nil)
74
+ if id
75
+ remove_by_value(index, id, id_or_key, id_or_value)
76
+ elsif id_or_value
77
+ remove_by_key(index, id_or_value, id_or_key)
78
+ else
79
+ remove_by_id(index, id_or_key)
80
+ end
81
+ end
82
+
83
+ def remove_by_id(index, id)
84
+ @connection.delete(id_path(:index => index, :id => get_id(id)))
85
+ end
86
+
87
+ def remove_by_key(index, id, key)
88
+ @connection.delete(key_path(:index => index, :id => get_id(id), :key => key))
89
+ end
90
+
91
+ def remove_by_value(index, id, key, value)
92
+ @connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value))
93
+ end
94
+
95
+ def drop(index)
96
+ @connection.delete(base_path(:index => index))
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,14 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeAutoIndexes < AutoIndexes
4
+ extend Neography::Rest::Paths
5
+
6
+ add_path :key_value, "/index/auto/node/:key/:value"
7
+ add_path :query_index, "/index/auto/node/?query=:query"
8
+ add_path :index_status, "/index/auto/node/status"
9
+ add_path :index_properties, "/index/auto/node/properties"
10
+ add_path :index_property, "/index/auto/node/properties/:property"
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeIndexes < Indexes
4
+ extend Neography::Rest::Paths
5
+ include Neography::Rest::Helpers
6
+
7
+ add_path :all, "/index/node"
8
+ add_path :base, "/index/node/:index"
9
+ add_path :unique, "/index/node/:index?unique"
10
+ add_path :uniqueness, "/index/node/:index?uniqueness=:function"
11
+ add_path :id, "/index/node/:index/:id"
12
+ add_path :key, "/index/node/:index/:key/:id"
13
+ add_path :value, "/index/node/:index/:key/:value/:id"
14
+ add_path :key_value, "/index/node/:index/:key/:value"
15
+ add_path :query, "/index/node/:index?query=:query"
16
+
17
+ def initialize(connection)
18
+ super(connection, :node)
19
+ end
20
+
21
+ def create_unique(index, key, value, properties = {})
22
+ options = {
23
+ :body => (
24
+ { :properties => properties,
25
+ :key => key,
26
+ :value => value
27
+ }
28
+ ).to_json,
29
+ :headers => json_content_type
30
+ }
31
+ @connection.post(unique_path(:index => index), options)
32
+ end
33
+
34
+ def get_or_create_unique(index, key, value, properties = {})
35
+ options = {
36
+ :body => (
37
+ { :properties => properties,
38
+ :key => key,
39
+ :value => value
40
+ }
41
+ ).to_json,
42
+ :headers => json_content_type
43
+ }
44
+ @connection.post(uniqueness_path(:index => index, :function => 'get_or_create'), options)
45
+
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,60 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeLabels
4
+ extend Neography::Rest::Paths
5
+ include Neography::Rest::Helpers
6
+
7
+ add_path :base, "/labels"
8
+ add_path :node, "/node/:id/labels"
9
+ add_path :nodes, "/label/:label/nodes"
10
+ add_path :find, "/label/:label/nodes?:property=%22:value%22"
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)
19
+ end
20
+
21
+ def get(id)
22
+ @connection.get(node_path(:id => get_id(id)))
23
+ end
24
+
25
+ def get_nodes(label)
26
+ @connection.get(nodes_path(:label => label))
27
+ end
28
+
29
+ def find_nodes(label, hash)
30
+ @connection.get(find_path(:label => label, :property => hash.keys.first, :value => hash.values.first))
31
+ end
32
+
33
+ def add(id, label)
34
+ options = {
35
+ :body => (
36
+ label
37
+ ).to_json,
38
+ :headers => json_content_type
39
+ }
40
+ @connection.post(node_path(:id => get_id(id)), options)
41
+ end
42
+
43
+ def set(id, label)
44
+ options = {
45
+ :body => (
46
+ Array(label)
47
+ ).to_json,
48
+ :headers => json_content_type
49
+ }
50
+ @connection.put(node_path(:id => get_id(id)), options)
51
+ end
52
+
53
+ def delete(id, label)
54
+ @connection.delete(delete_path(:id => get_id(id), :label => label))
55
+ end
56
+
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ module Neography
2
+ class Rest
3
+ class NodePaths
4
+ extend Neography::Rest::Paths
5
+ include Neography::Rest::Helpers
6
+
7
+ add_path :base, "/node/:id/path"
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")
15
+ options = path_options(to, relationships, depth, algorithm)
16
+ @connection.post(base_path(:id => get_id(from)), options) || {}
17
+ end
18
+
19
+ def get_all(from, to, relationships, depth = 1, algorithm = "allPaths")
20
+ options = path_options(to, relationships, depth, algorithm)
21
+ @connection.post(all_path(:id => get_id(from)), options) || []
22
+ end
23
+
24
+ def shortest_weighted(from, to, relationships, weight_attribute = "weight", depth = 1, algorithm = "dijkstra")
25
+ options = path_options(to, relationships, depth, algorithm, { :cost_property => weight_attribute })
26
+ @connection.post(all_path(:id => get_id(from)), options) || {}
27
+ end
28
+
29
+ private
30
+
31
+ def get_algorithm(algorithm)
32
+ case algorithm
33
+ when :shortest, "shortest", :shortestPath, "shortestPath", :short, "short"
34
+ "shortestPath"
35
+ when :allSimplePaths, "allSimplePaths", :simple, "simple"
36
+ "allSimplePaths"
37
+ when :dijkstra, "dijkstra"
38
+ "dijkstra"
39
+ else
40
+ "allPaths"
41
+ end
42
+ end
43
+
44
+ def path_options(to, relationships, depth, algorithm, extra_body = {})
45
+ options = { :body => {
46
+ "to" => @connection.configuration + "/node/#{get_id(to)}",
47
+ "relationships" => relationships,
48
+ "max_depth" => depth,
49
+ "algorithm" => get_algorithm(algorithm)
50
+ }.merge(extra_body).to_json,
51
+ :headers => json_content_type
52
+ }
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeProperties < Properties
4
+ extend Neography::Rest::Paths
5
+
6
+ add_path :all, "/node/:id/properties"
7
+ add_path :single, "/node/:id/properties/:property"
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeRelationships
4
+ extend Neography::Rest::Paths
5
+ 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)
16
+ options = {
17
+ :body => {
18
+ :to => @connection.configuration + "/node/#{get_id(to)}",
19
+ :data => properties,
20
+ :type => type
21
+ }.to_json,
22
+ :headers => json_content_type }
23
+
24
+ @connection.post(base_path(:id => get_id(from)), options)
25
+ end
26
+
27
+ def get(id, direction = nil, types = nil)
28
+ direction = parse_direction(direction)
29
+
30
+ if types.nil?
31
+ node_relationships = @connection.get(direction_path(:id => get_id(id), :direction => direction)) || []
32
+ else
33
+ node_relationships = @connection.get(type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || []
34
+ end
35
+
36
+ return nil if node_relationships.empty?
37
+ node_relationships
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,81 @@
1
+ module Neography
2
+ class Rest
3
+ class NodeTraversal
4
+ extend Neography::Rest::Paths
5
+ include Neography::Rest::Helpers
6
+
7
+ add_path :traversal, "/node/:id/traverse/:type"
8
+
9
+ def initialize(connection)
10
+ @connection = connection
11
+ end
12
+
13
+ def traverse(id, return_type, description)
14
+ options = { :body => {
15
+ "order" => get_order(description["order"]),
16
+ "uniqueness" => get_uniqueness(description["uniqueness"]),
17
+ "relationships" => description["relationships"],
18
+ "prune_evaluator" => description["prune evaluator"],
19
+ "return_filter" => description["return filter"],
20
+ "max_depth" => get_depth(description["depth"])
21
+ }.to_json,
22
+ :headers => json_content_type
23
+ }
24
+
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
65
+
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
77
+ end
78
+
79
+ end
80
+ end
81
+ end