diff --git a/README.rdoc b/README.rdoc index 2f841eb..c9becdb 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,7 +1,7 @@ == Welcome to Neography Neography is a thin ruby wrapper to the Neo4j Rest API, for more information: -* {Getting Started with REST for Neo4j}[http://wiki.neo4j.org/content/Getting_Started_REST] +* {Getting Started with Neo4j Server}[http://wiki.neo4j.org/content/Getting_Started_with_Neo4j_Server] * {Neo4j Rest API Reference}[http://components.neo4j.org/neo4j-rest/] @@ -16,7 +16,7 @@ Neography is a thin ruby wrapper to the Neo4j Rest API, for more information: Neography::Config.use do |config| config[:protocol] = 'http://' config[:server] = 'localhost' - config[:port] = '9999' + config[:port] = '7474' end ==== Rails @@ -66,7 +66,7 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and 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. +... and a work in progress more rubyish layer is in the works. Neography::Node.new # Create an empty node Neography::Node.new(:age => 31, :name => "Max") # Create a node with some properties diff --git a/lib/neography.rb b/lib/neography.rb index 35b84fc..bddadf4 100644 --- a/lib/neography.rb +++ b/lib/neography.rb @@ -15,39 +15,11 @@ def find_and_require_user_defined_code end end -def evaluate_response(response) - logger = Logger.new('log/neography.log') - - code = response.code - body = response.body - - case code - when 200 - logger.debug "OK" - when 201 - logger.debug "OK, created" - when 204 - logger.debug "OK, no content returned" - when 400 - logger.error "Invalid data sent" - when 404 - logger.error "#{body}" - end - -end require 'httparty' require 'json' -require 'logger' -#require 'net-http-spy' - -#Net::HTTP.http_logger_options = {:verbose => true} -#Net::HTTP.http_logger_options = {:body => true} require 'neography/config' require 'neography/rest' -require 'neography/neo' -require 'neography/node' -require 'neography/relationship' find_and_require_user_defined_code diff --git a/lib/neography/config.rb b/lib/neography/config.rb index f60d84a..64640ad 100644 --- a/lib/neography/config.rb +++ b/lib/neography/config.rb @@ -9,7 +9,7 @@ module Neography # ==== Default Configurations # :protocol:: default http:// protocol to use (can be https://) # :server:: default localhost where the database is stored on the network - # :port:: default 9999 what port is listening + # :port:: default 7474 what port is listening # class Config # This code is copied from merb-core/config.rb. @@ -22,7 +22,7 @@ def defaults @defaults ||= { :protocol => 'http://', :server => 'localhost', - :port => '9999' + :port => '7474' } end diff --git a/lib/neography/neo.rb b/lib/neography/neo.rb deleted file mode 100644 index 0540bc3..0000000 --- a/lib/neography/neo.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Neography - class Neo - include HTTParty - - base_uri 'http://localhost:9999' - - def self.root_node - get('/') - end - - end -end diff --git a/lib/neography/node.rb b/lib/neography/node.rb deleted file mode 100644 index cf89dcc..0000000 --- a/lib/neography/node.rb +++ /dev/null @@ -1,129 +0,0 @@ -module Neography - class Node - include HTTParty - base_uri 'http://localhost:9999' - format :json - - class << self - - def new(*args) - if args[0].respond_to?(:each_pair) && args[0] - options = { :body => args[0].to_json, :headers => {'Content-Type' => 'application/json'} } - response = post("/node", options) - evaluate_response(response) - build_node(response) - else - response = post("/node") - evaluate_response(response) - build_node(response) - end - end - - # create is the same as new - alias_method :create, :new - - def load(id) - begin - response = get("/node/#{id}") - evaluate_response(response) - build_node(response) - rescue - nil - end - end - - def properties(id) - begin - get("/node/#{id}/properties") - rescue - nil - end - end - - def set_properties(id, properties) - options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - response = put("/node/#{id}/properties", options) - evaluate_response(response) - response.parsed_response - end - - def remove_property(id, property) - response = delete("/node/#{id}/properties/#{property}") - evaluate_response(response) - response.parsed_response - end - - def remove_properties(id) - response = delete("/node/#{id}/properties") - evaluate_response(response) - response.parsed_response - end - - def del(id) - response = delete("/node/#{id}") - evaluate_response(response) - response.parsed_response - end - - def del!(id) - relationships = rels(id) - relationships.each {|r| Relationship.del(r[:rel_id])} - response = delete("/node/#{id}") - evaluate_response(response) - response.parsed_response - end - - def exists?(id) - load(id).nil? == false - end - - def rels(id, dir=nil, types=nil) - case dir - when :incoming - dir = "in" - when :outgoing - dir = "out" - else - dir = "all" - end - - if types.nil? - response = get("/node/#{id}/relationships/#{dir}") - else - response = get("/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") - end - evaluate_response(response) - build_rels(response) - end - - - private - - def build_node(response) - begin - node = response.parsed_response["data"] - rescue - node = Array.new - end - node[:neo_id] = response.parsed_response["self"].split('/').last - node - end - - def build_rels(response) - begin - rels = response.parsed_response - rels.each do |r| - r[:rel_id] = r["self"].split('/').last - r[:start_node] = r["start"].split('/').last - r[:end_node] = r["end"].split('/').last - end - rescue - rels = Array.new - end - rels - end - - - end - end -end diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb deleted file mode 100644 index ec73fcf..0000000 --- a/lib/neography/relationship.rb +++ /dev/null @@ -1,73 +0,0 @@ -module Neography - class Relationship - include HTTParty - base_uri Neography::Config.to_s - format :json - - class << self - - def new(type, from, to, props = nil) - options = { :body => {:to => Neography::Config.to_s + "/node/#{to[:neo_id]}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} } - response = post("/node/#{from[:neo_id]}/relationships", options) - evaluate_response(response) - build_relationship(response) - end - - def load(id) - begin - response = get("/relationship/#{id}") - evaluate_response(response) - build_relationship(response) - rescue - nil - end - end - - def properties(id) - begin - get("/relationship/#{id}/properties") - rescue - nil - end - end - - def set_properties(id, properties) - options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - response = put("/relationship/#{id}/properties", options) - evaluate_response(response) - response.parsed_response - end - - def remove_property(id, property) - response = delete("/relationship/#{id}/properties/#{property}") - evaluate_response(response) - response.parsed_response - end - - def remove_properties(id) - response = delete("/relationship/#{id}/properties") - evaluate_response(response) - response.parsed_response - end - - def del(id) - response = delete("/relationship/#{id}") - evaluate_response(response) - response.parsed_response - end - - private - - def build_relationship(response) - begin - relationship = response.parsed_response["data"] - rescue - relationship = Array.new - end - relationship[:rel_id] = response.parsed_response["self"].split('/').last - relationship - end - - end - end -end diff --git a/neography.gemspec b/neography.gemspec index 6b39abb..39e01d8 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -9,8 +9,8 @@ Gem::Specification.new do |s| s.authors = "Max De Marzi" s.email = "maxdemarzi@gmail.com" s.homepage = "http://rubygems.org/gems/neography" - s.summary = "ruby wrapper to Neo4j Rest Interface" - s.description = "A Ruby wrapper to the Neo4j Rest Client Interface see http://components.neo4j.org/neo4j-rest/ for more details." + s.summary = "ruby wrapper to Neo4j Rest API" + s.description = "A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/ for more details." s.rubyforge_project = "neography" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 531b33d..2a76399 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,12 +5,20 @@ FakeWeb.allow_net_connect = false -#To test against a real database: -#1. Make sure empty database is running (./bin/neo4j-rest start) -#2. Uncomment the next two lines +# To test against a real database: +# 1. Make sure empty database is running on your test neo4j server (bin/neo4j start) +# 2. Uncomment the next two lines FakeWeb.clean_registry FakeWeb.allow_net_connect = true +# 3. If you want to see more, uncomment the next few lines +# require 'net-http-spy' +# Net::HTTP.http_logger_options = {:body => true} # just the body +# Net::HTTP.http_logger_options = {:verbose => true} # see everything + + + + def generate_text(length=8) chars = 'abcdefghjkmnpqrstuvwxyz' key = '' diff --git a/spec/support/fake_root_spec.rb b/spec/support/fake_root_spec.rb index 0ce81da..becb6b2 100644 --- a/spec/support/fake_root_spec.rb +++ b/spec/support/fake_root_spec.rb @@ -1,5 +1,5 @@ -FakeWeb.register_uri(:get, "http://localhost:9999/", :body => '{ - "index" : "http://localhost:9999/index", - "node" : "http://localhost:9999/node", - "reference_node" : "http://localhost:9999/node/0" +FakeWeb.register_uri(:get, "http://localhost:7474/", :body => '{ + "index" : "http://localhost:7474/index", + "node" : "http://localhost:7474/node", + "reference_node" : "http://localhost:7474/node/0" }') \ No newline at end of file