diff --git a/lib/neography/config.rb b/lib/neography/config.rb index efebf0f..fd9d384 100644 --- a/lib/neography/config.rb +++ b/lib/neography/config.rb @@ -1,6 +1,6 @@ module Neography class Config - class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end + class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end @protocol = 'http://' @server = 'localhost' @@ -15,5 +15,6 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path @authentication = {} @username = nil @password = nil + @parser = {:parser => CrackParser} end end \ No newline at end of file diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 06d9b3e..f9e818e 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -3,7 +3,7 @@ module Neography class Rest include HTTParty - attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password + attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser def initialize(options=ENV['NEO4J_URL'] || {}) init = {:protocol => Neography::Config.protocol, @@ -17,7 +17,8 @@ def initialize(options=ENV['NEO4J_URL'] || {}) :max_threads => Neography::Config.max_threads, :authentication => Neography::Config.authentication, :username => Neography::Config.username, - :password => Neography::Config.password + :password => Neography::Config.password, + :parser => Neography::Config.parser } unless options.respond_to?(:each_pair) @@ -140,13 +141,12 @@ def reset_node_properties(id, properties) end def get_node_properties(id, properties = nil) - options = {:parser => CrackParser} if properties.nil? - get("/node/#{get_id(id)}/properties", options) + get("/node/#{get_id(id)}/properties") else node_properties = Hash.new Array(properties).each do |property| - value = get("/node/#{get_id(id)}/properties/#{property}", options) + value = get("/node/#{get_id(id)}/properties/#{property}") node_properties[property] = value unless value.nil? end return nil if node_properties.empty? @@ -155,19 +155,18 @@ def get_node_properties(id, properties = nil) end def remove_node_properties(id, properties = nil) - options = {:parser => CrackParser} if properties.nil? - delete("/node/#{get_id(id)}/properties", options) + delete("/node/#{get_id(id)}/properties") else Array(properties).each do |property| - delete("/node/#{get_id(id)}/properties/#{property}", options) + delete("/node/#{get_id(id)}/properties/#{property}") end end end def set_node_properties(id, properties) properties.each do |key, value| - options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'}, :parser => CrackParser} + options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} } put("/node/#{get_id(id)}/properties/#{key}", options) end end @@ -207,13 +206,12 @@ def reset_relationship_properties(id, properties) end def get_relationship_properties(id, properties = nil) - options = {:parser => CrackParser} if properties.nil? - get("/relationship/#{get_id(id)}/properties", options) + get("/relationship/#{get_id(id)}/properties") else relationship_properties = Hash.new Array(properties).each do |property| - value = get("/relationship/#{get_id(id)}/properties/#{property}", options) + value = get("/relationship/#{get_id(id)}/properties/#{property}") relationship_properties[property] = value unless value.nil? end return nil if relationship_properties.empty? @@ -222,12 +220,11 @@ def get_relationship_properties(id, properties = nil) end def remove_relationship_properties(id, properties = nil) - options = {:parser => CrackParser} if properties.nil? - delete("/relationship/#{get_id(id)}/properties", options) + delete("/relationship/#{get_id(id)}/properties") else Array(properties).each do |property| - delete("/relationship/#{get_id(id)}/properties/#{property}", options) + delete("/relationship/#{get_id(id)}/properties/#{property}") end end end @@ -395,15 +392,10 @@ def get_shortest_weighted_path(from, to, relationships, weight_attr='weight', de end def execute_query(query, params = {}) - options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json', 'accept' => 'application/json;stream=true'} , :parser => HTTParty::Parser} + options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} } result = post(@cypher_path, options) end - def execute_query_not_streaming(query, params = {}) - options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'}, :parser => HTTParty::Parser } - result = post(@cypher_path, options) - end - def execute_script(script, params = {}) options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} } result = post(@gremlin_path, options) @@ -495,19 +487,19 @@ def evaluate_response(response) end def get(path,options={}) - evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def post(path,options={}) - evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def put(path,options={}) - evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def delete(path,options={}) - evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def get_id(id) diff --git a/spec/integration/rest_plugin_spec.rb b/spec/integration/rest_plugin_spec.rb index b5f19a1..ec75df7 100644 --- a/spec/integration/rest_plugin_spec.rb +++ b/spec/integration/rest_plugin_spec.rb @@ -29,12 +29,6 @@ existing_node.should have_key("self") existing_node["self"].split('/').last.should == id end - - #it "can create a ton of nodes" do - # ton_nodes = @neo.execute_script("5000.times { g.addVertex();}") - # ton_nodes.should be_nil - #end - end describe "execute cypher query" do @@ -68,15 +62,6 @@ existing_node["data"][0][0]["self"].split('/').last.should == id end - it "can get the a bunch of nodes streaming", :slow => true do - Benchmark.bm do |x| - x.report("cypher ") { @existing_nodes = @neo.execute_query_not_streaming("start n=node(*) return n") } - x.report("streaming cypher ") { @existing_nodes_streaming = @neo.execute_query("start n=node(*) return n") } - end - @existing_nodes.should_not be_nil - @existing_nodes_streaming.should_not be_nil - end - end end \ No newline at end of file