neography 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neography (0.0.7)
4
+ neography (0.0.9)
5
5
  httparty (~> 0.7.3)
6
6
  json
7
7
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
4
4
  * {Getting Started with Neo4j Server}[http://wiki.neo4j.org/content/Getting_Started_with_Neo4j_Server]
5
- * {Neo4j Rest API Reference}[http://components.neo4j.org/neo4j-rest/]
5
+ * {Neo4j Rest API Reference}[http://components.neo4j.org/neo4j-server/milestone/rest.html]
6
6
 
7
7
  If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j
8
8
 
@@ -19,7 +19,7 @@ in order to access the functionality.
19
19
 
20
20
  === Try it now!
21
21
 
22
- I am hosting an instance of Neo4j (1.2 M5) at neography.org for you to try out.
22
+ I am hosting an instance of Neo4j (1.2) at neography.org for you to try out.
23
23
 
24
24
  You can see the administration at: {Neo4j Web Admin}[http://neography.org]
25
25
 
@@ -44,8 +44,6 @@ Just add gem 'neography' to your Gemfile and run bundle install
44
44
 
45
45
  === Documentation
46
46
 
47
- A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil:
48
-
49
47
  @neo = Neography::Rest.new({:protocol => 'http://',
50
48
  :server => 'localhost',
51
49
  :port => 7474,
@@ -57,9 +55,14 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
57
55
  :log_enabled => false,
58
56
  :max_threads => 20})
59
57
 
58
+ Quick initializer (assumes basic authorization if username is given):
59
+
60
+ @neo = Neography::Rest.new("http://username:password@myserver.com:7474/mydirectory")
61
+
62
+
60
63
  To Use:
61
64
 
62
- @neo = Neography::Rest.new
65
+ @neo = Neography::Rest.new # Inialize using all default parameters
63
66
 
64
67
  @neo.get_root # Get the root node
65
68
  node1 = @neo.create_node # Create an empty node
@@ -92,10 +95,15 @@ To Use:
92
95
  @neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship
93
96
  @neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship
94
97
 
95
- @neo.list_indexes # gives names and query templates for all defined indices
96
- @neo.add_to_index(index, key, value, node1) # adds a node to the specified index with the given key/value pair
97
- @neo.remove_from_index(index, key, value, node1) # removes a node from the specified index with the given key/value pair
98
- @neo.get_index(index, key, value) # queries the specified index with the given key/value pair
98
+ @neo.list_node_indexes # gives names and query templates for all defined indices
99
+ @neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair
100
+ @neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair
101
+ @neo.get_node_index(index, key, value) # queries the index with the given key/value pair
102
+ @neo.list_relationship_indexes # gives names and query templates for relationship indices
103
+ @neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
104
+ @neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair
105
+ @neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair
106
+
99
107
 
100
108
  @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
101
109
  @neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
@@ -133,7 +141,7 @@ Experimental:
133
141
  another_node = @neo.create_node("age" => 31, "name" => "Max")
134
142
  nodes = @neo.get_nodes([one_set_nodes, another_node]) # Get four nodes
135
143
 
136
- === Phase 2 (work in progress):
144
+ === Phase 2
137
145
 
138
146
  Trying to mimic the Neo4j.rb API.
139
147
 
@@ -1,6 +1,6 @@
1
1
  module Neography
2
2
  class Config
3
- class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication end
3
+ class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end
4
4
 
5
5
  @protocol = 'http://'
6
6
  @server = 'localhost'
@@ -11,5 +11,7 @@ module Neography
11
11
  @logger = Logger.new(@log_file) if @log_enabled
12
12
  @max_threads = 20
13
13
  @authentication = {}
14
+ @username = nil
15
+ @password = nil
14
16
  end
15
17
  end
@@ -0,0 +1,9 @@
1
+ module Neography
2
+ module NodeIndex
3
+
4
+ def find
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -5,15 +5,31 @@ module Neography
5
5
  attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password
6
6
 
7
7
  def initialize(options={})
8
- init = {:protocol => Neography::Config.protocol,
9
- :server => Neography::Config.server,
10
- :port => Neography::Config.port,
11
- :directory => Neography::Config.directory,
12
- :log_file => Neography::Config.log_file,
13
- :log_enabled => Neography::Config.log_enabled,
14
- :max_threads => Neography::Config.max_threads,
15
- :authentication => Neography::Config.authentication}
8
+ init = {:protocol => Neography::Config.protocol,
9
+ :server => Neography::Config.server,
10
+ :port => Neography::Config.port,
11
+ :directory => Neography::Config.directory,
12
+ :log_file => Neography::Config.log_file,
13
+ :log_enabled => Neography::Config.log_enabled,
14
+ :max_threads => Neography::Config.max_threads,
15
+ :authentication => Neography::Config.authentication,
16
+ :username => Neography::Config.username,
17
+ :password => Neography::Config.password}
18
+
19
+ unless options.respond_to?(:each_pair)
20
+ url = URI.parse(options)
21
+ options = Hash.new
22
+ options[:protocol] = url.scheme + "://"
23
+ options[:server] = url.host
24
+ options[:port] = url.port
25
+ options[:directory] = url.path
26
+ options[:username] = url.user
27
+ options[:password] = url.password
28
+ options[:authentication] = 'basic' unless url.user.nil?
29
+ end
30
+
16
31
  init.merge!(options)
32
+ puts init.inspect
17
33
 
18
34
  @protocol = init[:protocol]
19
35
  @server = init[:server]
@@ -25,6 +41,7 @@ module Neography
25
41
  @max_threads = init[:max_threads]
26
42
  @authentication = Hash.new
27
43
  @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
44
+ puts "Authentication: #{@authentication.inspect}"
28
45
  end
29
46
 
30
47
  def configure(protocol, server, port, directory)
@@ -219,25 +236,48 @@ module Neography
219
236
  delete("/node/#{get_id(id)}")
220
237
  end
221
238
 
222
- def list_indexes
239
+ def list_node_indexes
223
240
  get("/index/node")
224
241
  end
225
242
 
226
- def add_to_index(index, key, value, id)
243
+ def add_node_to_index(index, key, value, id)
227
244
  options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
228
245
  post("/index/node/#{index}/#{key}/#{value}", options)
229
246
  end
230
247
 
231
- def remove_from_index(index, key, value, id)
248
+ def remove_node_from_index(index, key, value, id)
232
249
  delete("/index/node/#{index}/#{key}/#{value}/#{get_id(id)}")
233
250
  end
234
251
 
235
- def get_index(index, key, value)
252
+ def get_node_index(index, key, value)
236
253
  index = get("/index/node/#{index}/#{key}/#{value}") || Array.new
237
254
  return nil if index.empty?
238
255
  index
239
256
  end
240
257
 
258
+ alias_method :list_indexes, :list_node_indexes
259
+ alias_method :add_to_index, :add_node_to_index
260
+ alias_method :remove_from_index, :remove_node_from_index
261
+ alias_method :get_index, :get_node_index
262
+
263
+ def list_relationship_indexes
264
+ get("/index/relationship")
265
+ end
266
+
267
+ def add_relationship_to_index(index, key, value, id)
268
+ options = { :body => (self.configuration + "/relationship/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
269
+ post("/index/relationship/#{index}/#{key}/#{value}", options)
270
+ end
271
+
272
+ def remove_relationship_from_index(index, key, value, id)
273
+ delete("/index/relationship/#{index}/#{key}/#{value}/#{get_id(id)}")
274
+ end
275
+
276
+ def get_relationship_index(index, key, value)
277
+ index = get("/index/relationship/#{index}/#{key}/#{value}") || Array.new
278
+ return nil if index.empty?
279
+ index
280
+ end
241
281
  def traverse(id, return_type, description)
242
282
  options = { :body => {"order" => get_order(description["order"]),
243
283
  "uniqueness" => get_uniqueness(description["uniqueness"]),
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ describe "basic authentication" do
5
+ describe "get_root" do
6
+ it "can get the root node" do
7
+ @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
8
+ root_node = @neo.get_root
9
+ root_node.should have_key("reference_node")
10
+ end
11
+ end
12
+
13
+ describe "create_node" do
14
+ it "can create an empty node" do
15
+ @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
16
+ new_node = @neo.create_node
17
+ new_node.should_not be_nil
18
+ end
19
+ end
20
+
21
+ describe "quick initalizer" do
22
+ it "can get the root node" do
23
+ @neo = Neography::Rest.new("http://abbe3c012:34d7b22eb@4c36b641.neo4j.atns.de:7474/9dc1fda5be8b5cde29621e21cae5adece3de0f37")
24
+ root_node = @neo.get_root
25
+ root_node.should have_key("reference_node")
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "digest authentication" do
31
+ describe "get_root" do
32
+ it "can get the root node" do
33
+ @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
34
+ root_node = @neo.get_root
35
+ root_node.should have_key("reference_node")
36
+ end
37
+ end
38
+
39
+ describe "create_node" do
40
+ it "can create an empty node" do
41
+ @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"})
42
+ new_node = @neo.create_node
43
+ new_node.should_not be_nil
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Relationship, "find" do
4
+ before(:each) do
5
+ Neography::Relationship.index(:strength)
6
+ end
7
+
8
+ it "can index when Neography::Relationships are created" do
9
+ a = Neography::Node.create
10
+ b = Neography::Node.create
11
+ r = Neography::Relationship.create(:friends, a, b)
12
+ r[:strength] = 'strong'
13
+ Neography::Relationship.find('strength: strong').first.should == r
14
+ end
15
+
16
+ it "can remove index when Neography::Relationship is deleted, just like nodes" do
17
+ a = Neography::Node.create
18
+ b = Neography::Node.create
19
+ r = Neography::Relationship.create(:friends, a, b)
20
+ r[:strength] = 'weak'
21
+ r2 = Neography::Relationship.find('strength: weak').first
22
+ r2.should == r
23
+ r2.del
24
+ Neography::Relationship.find('strength: weak').should be_empty
25
+ end
26
+ end
27
+
28
+
29
+ describe Neography::Node, "find" do
30
+
31
+ end
@@ -6,13 +6,23 @@ describe Neography::Rest do
6
6
  end
7
7
 
8
8
  describe "list indexes" do
9
- it "can get a listing of indexes" do
9
+ it "can get a listing of node indexes" do
10
10
  new_node = @neo.create_node
11
11
  key = generate_text(6)
12
12
  value = generate_text
13
- @neo.add_to_index("test_index", key, value, new_node)
13
+ @neo.add_node_to_index("test_index", key, value, new_node)
14
14
  @neo.list_indexes.should_not be_nil
15
15
  end
16
+
17
+ it "can get a listing of relationship indexes" do
18
+ new_node1 = @neo.create_node
19
+ new_node2 = @neo.create_node
20
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
21
+ key = generate_text(6)
22
+ value = generate_text
23
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
24
+ @neo.list_relationship_indexes.should_not be_nil
25
+ end
16
26
  end
17
27
 
18
28
  describe "add to index" do
@@ -20,10 +30,22 @@ describe Neography::Rest do
20
30
  new_node = @neo.create_node
21
31
  key = generate_text(6)
22
32
  value = generate_text
23
- @neo.add_to_index("test_index", key, value, new_node)
24
- new_index = @neo.get_index("test_index", key, value)
33
+ @neo.add_node_to_index("test_index", key, value, new_node)
34
+ new_index = @neo.get_node_index("test_index", key, value)
35
+ new_index.should_not be_nil
36
+ @neo.remove_node_from_index("test_index", key, value, new_node)
37
+ end
38
+
39
+ it "can add a relationship to an index" do
40
+ new_node1 = @neo.create_node
41
+ new_node2 = @neo.create_node
42
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
43
+ key = generate_text(6)
44
+ value = generate_text
45
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
46
+ new_index = @neo.get_relationship_index("test_index", key, value)
25
47
  new_index.should_not be_nil
26
- @neo.remove_from_index("test_index", key, value, new_node)
48
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
27
49
  end
28
50
  end
29
51
 
@@ -32,25 +54,76 @@ describe Neography::Rest do
32
54
  new_node = @neo.create_node
33
55
  key = generate_text(6)
34
56
  value = generate_text
35
- @neo.add_to_index("test_index", key, value, new_node)
36
- new_index = @neo.get_index("test_index", key, value)
57
+ @neo.add_node_to_index("test_index", key, value, new_node)
58
+ new_index = @neo.get_node_index("test_index", key, value)
37
59
  new_index.should_not be_nil
38
- @neo.remove_from_index("test_index", key, value, new_node)
39
- new_index = @neo.get_index("test_index", key, value)
60
+ @neo.remove_node_from_index("test_index", key, value, new_node)
61
+ new_index = @neo.get_node_index("test_index", key, value)
62
+ new_index.should be_nil
63
+ end
64
+
65
+ it "can remove a relationshp from an index" do
66
+ new_node1 = @neo.create_node
67
+ new_node2 = @neo.create_node
68
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
69
+ key = generate_text(6)
70
+ value = generate_text
71
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
72
+ new_index = @neo.get_relationship_index("test_index", key, value)
73
+ new_index.should_not be_nil
74
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
75
+ new_index = @neo.get_relationship_index("test_index", key, value)
40
76
  new_index.should be_nil
41
77
  end
42
78
  end
43
79
 
44
80
  describe "get index" do
45
- it "can get an index" do
81
+ it "can get a node index" do
46
82
  new_node = @neo.create_node
47
83
  key = generate_text(6)
48
84
  value = generate_text
49
- @neo.add_to_index("test_index", key, value, new_node)
50
- new_index = @neo.get_index("test_index", key, value)
85
+ @neo.add_node_to_index("test_index", key, value, new_node)
86
+ new_index = @neo.get_node_index("test_index", key, value)
87
+ new_index.should_not be_nil
88
+ @neo.remove_node_from_index("test_index", key, value, new_node)
89
+ end
90
+
91
+ it "can get a relationship index" do
92
+ new_node1 = @neo.create_node
93
+ new_node2 = @neo.create_node
94
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
95
+ key = generate_text(6)
96
+ value = generate_text
97
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
98
+ new_index = @neo.get_relationship_index("test_index", key, value)
51
99
  new_index.should_not be_nil
52
- @neo.remove_from_index("test_index", key, value, new_node)
100
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
53
101
  end
54
102
  end
55
103
 
104
+ describe "query index" do
105
+ it "can query a node index" do
106
+ new_node = @neo.create_node
107
+ key = generate_text(6)
108
+ value = generate_text
109
+ @neo.add_node_to_index("test_index", key, value, new_node)
110
+ new_index = @neo.get_node_index("test_index", key, value)
111
+ new_index.first["self"].should == new_node["self"]
112
+ @neo.remove_node_from_index("test_index", key, value, new_node)
113
+ end
114
+
115
+ it "can get a relationship index" do
116
+ new_node1 = @neo.create_node
117
+ new_node2 = @neo.create_node
118
+ new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
119
+ key = generate_text(6)
120
+ value = generate_text
121
+ @neo.add_relationship_to_index("test_index", key, value, new_relationship)
122
+ new_index = @neo.get_relationship_index("test_index", key, value)
123
+ new_index.first["self"].should == new_relationship["self"]
124
+ @neo.remove_relationship_from_index("test_index", key, value, new_relationship)
125
+ end
126
+ end
127
+
128
+
56
129
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Max De Marzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-04 00:00:00 -08:00
18
+ date: 2011-02-10 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -124,6 +124,7 @@ files:
124
124
  - lib/neography/equal.rb
125
125
  - lib/neography/neography.rb
126
126
  - lib/neography/node.rb
127
+ - lib/neography/node_index.rb
127
128
  - lib/neography/node_path.rb
128
129
  - lib/neography/node_relationship.rb
129
130
  - lib/neography/node_traverser.rb
@@ -135,7 +136,8 @@ files:
135
136
  - lib/neography/rest.rb
136
137
  - lib/neography/version.rb
137
138
  - neography.gemspec
138
- - spec/integration/heroku_spec.rb
139
+ - spec/integration/authorization_spec.rb
140
+ - spec/integration/index_spec.rb
139
141
  - spec/integration/neography_spec.rb
140
142
  - spec/integration/node_path_spec.rb
141
143
  - spec/integration/node_relationship_spec.rb
@@ -1,21 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- describe Neography::Rest do
4
- before(:each) do
5
- @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"})
6
- end
7
-
8
- describe "get_root" do
9
- it "can get the root node" do
10
- root_node = @neo.get_root
11
- root_node.should have_key("reference_node")
12
- end
13
- end
14
-
15
- describe "create_node" do
16
- it "can create an empty node" do
17
- new_node = @neo.create_node
18
- new_node.should_not be_nil
19
- end
20
- end
21
- end