Skip to content

Commit

Permalink
quick initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Feb 6, 2011
1 parent 2015a05 commit ab853ae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
9 changes: 7 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
:log_enabled => false,
:max_threads => 20})

Quick initializer (assumes basic authorization if username is given):

@neo = Neography::Rest.new("http://username:[email protected]:7474/mydirectory")


To Use:

@neo = Neography::Rest.new
@neo = Neography::Rest.new # Inialize using all default parameters

@neo.get_root # Get the root node
node1 = @neo.create_node # Create an empty node
Expand Down Expand Up @@ -138,7 +143,7 @@ Experimental:
another_node = @neo.create_node("age" => 31, "name" => "Max")
nodes = @neo.get_nodes([one_set_nodes, another_node]) # Get four nodes

=== Phase 2 (work in progress):
=== Phase 2

Trying to mimic the Neo4j.rb API.

Expand Down
13 changes: 13 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ def initialize(options={})
:log_enabled => Neography::Config.log_enabled,
:max_threads => Neography::Config.max_threads,
:authentication => Neography::Config.authentication}

unless options.respond_to?(:each_pair)
url = URI.parse(options)
options = Hash.new
options[:protocol] = url.scheme + "://"
options[:server] = url.host
options[:port] = url.port
options[:directory] = url.path
options[:user] = url.user
options[:password] = url.password
options[:authentication] = 'basic' unless url.user.nil?
end

init.merge!(options)

@protocol = init[:protocol]
Expand Down
49 changes: 38 additions & 11 deletions spec/integration/authorization_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
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 "basic authentication" do
describe "get_root" do
it "can get the root node" do
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
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
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
new_node = @neo.create_node
new_node.should_not be_nil
end
end

describe "get_root" do
it "can get the root node" do
root_node = @neo.get_root
root_node.should have_key("reference_node")
describe "quick initalizer" do
it "can get the root node" do
@neo = Neography::Rest.new("http://abbe3c012:[email protected]:7474/9dc1fda5be8b5cde29621e21cae5adece3de0f37")
root_node = @neo.get_root
root_node.should have_key("reference_node")
end
end
end

describe "create_node" do
it "can create an empty node" do
new_node = @neo.create_node
new_node.should_not be_nil
describe "digest authentication" do
describe "get_root" do
it "can get the root node" do
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
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
@neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
new_node = @neo.create_node
new_node.should_not be_nil
end
end
end

end

0 comments on commit ab853ae

Please sign in to comment.