diff --git a/Gemfile.lock b/Gemfile.lock index 9df27d8..222e499 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ PATH remote: . specs: - neography (0.0.6) - httparty (~> 0.6.1) + neography (0.0.7) + httparty (~> 0.7.3) json GEM @@ -11,7 +11,7 @@ GEM crack (0.1.8) diff-lcs (1.1.2) fakeweb (1.3.0) - httparty (0.6.1) + httparty (0.7.3) crack (= 0.1.8) json (1.4.6) json (1.4.6-java) @@ -33,7 +33,7 @@ PLATFORMS DEPENDENCIES fakeweb (~> 1.3.0) - httparty (~> 0.6.1) + httparty (~> 0.7.3) json neography! net-http-spy (~> 0.2.1) diff --git a/README.rdoc b/README.rdoc index 90262a5..1407560 100644 --- a/README.rdoc +++ b/README.rdoc @@ -46,12 +46,16 @@ Just add gem 'neography' to your Gemfile and run bundle install A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil: - # protocol, server, port, log_file, log_enabled, max_threads - @neo = Neography::Rest.new ('http://', '192.168.10.1', 7479, 'log/neography.log', true, 50) - -Default Parameters are: - - @neo = Neography::Rest.new ('http://', 'localhost', 7474, '/neography.log', false, 20) + @neo = Neography::Rest.new({:protocol => 'http://', + :server => 'localhost', + :port => 7474, + :directory => '', # use '/' or leave out for default + :authentication => 'basic', # 'basic', 'digest' or leave out for default + :username => 'your username', #leave out for default + :password => 'your password', #leave out for default + :log_file => 'neography.log', + :log_enabled => false, + :max_threads => 20}) To Use: @@ -136,7 +140,7 @@ Trying to mimic the Neo4j.rb API. Now we are returning full objects. The properties of the node or relationship can be accessed directly (node.name). The Neo4j ID is available by using node.neo_id . - @neo2 = Neography::Rest.new ('http://', '192.168.10.1') + @neo2 = Neography::Rest.new ({:server => '192.168.10.1'}) Neography::Node.create # Create an empty node Neography::Node.create("age" => 31, "name" => "Max") # Create a node with some properties @@ -228,13 +232,20 @@ See Neo4j API for: === Examples -A couple of examples borrowed from Matthew Deiters's Neo4jr-social +A couple of examples borrowed from Matthew Deiters's Neo4jr-social: * {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook.rb] * {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin.rb] +Phase 2 way of doing these: + +* {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook_v2.rb] +* {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin_v2.rb] + + === To Do +* Phase 2 Index functionality * More Tests * More Examples * Mixins ? diff --git a/lib/neography/config.rb b/lib/neography/config.rb index 7f2992c..c8f70b2 100644 --- a/lib/neography/config.rb +++ b/lib/neography/config.rb @@ -1,14 +1,15 @@ module Neography class Config - class << self; attr_accessor :protocol, :server, :port, :log_file, :log_enabled, :logger, :max_threads end + class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication end @protocol = 'http://' @server = 'localhost' @port = 7474 + @directory = '' @log_file = 'neography.log' @log_enabled = false @logger = Logger.new(@log_file) if @log_enabled @max_threads = 20 - + @authentication = {} end end \ No newline at end of file diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 9a44817..941472e 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,31 +1,41 @@ module Neography class Rest include HTTParty - attr_accessor :protocol, :server, :port, :log_file, :log_enabled, :logger, :max_threads - - def initialize(protocol=Neography::Config.protocol, - server=Neography::Config.server, - port=Neography::Config.port, - log_file=Neography::Config.log_file, - log_enabled=Neography::Config.log_enabled, - max_threads=Neography::Config.max_threads) - @protocol = protocol - @server = server - @port = port - @log_file = log_file - @log_enabled = log_enabled - @logger = Logger.new(@log_file) if @log_enabled - @max_threads = max_threads - end - def configure(protocol, server, port) + attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password + + def initialize(options={}) + init = {:protocol => Neography::Config.protocol, + :server => Neography::Config.server, + :port => Neography::Config.port, + :directory => Neography::Config.directory, + :log_file => Neography::Config.log_file, + :log_enabled => Neography::Config.log_enabled, + :max_threads => Neography::Config.max_threads, + :authentication => Neography::Config.authentication} + init.merge!(options) + + @protocol = init[:protocol] + @server = init[:server] + @port = init[:port] + @directory = init[:directory] + @log_file = init[:log_file] + @log_enabled = init[:log_enabled] + @logger = Logger.new(@log_file) if @log_enabled + @max_threads = init[:max_threads] + @authentication = Hash.new + @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty? + end + + def configure(protocol, server, port, directory) @protocol = protocol @server = server @port = port + @directory = directory end def configuration - @protocol + @server + ':' + @port.to_s + "/db/data" + @protocol + @server + ':' + @port.to_s + @directory + "/db/data" end def get_root @@ -277,19 +287,19 @@ def evaluate_response(response) end def get(path,options={}) - evaluate_response(HTTParty.get(configuration + path, options)) + evaluate_response(HTTParty.get(configuration + path, options.merge!(@authentication))) end def post(path,options={}) - evaluate_response(HTTParty.post(configuration + path, options)) + evaluate_response(HTTParty.post(configuration + path, options.merge!(@authentication))) end def put(path,options={}) - evaluate_response(HTTParty.put(configuration + path, options)) + evaluate_response(HTTParty.put(configuration + path, options.merge!(@authentication))) end def delete(path,options={}) - evaluate_response(HTTParty.delete(configuration + path, options)) + evaluate_response(HTTParty.delete(configuration + path, options.merge!(@authentication))) end def get_id(id) diff --git a/neography.gemspec b/neography.gemspec index 39e01d8..024f2ca 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -22,6 +22,6 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 2.0.0.beta.22" s.add_development_dependency "net-http-spy", "~> 0.2.1" s.add_development_dependency "fakeweb", "~> 1.3.0" - s.add_dependency "httparty", "~> 0.6.1" + s.add_dependency "httparty", "~> 0.7.3" s.add_dependency "json" end diff --git a/spec/integration/heroku_spec.rb b/spec/integration/heroku_spec.rb new file mode 100644 index 0000000..5d65e74 --- /dev/null +++ b/spec/integration/heroku_spec.rb @@ -0,0 +1,21 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Neography::Rest do + before(:each) do + @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"}) + end + + describe "get_root" do + it "can get the root node" do + root_node = @neo.get_root + root_node.should have_key("reference_node") + end + end + + describe "create_node" do + it "can create an empty node" do + new_node = @neo.create_node + new_node.should_not be_nil + end + end +end \ No newline at end of file diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 4c27525..6193ba6 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -7,6 +7,10 @@ describe "list indexes" do it "can get a listing of 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.list_indexes.should_not be_nil end end @@ -16,10 +20,10 @@ new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node) - new_index = @neo.get_index(key, value) + @neo.add_to_index("test_index", key, value, new_node) + new_index = @neo.get_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node) + @neo.remove_from_index("test_index", key, value, new_node) end end @@ -28,11 +32,11 @@ new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node) - new_index = @neo.get_index(key, value) + @neo.add_to_index("test_index", key, value, new_node) + new_index = @neo.get_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node) - new_index = @neo.get_index(key, value) + @neo.remove_from_index("test_index", key, value, new_node) + new_index = @neo.get_index("test_index", key, value) new_index.should be_nil end end @@ -42,10 +46,10 @@ new_node = @neo.create_node key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node) - new_index = @neo.get_index(key, value) + @neo.add_to_index("test_index", key, value, new_node) + new_index = @neo.get_index("test_index", key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node) + @neo.remove_from_index("test_index", key, value, new_node) end end