diff --git a/README.rdoc b/README.rdoc index 6d5459d..cf598a1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -61,6 +61,11 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and Neography::Rest.remove_relationship_properties(id, "since") # Remove one property of a relationship Neography::Rest.remove_relationship_properties(id, ["since","met"]) # Remove multiple properties of a relationship + Neography::Rest.list_indexes # doesn't really seam to do what the api says it does + Neography::Rest.add_to_index(key, value, id) # adds a node to an index with the given key/value pair + Neography::Rest.remove_from_index(key, value, id) # removes a node to an index with the given key/value pair + Neography::Rest.get_index(key, value) # gets an index with the given key/value pair + ... and a work in progress more rubyish layer that's not quite ready for use yet. Neography::Node.new # Create an empty node @@ -72,8 +77,8 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and Neography::Node.del(3) # Deletes a node without any relationships Neography::Node.del!(3) # Deletes a node and all its relationships - === License + * Neography - MIT, see the LICENSE file http://github.com/maxdemarzi/neography/tree/master/LICENSE. * Lucene - Apache, see http://lucene.apache.org/java/docs/features.html * Neo4j - Dual free software/commercial license, see http://neo4j.org/ diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index edb70a4..ed2458b 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -133,6 +133,25 @@ def delete_node!(id) rescue_ij { delete("/node/#{id}") } end + def list_indexes + rescue_ij { get("/index") } + end + + def add_to_index(key, value, id) + options = { :body => (Neography::Config.to_s + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} } + rescue_ij { post("/index/node/#{key}/#{value}", options) } + end + + def remove_from_index(key, value, id) + rescue_ij { delete("/index/node/#{key}/#{value}/#{id}") } + end + + def get_index(key, value) + index = rescue_ij { get("/index/node/#{key}/#{value}") } || Array.new + return nil if index.empty? + index + end + private # Rescue from Invalid JSON error thrown by Crack Gem diff --git a/spec/integration/rest_spec.rb b/spec/integration/rest_spec.rb index c58790a..f987d3f 100644 --- a/spec/integration/rest_spec.rb +++ b/spec/integration/rest_spec.rb @@ -599,4 +599,52 @@ end end + describe "list indexes" do + it "can get a listing of indexes" do + Neography::Rest.list_indexes.should_not be_nil + end + end + + describe "add to index" do + it "can add a node to an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + end + end + + describe "remove from index" do + it "can remove a node from an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should be_nil + end + end + + describe "get index" do + it "can get an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + end + end + + end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d63b985..531b33d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,3 +11,9 @@ FakeWeb.clean_registry FakeWeb.allow_net_connect = true +def generate_text(length=8) + chars = 'abcdefghjkmnpqrstuvwxyz' + key = '' + length.times { |i| key << chars[rand(chars.length)] } + key +end \ No newline at end of file