From c1eef084ad995c1a50eb85d99db743047327537b Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 01:43:33 +0000 Subject: [PATCH] making gremlin script parameter aware --- lib/neography/rest.rb | 4 ++-- spec/integration/rest_plugin_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index fc660d5..d593366 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -346,8 +346,8 @@ def execute_query(query) result = post("/ext/CypherPlugin/graphdb/execute_query", options) end - def execute_script(script) - options = { :body => "script=" + CGI::escape(script), :headers => {'Content-Type' => 'application/x-www-form-urlencoded'} } + def execute_script(script, params = {}) + options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} } result = post("/ext/GremlinPlugin/graphdb/execute_script", options) result == "null" ? nil : result end diff --git a/spec/integration/rest_plugin_spec.rb b/spec/integration/rest_plugin_spec.rb index 222d962..2254256 100644 --- a/spec/integration/rest_plugin_spec.rb +++ b/spec/integration/rest_plugin_spec.rb @@ -11,6 +11,27 @@ root_node.should have_key("self") root_node["self"].split('/').last.should == "0" end + + it "can get the a node" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_script("g.v(#{id})") + existing_node.should_not be_nil + existing_node.should have_key("self") + existing_node["self"].split('/').last.should == id + end + + it "can get the a node with a variable" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_script("g.v(id)", {:id => id}) + existing_node.should_not be_nil + existing_node.should have_key("self") + existing_node["self"].split('/').last.should == id + end + + + end describe "execute cypher query" do