diff --git a/Gemfile.lock b/Gemfile.lock index 222e499..26600af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neography (0.0.7) + neography (0.0.9) httparty (~> 0.7.3) json diff --git a/README.rdoc b/README.rdoc index 1407560..6e71698 100644 --- a/README.rdoc +++ b/README.rdoc @@ -92,10 +92,15 @@ To Use: @neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship @neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship - @neo.list_indexes # gives names and query templates for all defined indices - @neo.add_to_index(index, key, value, node1) # adds a node to the specified index with the given key/value pair - @neo.remove_from_index(index, key, value, node1) # removes a node from the specified index with the given key/value pair - @neo.get_index(index, key, value) # queries the specified index with the given key/value pair + @neo.list_node_indexes # gives names and query templates for all defined indices + @neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair + @neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair + @neo.get_node_index(index, key, value) # queries the index with the given key/value pair + @neo.list_relationship_indexes # gives names and query templates for relationship indices + @neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair + @neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair + @neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair + @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes @neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 941472e..801579a 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -219,25 +219,48 @@ def delete_node!(id) delete("/node/#{get_id(id)}") end - def list_indexes + def list_node_indexes get("/index/node") end - def add_to_index(index, key, value, id) + def add_node_to_index(index, key, value, id) options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} } post("/index/node/#{index}/#{key}/#{value}", options) end - def remove_from_index(index, key, value, id) + def remove_node_from_index(index, key, value, id) delete("/index/node/#{index}/#{key}/#{value}/#{get_id(id)}") end - def get_index(index, key, value) + def get_node_index(index, key, value) index = get("/index/node/#{index}/#{key}/#{value}") || Array.new return nil if index.empty? index end + alias_method :list_indexes, :list_node_indexes + alias_method :add_to_index, :add_node_to_index + alias_method :remove_from_index, :remove_node_from_index + alias_method :get_index, :get_node_index + + def list_relationship_indexes + get("/index/relationship") + end + + def add_relationship_to_index(index, key, value, id) + options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} } + post("/index/relationship/#{index}/#{key}/#{value}", options) + end + + def remove_relationship_from_index(index, key, value, id) + delete("/index/relationship/#{index}/#{key}/#{value}/#{get_id(id)}") + end + + def get_relationship_index(index, key, value) + index = get("/index/relationship/#{index}/#{key}/#{value}") || Array.new + return nil if index.empty? + index + end def traverse(id, return_type, description) options = { :body => {"order" => get_order(description["order"]), "uniqueness" => get_uniqueness(description["uniqueness"]), diff --git a/spec/integration/heroku_spec.rb b/spec/integration/authorization_spec.rb similarity index 100% rename from spec/integration/heroku_spec.rb rename to spec/integration/authorization_spec.rb diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 6193ba6..ec368cc 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -6,13 +6,23 @@ end describe "list indexes" do - it "can get a listing of indexes" do + it "can get a listing of node indexes" do new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index("test_index", key, value, new_node) + @neo.add_node_to_index("test_index", key, value, new_node) @neo.list_indexes.should_not be_nil end + + it "can get a listing of relationship indexes" do + new_node1 = @neo.create_node + new_node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + key = generate_text(6) + value = generate_text + @neo.add_relationship_to_index("test_index", key, value, new_relationship) + @neo.list_relationship_indexes.should_not be_nil + end end describe "add to index" do @@ -20,10 +30,22 @@ new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index("test_index", key, value, new_node) - new_index = @neo.get_index("test_index", key, value) + @neo.add_node_to_index("test_index", key, value, new_node) + new_index = @neo.get_node_index("test_index", key, value) + new_index.should_not be_nil + @neo.remove_node_from_index("test_index", key, value, new_node) + end + + it "can add a relationship to an index" do + new_node1 = @neo.create_node + new_node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + key = generate_text(6) + value = generate_text + @neo.add_relationship_to_index("test_index", key, value, new_relationship) + new_index = @neo.get_relationship_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index("test_index", key, value, new_node) + @neo.remove_relationship_from_index("test_index", key, value, new_relationship) end end @@ -32,24 +54,50 @@ new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index("test_index", key, value, new_node) - new_index = @neo.get_index("test_index", key, value) + @neo.add_node_to_index("test_index", key, value, new_node) + new_index = @neo.get_node_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index("test_index", key, value, new_node) - new_index = @neo.get_index("test_index", key, value) + @neo.remove_node_from_index("test_index", key, value, new_node) + new_index = @neo.get_node_index("test_index", key, value) + new_index.should be_nil + end + + it "can remove a relationshp from an index" do + new_node1 = @neo.create_node + new_node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + key = generate_text(6) + value = generate_text + @neo.add_relationship_to_index("test_index", key, value, new_relationship) + new_index = @neo.get_relationship_index("test_index", key, value) + new_index.should_not be_nil + @neo.remove_relationship_from_index("test_index", key, value, new_relationship) + new_index = @neo.get_relationship_index("test_index", key, value) new_index.should be_nil end end describe "get index" do - it "can get an index" do + it "can get a node index" do new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index("test_index", key, value, new_node) - new_index = @neo.get_index("test_index", key, value) + @neo.add_node_to_index("test_index", key, value, new_node) + new_index = @neo.get_node_index("test_index", key, value) + new_index.should_not be_nil + @neo.remove_node_from_index("test_index", key, value, new_node) + end + + it "can get a relationship index" do + new_node1 = @neo.create_node + new_node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + key = generate_text(6) + value = generate_text + @neo.add_relationship_to_index("test_index", key, value, new_relationship) + new_index = @neo.get_relationship_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index("test_index", key, value, new_node) + @neo.remove_relationship_from_index("test_index", key, value, new_relationship) end end