From 914d4d319e3a2effadb636715462a37340641f90 Mon Sep 17 00:00:00 2001 From: ajay Date: Thu, 2 Feb 2012 21:54:45 +0800 Subject: [PATCH] added 2 more functions - create_unique_node and create_unique_realtionship --- lib/neography/rest.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 73781a3..0f3695f 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -172,6 +172,14 @@ def create_relationship(type, from, to, props = nil) post("/node/#{get_id(from)}/relationships", options) end + def create_unique_relationship(index, key, value, type, from, to) + body = {:key=>key,:value=>value, :type => type } + body[:start] = self.configuration + "/node/#{get_id(from)}" + body[:end] = self.configuration + "/node/#{get_id(to)}" + options = { :body => body.to_json, :headers => {'Content-Type' => 'application/json'} } + post("/index/relationship/#{index}?unique", options) + end + def get_relationship(id) get("/relationship/#{get_id(id)}") end @@ -256,6 +264,11 @@ def add_node_to_index(index, key, value, id) post("/index/node/#{index}", options) end + def create_unique_node(index, key, value, props={}) + options = { :body => ({:properties=>props, :key => key, :value => value }).to_json, :headers => {'Content-Type' => 'application/json'} } + post("/index/node/#{index}?unique", options) + end + def remove_node_from_index(*args) case args.size when 4 then delete("/index/node/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")