neography 0.0.26 → 0.0.27
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/.travis.yml +4 -1
- data/Gemfile.lock +20 -19
- data/README.rdoc +53 -46
- data/lib/neography/config.rb +1 -1
- data/lib/neography/oj_parser.rb +8 -0
- data/lib/neography/rest.rb +43 -2
- data/lib/neography/version.rb +1 -1
- data/lib/neography.rb +3 -2
- data/neography.gemspec +2 -2
- data/spec/integration/rest_batch_spec.rb +55 -1
- data/spec/integration/rest_index_spec.rb +19 -0
- metadata +31 -31
- data/lib/neography/crack_parser.rb +0 -7
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
neography (0.0.
|
5
|
-
|
6
|
-
httparty (= 0.8.1)
|
4
|
+
neography (0.0.26)
|
5
|
+
httparty (>= 0.8.1)
|
7
6
|
json
|
7
|
+
oj
|
8
8
|
os
|
9
9
|
rake (>= 0.8.7)
|
10
10
|
rubyzip
|
@@ -12,26 +12,27 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: http://rubygems.org/
|
14
14
|
specs:
|
15
|
-
crack (0.1.8)
|
16
15
|
diff-lcs (1.1.3)
|
17
|
-
httparty (0.8.
|
18
|
-
multi_json
|
16
|
+
httparty (0.8.3)
|
17
|
+
multi_json (~> 1.0)
|
19
18
|
multi_xml
|
20
|
-
json (1.
|
21
|
-
|
22
|
-
|
19
|
+
json (1.7.3)
|
20
|
+
json (1.7.3-java)
|
21
|
+
multi_json (1.3.6)
|
22
|
+
multi_xml (0.5.1)
|
23
23
|
net-http-spy (0.2.1)
|
24
|
-
|
24
|
+
oj (1.2.9)
|
25
|
+
os (0.9.6)
|
25
26
|
rake (0.8.7)
|
26
|
-
rspec (2.
|
27
|
-
rspec-core (~> 2.
|
28
|
-
rspec-expectations (~> 2.
|
29
|
-
rspec-mocks (~> 2.
|
30
|
-
rspec-core (2.
|
31
|
-
rspec-expectations (2.
|
32
|
-
diff-lcs (~> 1.1.
|
33
|
-
rspec-mocks (2.
|
34
|
-
rubyzip (0.9.
|
27
|
+
rspec (2.10.0)
|
28
|
+
rspec-core (~> 2.10.0)
|
29
|
+
rspec-expectations (~> 2.10.0)
|
30
|
+
rspec-mocks (~> 2.10.0)
|
31
|
+
rspec-core (2.10.1)
|
32
|
+
rspec-expectations (2.10.0)
|
33
|
+
diff-lcs (~> 1.1.3)
|
34
|
+
rspec-mocks (2.10.1)
|
35
|
+
rubyzip (0.9.8)
|
35
36
|
|
36
37
|
PLATFORMS
|
37
38
|
java
|
data/README.rdoc
CHANGED
@@ -6,13 +6,15 @@ Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
|
|
6
6
|
|
7
7
|
If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge
|
8
8
|
|
9
|
+
{<img src="https://secure.travis-ci.org/maxdemarzi/neography.png?branch=master" alt="Build Status" />}[http://travis-ci.org/maxdemarzi/neography]
|
10
|
+
|
9
11
|
Complement to Neography are the:
|
10
12
|
|
11
|
-
* {Neo4j Active Record Adapter}[https://github.com/yournextleap/activerecord-neo4j-adapter] by Nikhil Lanjewar
|
13
|
+
* {Neo4j Active Record Adapter}[https://github.com/yournextleap/activerecord-neo4j-adapter] by Nikhil Lanjewar
|
12
14
|
* {Neology}[https://github.com/lordkada/neology] by Carlo Alberto Degli Atti
|
13
15
|
* {Neoid}[https://github.com/elado/neoid] by Elad Ossadon
|
14
16
|
|
15
|
-
An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz
|
17
|
+
An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz
|
16
18
|
|
17
19
|
=== Neography in the Wild
|
18
20
|
|
@@ -46,48 +48,48 @@ in order to access the functionality.
|
|
46
48
|
os
|
47
49
|
rake
|
48
50
|
json
|
49
|
-
httparty
|
51
|
+
httparty
|
50
52
|
|
51
53
|
for development:
|
52
|
-
rspec
|
53
|
-
net-http-spy
|
54
|
+
rspec
|
55
|
+
net-http-spy
|
54
56
|
|
55
57
|
==== Rails
|
56
58
|
|
57
59
|
Just add gem 'neography' to your Gemfile and run bundle install.
|
58
60
|
|
59
61
|
The following tasks will be available to you:
|
60
|
-
|
62
|
+
|
61
63
|
rake neo4j:install # Install Neo4j to the neo4j directory under your project
|
62
64
|
rake neo4j:install[community,1.6.M03] # Install Neo4j Community edition, version 1.6.M03
|
63
|
-
rake neo4j:install[advanced,1.5] # Install Neo4j Advanced edition, version 1.5
|
65
|
+
rake neo4j:install[advanced,1.5] # Install Neo4j Advanced edition, version 1.5
|
64
66
|
rake neo4j:install[enterprise,1.5] # Install Neo4j Enterprise edition, version 1.5
|
65
67
|
rake neo4j:start # Start Neo4j
|
66
68
|
rake neo4j:stop # Stop Neo4j
|
67
69
|
rake neo4j:restart # Restart Neo4j
|
68
|
-
rake neo4j:reset_yes_i_am_sure # Wipe your Neo4j Database
|
70
|
+
rake neo4j:reset_yes_i_am_sure # Wipe your Neo4j Database
|
69
71
|
|
70
72
|
Windows users will need to run in a command prompt with Administrative Privileges
|
71
|
-
in order to install Neo4j as a Service.
|
73
|
+
in order to install Neo4j as a Service.
|
72
74
|
|
73
75
|
If you are not using Rails, then add:
|
74
76
|
|
75
77
|
require 'neography/tasks'
|
76
78
|
|
77
|
-
to your Rakefile to have access to these tasks.
|
79
|
+
to your Rakefile to have access to these tasks.
|
78
80
|
|
79
81
|
rake neo4j:install requires wget to be installed. It will download and install Neo4j into a neo4j directory in your project regardless of what version you choose.
|
80
82
|
|
81
83
|
|
82
84
|
=== Documentation
|
83
85
|
|
84
|
-
@neo = Neography::Rest.new({:protocol => 'http://',
|
85
|
-
:server => 'localhost',
|
86
|
-
:port => 7474,
|
87
|
-
:directory => '', # use '/<my directory>' or leave out for default
|
88
|
-
:authentication => 'basic', # 'basic', 'digest' or leave out for default
|
89
|
-
:username => 'your username', #leave out for default
|
90
|
-
:password => 'your password', #leave out for default
|
86
|
+
@neo = Neography::Rest.new({:protocol => 'http://',
|
87
|
+
:server => 'localhost',
|
88
|
+
:port => 7474,
|
89
|
+
:directory => '', # use '/<my directory>' or leave out for default
|
90
|
+
:authentication => 'basic', # 'basic', 'digest' or leave out for default
|
91
|
+
:username => 'your username', #leave out for default
|
92
|
+
:password => 'your password', #leave out for default
|
91
93
|
:log_file => 'neography.log',
|
92
94
|
:log_enabled => false,
|
93
95
|
:max_threads => 20,
|
@@ -101,12 +103,12 @@ Quick initializer (assumes basic authorization if username is given):
|
|
101
103
|
|
102
104
|
To Use:
|
103
105
|
|
104
|
-
@neo = Neography::Rest.new # Inialize using all default parameters
|
106
|
+
@neo = Neography::Rest.new # Inialize using all default parameters
|
105
107
|
|
106
108
|
@neo.get_root # Get the root node
|
107
109
|
@neo.create_node # Create an empty node
|
108
110
|
@neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
|
109
|
-
@neo.create_unique_node(index_name, key, unique_value, # Create a unique node
|
111
|
+
@neo.create_unique_node(index_name, key, unique_value, # Create a unique node
|
110
112
|
{"age" => 31, "name" => "Max"}) # this needs an existing index
|
111
113
|
|
112
114
|
@neo.get_node(node2) # Get a node and its properties
|
@@ -122,7 +124,7 @@ To Use:
|
|
122
124
|
@neo.remove_node_properties(node1, ["weight","age"]) # Remove multiple properties of a node
|
123
125
|
|
124
126
|
@neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
|
125
|
-
@neo.create_unique_relationship(index_name, key, value, # Create a unique relationship between nodes
|
127
|
+
@neo.create_unique_relationship(index_name, key, value, # Create a unique relationship between nodes
|
126
128
|
"friends", new_node1, new_node2) # this needs an existing index
|
127
129
|
|
128
130
|
@neo.get_relationship(rel1) # Get a relationship
|
@@ -148,7 +150,9 @@ To Use:
|
|
148
150
|
@neo.remove_node_from_index(index, node1) # removes a node from the index
|
149
151
|
@neo.get_node_index(index, key, value) # exact query of the node index with the given key/value pair
|
150
152
|
@neo.find_node_index(index, key, value) # advanced query of the node index with the given key/value pair
|
151
|
-
@neo.find_node_index(index, query
|
153
|
+
@neo.find_node_index(index, query) # advanced query of the node index with the given query
|
154
|
+
@neo.get_node_auto_index(key, value) # exact query of the node auto index with the given key/value pair
|
155
|
+
@neo.find_node_auto_index(query) # advanced query of the node auto index with the given query
|
152
156
|
@neo.list_relationship_indexes # gives names and query templates for relationship indices
|
153
157
|
@neo.create_relationship_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
|
154
158
|
@neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
|
@@ -158,12 +162,14 @@ To Use:
|
|
158
162
|
@neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair
|
159
163
|
@neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair
|
160
164
|
@neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query
|
165
|
+
@neo.get_relationship_auto_index(key, value) # exact query of the relationship auto index with the given key/value pair
|
166
|
+
@neo.find_relationship_auto_index(query) # advanced query of the relationship auto index with the given query
|
161
167
|
@neo.execute_script("g.v(0)") # sends a Groovy script (through the Gremlin plugin)
|
162
168
|
@neo.execute_script("g.v(id)", {:id => 3}) # sends a parameterized Groovy script (optimized for repeated calls)
|
163
169
|
@neo.execute_query("start n=node(0) return n") # sends a Cypher query (through the Cypher plugin)
|
164
170
|
@neo.execute_query("start n=node(id) return n", {:id => 3}) # sends a parameterized Cypher query (optimized for repeated calls)
|
165
171
|
|
166
|
-
@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
|
172
|
+
@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
|
167
173
|
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
|
168
174
|
@neo.get_shortest_weighted_path(node1, node2, relationships, # find the shortest path between two nodes
|
169
175
|
weight_attr='weight', depth=2, # accounting for weight in the relationships
|
@@ -174,26 +180,26 @@ To Use:
|
|
174
180
|
{"order" => "breadth first", # "breadth first" or "depth first" traversal order
|
175
181
|
"uniqueness" => "node global", # See Uniqueness in API documentation for options.
|
176
182
|
"relationships" => [{"type"=> "roommates", # A hash containg a description of the traversal
|
177
|
-
"direction" => "all"}, # two relationships.
|
178
|
-
{"type"=> "friends", #
|
179
|
-
"direction" => "out"}], #
|
183
|
+
"direction" => "all"}, # two relationships.
|
184
|
+
{"type"=> "friends", #
|
185
|
+
"direction" => "out"}], #
|
180
186
|
"prune evaluator" => {"language" => "javascript", # A prune evaluator (when to stop traversing)
|
181
187
|
"body" => "position.endNode().getProperty('age') < 21;"},
|
182
188
|
"return filter" => {"language" => "builtin", # "all" or "all but start node"
|
183
189
|
"name" => "all"},
|
184
|
-
"depth" => 4})
|
190
|
+
"depth" => 4})
|
185
191
|
|
186
|
-
# "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
|
192
|
+
# "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
|
187
193
|
# If not specified a depth of 1 is used and if a "prune evaluator" is specified instead of a depth, no depth limit is set.
|
188
194
|
|
189
195
|
@neo.batch [:get_node, node1], [:get_node, node2] # Gets two nodes in a batch
|
190
|
-
@neo.batch [:create_node, {"name" => "Max"}],
|
196
|
+
@neo.batch [:create_node, {"name" => "Max"}],
|
191
197
|
[:create_node, {"name" => "Marc"}] # Creates two nodes in a batch
|
192
|
-
@neo.batch [:set_node_property, node1, {"name" => "Tom"}],
|
198
|
+
@neo.batch [:set_node_property, node1, {"name" => "Tom"}],
|
193
199
|
[:set_node_property, node2, {"name" => "Jerry"}] # Sets the property of two nodes
|
194
|
-
@neo.batch [:create_unique_node, index_name, key, value,
|
200
|
+
@neo.batch [:create_unique_node, index_name, key, value,
|
195
201
|
{"age" => 33, "name" => "Max"}] # Creates a unique node
|
196
|
-
@neo.batch [:get_node_relationships, node1, "out",
|
202
|
+
@neo.batch [:get_node_relationships, node1, "out",
|
197
203
|
[:get_node_relationships, node2, "out"] # Get node relationships in a batch
|
198
204
|
@neo.batch [:get_relationship, rel1],
|
199
205
|
[:get_relationship, rel2] # Gets two relationships in a batch
|
@@ -201,23 +207,24 @@ To Use:
|
|
201
207
|
node1, node2, {:since => "high school"}],
|
202
208
|
[:create_relationship, "friends",
|
203
209
|
node1, node3, {:since => "college"}] # Creates two relationships in a batch
|
204
|
-
@neo.batch [:create_unique_relationship, index_name,
|
210
|
+
@neo.batch [:create_unique_relationship, index_name,
|
205
211
|
key, value, "friends", node1, node2] # Creates a unique relationship
|
206
212
|
@neo.batch [:get_node_index, index_name, key, value] # Get node index
|
207
213
|
@neo.batch [:get_relationship_index, index_name, key, value] # Get relationship index
|
208
214
|
|
209
|
-
@neo.batch [:create_node, {"name" => "Max"}],
|
215
|
+
@neo.batch [:create_node, {"name" => "Max"}],
|
210
216
|
[:create_node, {"name" => "Marc"}], # Creates two nodes and index them
|
211
217
|
[:add_node_to_index, "test_node_index", key, value, "{0}"],
|
212
218
|
[:add_node_to_index, "test_node_index", key, value, "{1}"],
|
213
219
|
[:create_relationship, "friends", # and create a relationship for those
|
214
220
|
"{0}", "{1}", {:since => "college"}], # newly created nodes
|
215
|
-
[:add_relationship_to_index,
|
221
|
+
[:add_relationship_to_index,
|
216
222
|
"test_relationship_index", key, value, "{4}"] # and index the new relationship
|
217
223
|
|
218
|
-
@neo.batch *[[:create_node, {"name" => "Max"}],
|
224
|
+
@neo.batch *[[:create_node, {"name" => "Max"}],
|
219
225
|
[:create_node, {"name" => "Marc"}]] # Use the Splat (*) with Arrays of Arrays
|
220
226
|
|
227
|
+
|
221
228
|
See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation.
|
222
229
|
|
223
230
|
|
@@ -234,7 +241,7 @@ Experimental:
|
|
234
241
|
{"age" => 24, "name" => "Alex"}) # Create two nodes with properties threaded
|
235
242
|
nodes = @neo.get_nodes([17,86,397,33]) # Get four nodes by their id
|
236
243
|
|
237
|
-
one_set_nodes = @neo.create_nodes(3)
|
244
|
+
one_set_nodes = @neo.create_nodes(3)
|
238
245
|
another_node = @neo.create_node("age" => 31, "name" => "Max")
|
239
246
|
nodes = @neo.get_nodes([one_set_nodes, another_node]) # Get four nodes
|
240
247
|
|
@@ -272,7 +279,7 @@ The Neo4j ID is available by using node.neo_id .
|
|
272
279
|
n1.weight = 190 # Add a node property as a method
|
273
280
|
n1[:name] = nil # Delete a node property using [:key] = nil
|
274
281
|
n1.name = nil # Delete a node property by setting it to nil
|
275
|
-
|
282
|
+
|
276
283
|
n2 = Neography::Node.create
|
277
284
|
new_rel = Neography::Relationship.create(:family, n1, n2) # Create a relationship from my_node to node2
|
278
285
|
new_rel.start_node # Get the start/from node of a relationship
|
@@ -317,13 +324,13 @@ The Neo4j ID is available by using node.neo_id .
|
|
317
324
|
n1.rels(:friends).outgoing # Get outgoing friends relationships
|
318
325
|
n1.rels(:friends).incoming # Get incoming friends relationships
|
319
326
|
n1.rels(:friends,:work) # Get friends and work relationships
|
320
|
-
n1.rels(:friends,:work).outgoing # Get outgoing friends and work relationships
|
321
|
-
|
327
|
+
n1.rels(:friends,:work).outgoing # Get outgoing friends and work relationships
|
328
|
+
|
322
329
|
n1.all_paths_to(n2).incoming(:friends).depth(4) # Gets all paths of a specified type
|
323
330
|
n1.all_simple_paths_to(n2).incoming(:friends).depth(4) # for the relationships defined
|
324
|
-
n1.all_shortest_paths_to(n2).incoming(:friends).depth(4) # at a maximum depth
|
331
|
+
n1.all_shortest_paths_to(n2).incoming(:friends).depth(4) # at a maximum depth
|
325
332
|
n1.path_to(n2).incoming(:friends).depth(4) # Same as above, but just one path.
|
326
|
-
n1.simple_path_to(n2).incoming(:friends).depth(4)
|
333
|
+
n1.simple_path_to(n2).incoming(:friends).depth(4)
|
327
334
|
n1.shortest_path_to(n2).incoming(:friends).depth(4)
|
328
335
|
|
329
336
|
n1.shortest_path_to(n2).incoming(:friends).depth(4).rels # Gets just relationships in path
|
@@ -350,9 +357,9 @@ Phase 2 way of doing these:
|
|
350
357
|
|
351
358
|
=== Testing
|
352
359
|
|
353
|
-
To run testing locally you will need to have two instances of the server running. There is some
|
354
|
-
good advice on how to set up the a second instance on the
|
355
|
-
{neo4j site}[http://docs.neo4j.org/chunked/stable/server-installation.html#_multiple_server_instances_on_one_machine].
|
360
|
+
To run testing locally you will need to have two instances of the server running. There is some
|
361
|
+
good advice on how to set up the a second instance on the
|
362
|
+
{neo4j site}[http://docs.neo4j.org/chunked/stable/server-installation.html#_multiple_server_instances_on_one_machine].
|
356
363
|
Connect to the second instance in your testing environment, for example:
|
357
364
|
|
358
365
|
if Rails.env.development?
|
@@ -361,8 +368,8 @@ Connect to the second instance in your testing environment, for example:
|
|
361
368
|
@neo = Neography::Rest.new({:port => 7475})
|
362
369
|
end
|
363
370
|
|
364
|
-
Install the test-delete-db-extension plugin, as mentioned in the neo4j.org docs, if you want to use
|
365
|
-
the Rest clean_database method to empty your database between tests. In Rspec, for example,
|
371
|
+
Install the test-delete-db-extension plugin, as mentioned in the neo4j.org docs, if you want to use
|
372
|
+
the Rest clean_database method to empty your database between tests. In Rspec, for example,
|
366
373
|
put this in your spec_helper.rb:
|
367
374
|
|
368
375
|
config.before(:each) do
|
data/lib/neography/config.rb
CHANGED
data/lib/neography/rest.rb
CHANGED
@@ -291,6 +291,18 @@ module Neography
|
|
291
291
|
index
|
292
292
|
end
|
293
293
|
|
294
|
+
def get_node_auto_index(key, value)
|
295
|
+
index = get("/index/auto/node/#{key}/#{value}") || Array.new
|
296
|
+
return nil if index.empty?
|
297
|
+
index
|
298
|
+
end
|
299
|
+
|
300
|
+
def find_node_auto_index(query)
|
301
|
+
index = get("/index/auto/node/?query=#{query}") || Array.new
|
302
|
+
return nil if index.empty?
|
303
|
+
index
|
304
|
+
end
|
305
|
+
|
294
306
|
def find_node_index(*args)
|
295
307
|
case args.size
|
296
308
|
when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
|
@@ -342,6 +354,18 @@ module Neography
|
|
342
354
|
index
|
343
355
|
end
|
344
356
|
|
357
|
+
def get_relationship_auto_index(key, value)
|
358
|
+
index = get("/index/auto/relationship/#{key}/#{value}") || Array.new
|
359
|
+
return nil if index.empty?
|
360
|
+
index
|
361
|
+
end
|
362
|
+
|
363
|
+
def find_relationship_auto_index(query)
|
364
|
+
index = get("/index/auto/relationship/?query=#{query}") || Array.new
|
365
|
+
return nil if index.empty?
|
366
|
+
index
|
367
|
+
end
|
368
|
+
|
345
369
|
def traverse(id, return_type, description)
|
346
370
|
options = { :body => {"order" => get_order(description["order"]),
|
347
371
|
"uniqueness" => get_uniqueness(description["uniqueness"]),
|
@@ -368,7 +392,7 @@ module Neography
|
|
368
392
|
end
|
369
393
|
|
370
394
|
def execute_query(query, params = {})
|
371
|
-
options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} }
|
395
|
+
options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json;stream=true'} }
|
372
396
|
result = post(@cypher_path, options)
|
373
397
|
end
|
374
398
|
|
@@ -383,10 +407,19 @@ module Neography
|
|
383
407
|
Array(args).each_with_index do |c,i|
|
384
408
|
batch << {:id => i}.merge(get_batch(c))
|
385
409
|
end
|
386
|
-
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
|
410
|
+
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json;stream=true'} }
|
387
411
|
post("/batch", options)
|
388
412
|
end
|
389
413
|
|
414
|
+
def batch_not_streaming(*args)
|
415
|
+
batch = []
|
416
|
+
Array(args).each_with_index do |c,i|
|
417
|
+
batch << {:id => i}.merge(get_batch(c))
|
418
|
+
end
|
419
|
+
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
|
420
|
+
post("/batch", options)
|
421
|
+
end
|
422
|
+
|
390
423
|
# For testing (use a separate neo4j instance)
|
391
424
|
# call this before each test or spec
|
392
425
|
def clean_database(sanity_check = "not_really")
|
@@ -432,6 +465,14 @@ module Neography
|
|
432
465
|
{:method => "GET", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{args[3]}"}
|
433
466
|
when :get_node_relationships
|
434
467
|
{:method => "GET", :to => "/node/#{get_id(args[1])}/relationships/#{args[2] || 'all'}"}
|
468
|
+
when :execute_script
|
469
|
+
{:method => "POST", :to => @gremlin_path, :body => {:script => args[1], :params => args[2]}}
|
470
|
+
when :execute_query
|
471
|
+
if args[2]
|
472
|
+
{:method => "POST", :to => @cypher_path, :body => {:query => args[1], :params => args[2]}}
|
473
|
+
else
|
474
|
+
{:method => "POST", :to => @cypher_path, :body => {:query => args[1]}}
|
475
|
+
end
|
435
476
|
else
|
436
477
|
raise "Unknown option #{args[0]}"
|
437
478
|
end
|
data/lib/neography/version.rb
CHANGED
data/lib/neography.rb
CHANGED
@@ -16,15 +16,16 @@ end
|
|
16
16
|
DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]
|
17
17
|
|
18
18
|
require 'cgi'
|
19
|
-
require 'crack'
|
20
19
|
require 'httparty'
|
21
20
|
require 'json'
|
21
|
+
require 'oj'
|
22
22
|
require 'logger'
|
23
23
|
require 'ostruct'
|
24
24
|
require 'os'
|
25
25
|
require 'zip/zipfilesystem'
|
26
26
|
|
27
|
-
require 'neography/
|
27
|
+
require 'neography/oj_parser'
|
28
|
+
|
28
29
|
require 'neography/config'
|
29
30
|
require 'neography/rest'
|
30
31
|
require 'neography/neography'
|
data/neography.gemspec
CHANGED
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "rspec"
|
23
23
|
s.add_development_dependency "net-http-spy", "0.2.1"
|
24
24
|
s.add_development_dependency "rake", "~> 0.8.7"
|
25
|
-
s.add_dependency "
|
26
|
-
s.add_dependency "httparty", "0.8.1"
|
25
|
+
s.add_dependency "httparty", ">= 0.8.1"
|
27
26
|
s.add_dependency "rake", ">= 0.8.7"
|
28
27
|
s.add_dependency "json"
|
29
28
|
s.add_dependency "os"
|
30
29
|
s.add_dependency "rubyzip"
|
30
|
+
s.add_dependency "oj"
|
31
31
|
end
|
@@ -202,7 +202,6 @@ describe Neography::Rest do
|
|
202
202
|
existing_index.first["self"].should == new_node["self"]
|
203
203
|
@neo.remove_node_from_index(index_name, key, value, new_node)
|
204
204
|
end
|
205
|
-
end
|
206
205
|
|
207
206
|
it "can get a node index" do
|
208
207
|
index_name = generate_text(6)
|
@@ -235,6 +234,41 @@ describe Neography::Rest do
|
|
235
234
|
batch_result.first["body"].first["end"].split('/').last.should == node2["self"].split('/').last
|
236
235
|
end
|
237
236
|
|
237
|
+
it "can batch gremlin" do
|
238
|
+
batch_result = @neo.batch [:execute_script, "g.v(0)"]
|
239
|
+
batch_result.first.should have_key("id")
|
240
|
+
batch_result.first.should have_key("from")
|
241
|
+
batch_result.first["body"]["self"].split('/').last.should == "0"
|
242
|
+
end
|
243
|
+
|
244
|
+
it "can batch gremlin with parameters" do
|
245
|
+
new_node = @neo.create_node
|
246
|
+
id = new_node["self"].split('/').last
|
247
|
+
batch_result = @neo.batch [:execute_script, "g.v(id)", {:id => id.to_i}]
|
248
|
+
batch_result.first.should have_key("id")
|
249
|
+
batch_result.first.should have_key("from")
|
250
|
+
batch_result.first["body"]["self"].split('/').last.should == id
|
251
|
+
end
|
252
|
+
|
253
|
+
it "can batch cypher" do
|
254
|
+
batch_result = @neo.batch [:execute_query, "start n=node(0) return n"]
|
255
|
+
batch_result.first.should have_key("id")
|
256
|
+
batch_result.first.should have_key("from")
|
257
|
+
batch_result.first["body"]["data"][0][0]["self"].split('/').last.should == "0"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "can batch cypher with parameters" do
|
261
|
+
new_node = @neo.create_node
|
262
|
+
id = new_node["self"].split('/').last
|
263
|
+
batch_result = @neo.batch [:execute_query, "start n=node({id}) return n", {:id => id.to_i}]
|
264
|
+
batch_result.first.should have_key("id")
|
265
|
+
batch_result.first.should have_key("from")
|
266
|
+
batch_result.first["body"]["data"][0][0]["self"].split('/').last.should == id
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
end
|
271
|
+
|
238
272
|
describe "referenced batch" do
|
239
273
|
it "can create a relationship from two newly created nodes" do
|
240
274
|
batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}]
|
@@ -329,6 +363,26 @@ describe Neography::Rest do
|
|
329
363
|
batch_result.first["body"][1]["self"].should == new_relationship2["self"]
|
330
364
|
end
|
331
365
|
|
366
|
+
it "can create a relationship from a unique node" do
|
367
|
+
|
368
|
+
require 'net-http-spy'
|
369
|
+
Net::HTTP.http_logger_options = {:verbose => true} # see everything
|
370
|
+
|
371
|
+
batch_result = @neo.batch [:create_node, {:street1=>"94437 Kemmer Crossing", :street2=>"Apt. 333", :city=>"Abshireton", :state=>"AA", :zip=>"65820", :_type=>"Address", :created_at=>1335269478}],
|
372
|
+
[:add_node_to_index, "person_ssn", "ssn", "000-00-0001", "{0}"],
|
373
|
+
[:create_unique_node, "person", "ssn", "000-00-0001", {:first_name=>"Jane", :last_name=>"Doe", :ssn=>"000-00-0001", :_type=>"Person", :created_at=>1335269478}],
|
374
|
+
[:create_relationship, "has", "{0}", "{2}", {}]
|
375
|
+
puts batch_result.inspect
|
376
|
+
|
377
|
+
|
378
|
+
batch_result = @neo.batch [:create_unique_node, "person", "ssn", "000-00-0001", {:first_name=>"Jane", :last_name=>"Doe", :ssn=>"000-00-0001", :_type=>"Person", :created_at=>1335269478}],
|
379
|
+
[:add_node_to_index, "person_ssn", "ssn", "000-00-0001", "{0}"],
|
380
|
+
[:create_node, {:street1=>"94437 Kemmer Crossing", :street2=>"Apt. 333", :city=>"Abshireton", :state=>"AA", :zip=>"65820", :_type=>"Address", :created_at=>1335269478}],
|
381
|
+
[:create_relationship, "has", "{0}", "{2}", {}]
|
382
|
+
|
383
|
+
puts batch_result.inspect
|
384
|
+
end
|
385
|
+
|
332
386
|
end
|
333
387
|
|
334
388
|
end
|
@@ -293,5 +293,24 @@ describe Neography::Rest do
|
|
293
293
|
|
294
294
|
end
|
295
295
|
|
296
|
+
describe "auto indexes" do
|
297
|
+
|
298
|
+
it "can get a node from an automatic index" do
|
299
|
+
pending
|
300
|
+
end
|
301
|
+
|
302
|
+
it "can query a node from an automatic index" do
|
303
|
+
pending
|
304
|
+
end
|
305
|
+
|
306
|
+
it "can get a relationship from an automatic index" do
|
307
|
+
pending
|
308
|
+
end
|
309
|
+
|
310
|
+
it "can query a relationship from an automatic index" do
|
311
|
+
pending
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
296
315
|
|
297
316
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.27
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &77647920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *77647920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: net-http-spy
|
27
|
-
requirement: &
|
27
|
+
requirement: &77647650 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.2.1
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *77647650
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &77647390 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,32 +43,21 @@ dependencies:
|
|
43
43
|
version: 0.8.7
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: crack
|
49
|
-
requirement: &83773650 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - =
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.8
|
55
|
-
type: :runtime
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *83773650
|
46
|
+
version_requirements: *77647390
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: httparty
|
60
|
-
requirement: &
|
49
|
+
requirement: &77647160 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
|
-
- -
|
52
|
+
- - ! '>='
|
64
53
|
- !ruby/object:Gem::Version
|
65
54
|
version: 0.8.1
|
66
55
|
type: :runtime
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *77647160
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
59
|
name: rake
|
71
|
-
requirement: &
|
60
|
+
requirement: &77646900 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
@@ -76,10 +65,10 @@ dependencies:
|
|
76
65
|
version: 0.8.7
|
77
66
|
type: :runtime
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
68
|
+
version_requirements: *77646900
|
80
69
|
- !ruby/object:Gem::Dependency
|
81
70
|
name: json
|
82
|
-
requirement: &
|
71
|
+
requirement: &77646700 !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ! '>='
|
@@ -87,10 +76,10 @@ dependencies:
|
|
87
76
|
version: '0'
|
88
77
|
type: :runtime
|
89
78
|
prerelease: false
|
90
|
-
version_requirements: *
|
79
|
+
version_requirements: *77646700
|
91
80
|
- !ruby/object:Gem::Dependency
|
92
81
|
name: os
|
93
|
-
requirement: &
|
82
|
+
requirement: &77646470 !ruby/object:Gem::Requirement
|
94
83
|
none: false
|
95
84
|
requirements:
|
96
85
|
- - ! '>='
|
@@ -98,10 +87,21 @@ dependencies:
|
|
98
87
|
version: '0'
|
99
88
|
type: :runtime
|
100
89
|
prerelease: false
|
101
|
-
version_requirements: *
|
90
|
+
version_requirements: *77646470
|
102
91
|
- !ruby/object:Gem::Dependency
|
103
92
|
name: rubyzip
|
104
|
-
requirement: &
|
93
|
+
requirement: &77646260 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *77646260
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: oj
|
104
|
+
requirement: &77646020 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *77646020
|
113
113
|
description: A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/
|
114
114
|
for more details.
|
115
115
|
email: maxdemarzi@gmail.com
|
@@ -135,7 +135,6 @@ files:
|
|
135
135
|
- examples/traversal_example2.rb
|
136
136
|
- lib/neography.rb
|
137
137
|
- lib/neography/config.rb
|
138
|
-
- lib/neography/crack_parser.rb
|
139
138
|
- lib/neography/equal.rb
|
140
139
|
- lib/neography/index.rb
|
141
140
|
- lib/neography/neography.rb
|
@@ -143,6 +142,7 @@ files:
|
|
143
142
|
- lib/neography/node_path.rb
|
144
143
|
- lib/neography/node_relationship.rb
|
145
144
|
- lib/neography/node_traverser.rb
|
145
|
+
- lib/neography/oj_parser.rb
|
146
146
|
- lib/neography/path_traverser.rb
|
147
147
|
- lib/neography/property.rb
|
148
148
|
- lib/neography/property_container.rb
|