Skip to content

Commit

Permalink
fix to v2 authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Feb 10, 2011
1 parent 590d763 commit 994d90c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/neography/config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Neography
class Config
class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication end
class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end

@protocol = 'http://'
@server = 'localhost'
Expand All @@ -11,5 +11,7 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :
@logger = Logger.new(@log_file) if @log_enabled
@max_threads = 20
@authentication = {}
@username = nil
@password = nil
end
end
9 changes: 9 additions & 0 deletions lib/neography/node_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Neography
module NodeIndex

def find

end

end
end
22 changes: 13 additions & 9 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ class Rest
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 = {: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,
:username => Neography::Config.username,
:password => Neography::Config.password}

unless options.respond_to?(:each_pair)
url = URI.parse(options)
Expand All @@ -21,12 +23,13 @@ def initialize(options={})
options[:server] = url.host
options[:port] = url.port
options[:directory] = url.path
options[:user] = url.user
options[:username] = url.user
options[:password] = url.password
options[:authentication] = 'basic' unless url.user.nil?
end

init.merge!(options)
puts init.inspect

@protocol = init[:protocol]
@server = init[:server]
Expand All @@ -38,6 +41,7 @@ def initialize(options={})
@max_threads = init[:max_threads]
@authentication = Hash.new
@authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
puts "Authentication: #{@authentication.inspect}"
end

def configure(protocol, server, port, directory)
Expand Down
31 changes: 31 additions & 0 deletions spec/integration/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Neography::Relationship, "find" do
before(:each) do
Neography::Relationship.index(:strength)
end

it "can index when Neography::Relationships are created" do
a = Neography::Node.create
b = Neography::Node.create
r = Neography::Relationship.create(:friends, a, b)
r[:strength] = 'strong'
Neography::Relationship.find('strength: strong').first.should == r
end

it "can remove index when Neography::Relationship is deleted, just like nodes" do
a = Neography::Node.create
b = Neography::Node.create
r = Neography::Relationship.create(:friends, a, b)
r[:strength] = 'weak'
r2 = Neography::Relationship.find('strength: weak').first
r2.should == r
r2.del
Neography::Relationship.find('strength: weak').should be_empty
end
end


describe Neography::Node, "find" do

end

0 comments on commit 994d90c

Please sign in to comment.