neography 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neography (0.0.10)
4
+ neography (0.0.11)
5
5
  httparty (~> 0.7.3)
6
6
  json
7
7
 
@@ -16,6 +16,7 @@ GEM
16
16
  json (1.4.6)
17
17
  json (1.4.6-java)
18
18
  net-http-spy (0.2.1)
19
+ rake (0.8.7)
19
20
  rspec (2.0.1)
20
21
  rspec-core (~> 2.0.1)
21
22
  rspec-expectations (~> 2.0.1)
@@ -37,4 +38,5 @@ DEPENDENCIES
37
38
  json
38
39
  neography!
39
40
  net-http-spy (~> 0.2.1)
41
+ rake (~> 0.8.7)
40
42
  rspec (~> 2.0.0.beta.22)
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ in order to access the functionality.
19
19
 
20
20
  === Try it now!
21
21
 
22
- I am hosting an instance of Neo4j (1.2) at neography.org for you to try out.
22
+ I am hosting an instance of Neo4j (1.3M04) at neography.org for you to try out.
23
23
 
24
24
  You can see the administration at: {Neo4j Web Admin}[http://neography.org]
25
25
 
@@ -99,12 +99,18 @@ To Use:
99
99
  @neo.create_node_index(name, type, provider) # creates an index, defaults are "exact" and "lucene"
100
100
  @neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair
101
101
  @neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair
102
- @neo.get_node_index(index, key, value) # queries the index with the given key/value pair
102
+ @neo.remove_node_from_index(index, key, node1) # removes a node from the index with the given key
103
+ @neo.remove_node_from_index(index, node1) # removes a node from the index
104
+ @neo.get_node_index(index, key, value) # exact query of the node index with the given key/value pair
105
+ @neo.find_node_index(index, key, value) # advanced query of the node index with the given key/value pair
103
106
  @neo.list_relationship_indexes # gives names and query templates for relationship indices
104
- @neo.create_relationshp_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
107
+ @neo.create_relationship_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
105
108
  @neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
106
109
  @neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair
107
- @neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair
110
+ @neo.remove_relationship_from_index(index, key, rel1) # removes a relationship from the index with the given key
111
+ @neo.remove_relationship_from_index(index, rel1) # removes a relationship from the index
112
+ @neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair
113
+ @neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair
108
114
 
109
115
 
110
116
  @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = "--color"
8
+ t.pattern = "spec/integration/*_spec.rb"
9
+ end
10
+
11
+ task :default => :spec
@@ -248,8 +248,12 @@ module Neography
248
248
  post("/index/node/#{index}/#{key}/#{value}", options)
249
249
  end
250
250
 
251
- def remove_node_from_index(index, key, value, id)
252
- delete("/index/node/#{index}/#{key}/#{value}/#{get_id(id)}")
251
+ def remove_node_from_index(*args)
252
+ case args.size
253
+ when 4 then delete("/index/node/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
254
+ when 3 then delete("/index/node/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
255
+ when 2 then delete("/index/node/#{args[0]}/#{get_id(args[1])}")
256
+ end
253
257
  end
254
258
 
255
259
  def get_node_index(index, key, value)
@@ -258,6 +262,12 @@ module Neography
258
262
  index
259
263
  end
260
264
 
265
+ def find_node_index(index, key, value)
266
+ index = get("/index/node/#{index}/#{key}?query=#{value}") || Array.new
267
+ return nil if index.empty?
268
+ index
269
+ end
270
+
261
271
  alias_method :list_indexes, :list_node_indexes
262
272
  alias_method :add_to_index, :add_node_to_index
263
273
  alias_method :remove_from_index, :remove_node_from_index
@@ -277,8 +287,12 @@ module Neography
277
287
  post("/index/relationship/#{index}/#{key}/#{value}", options)
278
288
  end
279
289
 
280
- def remove_relationship_from_index(index, key, value, id)
281
- delete("/index/relationship/#{index}/#{key}/#{value}/#{get_id(id)}")
290
+ def remove_relationship_from_index(*args)
291
+ case args.size
292
+ when 4 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
293
+ when 3 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
294
+ when 2 then delete("/index/relationship/#{args[0]}/#{get_id(args[1])}")
295
+ end
282
296
  end
283
297
 
284
298
  def get_relationship_index(index, key, value)
@@ -286,6 +300,13 @@ module Neography
286
300
  return nil if index.empty?
287
301
  index
288
302
  end
303
+
304
+ def find_relationship_index(index, key, value)
305
+ index = get("/index/relationship/#{index}/#{key}?query=#{value}") || Array.new
306
+ return nil if index.empty?
307
+ index
308
+ end
309
+
289
310
  def traverse(id, return_type, description)
290
311
  options = { :body => {"order" => get_order(description["order"]),
291
312
  "uniqueness" => get_uniqueness(description["uniqueness"]),
@@ -335,19 +356,19 @@ module Neography
335
356
  end
336
357
 
337
358
  def get(path,options={})
338
- evaluate_response(HTTParty.get(configuration + path, options.merge!(@authentication)))
359
+ evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication)))
339
360
  end
340
361
 
341
362
  def post(path,options={})
342
- evaluate_response(HTTParty.post(configuration + path, options.merge!(@authentication)))
363
+ evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication)))
343
364
  end
344
365
 
345
366
  def put(path,options={})
346
- evaluate_response(HTTParty.put(configuration + path, options.merge!(@authentication)))
367
+ evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication)))
347
368
  end
348
369
 
349
370
  def delete(path,options={})
350
- evaluate_response(HTTParty.delete(configuration + path, options.merge!(@authentication)))
371
+ evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication)))
351
372
  end
352
373
 
353
374
  def get_id(id)
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/neography.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
23
23
  s.add_development_dependency "net-http-spy", "~> 0.2.1"
24
24
  s.add_development_dependency "fakeweb", "~> 1.3.0"
25
+ s.add_development_dependency "rake", "~> 0.8.7"
25
26
  s.add_dependency "httparty", "~> 0.7.3"
26
27
  s.add_dependency "json"
27
28
  end
@@ -1,9 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe Neography::Rest do
4
- describe "basic authentication" do
3
+ describe Neography::Rest, :slow => true do
4
+ describe "basic authentication" do
5
5
  describe "get_root" do
6
- it "can get the root node" do
6
+ it "can get the root node"do
7
7
  @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
8
8
  root_node = @neo.get_root
9
9
  root_node.should have_key("reference_node")
@@ -18,7 +18,7 @@ describe Neography::Rest do
18
18
  end
19
19
  end
20
20
 
21
- describe "quick initalizer" do
21
+ describe "quick initializer" do
22
22
  it "can get the root node" do
23
23
  @neo = Neography::Rest.new("http://abbe3c012:34d7b22eb@4c36b641.neo4j.atns.de:7474/9dc1fda5be8b5cde29621e21cae5adece3de0f37")
24
24
  root_node = @neo.get_root
@@ -27,7 +27,7 @@ describe Neography::Rest do
27
27
  end
28
28
  end
29
29
 
30
- describe "digest authentication" do
30
+ describe "digest authentication" do
31
31
  describe "get_root" do
32
32
  it "can get the root node" do
33
33
  @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
@@ -12,7 +12,7 @@ describe Neography::Rest do
12
12
  new_nodes.size.should == 2
13
13
  end
14
14
 
15
- it "is faster than non-threaded?" do
15
+ it "is faster than non-threaded?" , :slow => true do
16
16
  Benchmark.bm do |x|
17
17
  x.report("create 500 nodes ") { @not_threaded = @neo.create_nodes(500) }
18
18
  x.report("create 500 nodes threaded") { @threaded = @neo.create_nodes_threaded(500) }
@@ -61,7 +61,7 @@ describe Neography::Rest do
61
61
  new_nodes[1]["data"]["weight"].should == 215
62
62
  end
63
63
 
64
- it "is not super slow?" do
64
+ it "is not super slow?" , :slow => true do
65
65
  Benchmark.bm do |x|
66
66
  x.report( "create 1 node" ) { @neo.create_nodes( 1) }
67
67
  x.report( "create 10 nodes") { @neo.create_nodes( 10) }
@@ -89,7 +89,7 @@ describe Neography::Rest do
89
89
  existing_nodes[1]["self"] == new_node2["self"]
90
90
  end
91
91
 
92
- it "is not super slow?" do
92
+ it "is not super slow?" , :slow => true do
93
93
  one_node = @neo.create_nodes( 1)
94
94
  ten_nodes = @neo.create_nodes( 10)
95
95
  one_hundred_nodes = @neo.create_nodes(100)
@@ -6,11 +6,10 @@ describe Neography::Rest do
6
6
  end
7
7
 
8
8
 
9
- describe "get_nodes" do
9
+ describe "get_nodes", :slow => true do
10
10
  it "can get nodes that exists" do
11
11
  existing_nodes = @neo.get_nodes
12
12
  existing_nodes.should_not be_nil
13
- puts existing_nodes.inspect
14
13
  end
15
14
 
16
15
  it "can get all nodes that exists the ugly way" do
@@ -102,7 +102,31 @@ describe Neography::Rest do
102
102
  new_index.should be_nil
103
103
  end
104
104
 
105
- it "can remove a relationshp from an index" do
105
+ it "can remove a node from an index without supplying value" do
106
+ new_node = @neo.create_node
107
+ key = generate_text(6)
108
+ value = generate_text
109
+ @neo.add_node_to_index("test_index", key, value, new_node)
110
+ new_index = @neo.get_node_index("test_index", key, value)
111
+ new_index.should_not be_nil
112
+ @neo.remove_node_from_index("test_index", key, new_node)
113
+ new_index = @neo.get_node_index("test_index", key, value)
114
+ new_index.should be_nil
115
+ end
116
+
117
+ it "can remove a node from an index without supplying key nor value" do
118
+ new_node = @neo.create_node
119
+ key = generate_text(6)
120
+ value = generate_text
121
+ @neo.add_node_to_index("test_index", key, value, new_node)
122
+ new_index = @neo.get_node_index("test_index", key, value)
123
+ new_index.should_not be_nil
124
+ @neo.remove_node_from_index("test_index", new_node)
125
+ new_index = @neo.get_node_index("test_index", key, value)
126
+ new_index.should be_nil
127
+ end
128
+
129
+ it "can remove a relationship from an index" do
106
130
  new_node1 = @neo.create_node
107
131
  new_node2 = @neo.create_node
108
132
  new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
@@ -115,6 +139,34 @@ describe Neography::Rest do
115
139
  new_index = @neo.get_relationship_index("test_index", key, value)
116
140
  new_index.should be_nil
117
141
  end
142
+
143
+ it "can remove a relationship from an index without supplying value" do
144
+ new_node1 = @neo.create_node
145
+ new_node2 = @neo.create_node
146
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
147
+ key = generate_text(6)
148
+ value = generate_text
149
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
150
+ new_index = @neo.get_relationship_index("test_index", key, value)
151
+ new_index.should_not be_nil
152
+ @neo.remove_relationship_from_index("test_index", key, new_relationship)
153
+ new_index = @neo.get_relationship_index("test_index", key, value)
154
+ new_index.should be_nil
155
+ end
156
+
157
+ it "can remove a relationship from an index without supplying key nor value" do
158
+ new_node1 = @neo.create_node
159
+ new_node2 = @neo.create_node
160
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
161
+ key = generate_text(6)
162
+ value = generate_text
163
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
164
+ new_index = @neo.get_relationship_index("test_index", key, value)
165
+ new_index.should_not be_nil
166
+ @neo.remove_relationship_from_index("test_index", new_relationship)
167
+ new_index = @neo.get_relationship_index("test_index", key, value)
168
+ new_index.should be_nil
169
+ end
118
170
  end
119
171
 
120
172
  describe "get index" do
@@ -152,6 +204,16 @@ describe Neography::Rest do
152
204
  @neo.remove_node_from_index("test_index", key, value, new_node)
153
205
  end
154
206
 
207
+ it "can find a node index" do
208
+ new_node = @neo.create_node
209
+ key = generate_text(6)
210
+ value = generate_text
211
+ @neo.add_node_to_index("test_index", key, value, new_node)
212
+ new_index = @neo.find_node_index("test_index", key, value)
213
+ new_index.first["self"].should == new_node["self"]
214
+ @neo.remove_node_from_index("test_index", key, value, new_node)
215
+ end
216
+
155
217
  it "can get a relationship index" do
156
218
  new_node1 = @neo.create_node
157
219
  new_node2 = @neo.create_node
@@ -163,6 +225,31 @@ describe Neography::Rest do
163
225
  new_index.first["self"].should == new_relationship["self"]
164
226
  @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
165
227
  end
228
+
229
+ it "can get a relationship index with empty spaces" do
230
+ new_node1 = @neo.create_node
231
+ new_node2 = @neo.create_node
232
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
233
+ key = generate_text(6)
234
+ value = generate_text + " " + generate_text
235
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
236
+ new_index = @neo.get_relationship_index("test_index", key, value)
237
+ new_index.first["self"].should == new_relationship["self"]
238
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
239
+ end
240
+
241
+ it "can find a relationship index" do
242
+ new_node1 = @neo.create_node
243
+ new_node2 = @neo.create_node
244
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
245
+ key = generate_text(6)
246
+ value = generate_text
247
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
248
+ new_index = @neo.find_relationship_index("test_index", key, value)
249
+ new_index.first["self"].should == new_relationship["self"]
250
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
251
+ end
252
+
166
253
  end
167
254
 
168
255
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'neography'
2
- require 'fakeweb'
2
+ require 'fake_web'
3
3
  require 'benchmark'
4
4
 
5
5
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -22,4 +22,8 @@ def generate_text(length=8)
22
22
  key = ''
23
23
  length.times { |i| key << chars[rand(chars.length)] }
24
24
  key
25
+ end
26
+
27
+ RSpec.configure do |c|
28
+ c.filter_run_excluding :slow => true
25
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Max De Marzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-23 00:00:00 -08:00
18
+ date: 2011-03-11 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -69,9 +69,25 @@ dependencies:
69
69
  type: :development
70
70
  version_requirements: *id003
71
71
  - !ruby/object:Gem::Dependency
72
- name: httparty
72
+ name: rake
73
73
  prerelease: false
74
74
  requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 49
80
+ segments:
81
+ - 0
82
+ - 8
83
+ - 7
84
+ version: 0.8.7
85
+ type: :development
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: httparty
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
75
91
  none: false
76
92
  requirements:
77
93
  - - ~>
@@ -83,11 +99,11 @@ dependencies:
83
99
  - 3
84
100
  version: 0.7.3
85
101
  type: :runtime
86
- version_requirements: *id004
102
+ version_requirements: *id005
87
103
  - !ruby/object:Gem::Dependency
88
104
  name: json
89
105
  prerelease: false
90
- requirement: &id005 !ruby/object:Gem::Requirement
106
+ requirement: &id006 !ruby/object:Gem::Requirement
91
107
  none: false
92
108
  requirements:
93
109
  - - ">="
@@ -97,7 +113,7 @@ dependencies:
97
113
  - 0
98
114
  version: "0"
99
115
  type: :runtime
100
- version_requirements: *id005
116
+ version_requirements: *id006
101
117
  description: A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/ for more details.
102
118
  email: maxdemarzi@gmail.com
103
119
  executables: []