neography 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
data/.project CHANGED
@@ -5,6 +5,11 @@
5
5
  <projects>
6
6
  </projects>
7
7
  <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
8
13
  </buildSpec>
9
14
  <natures>
10
15
  <nature>com.aptana.ruby.core.rubynature</nature>
data/CONTRIBUTORS CHANGED
@@ -9,4 +9,8 @@ Contributors:
9
9
  * Stephen Becker IV
10
10
  * Thomas Baum
11
11
  * Maximilian Schulz
12
- * Hesham Amiri
12
+ * Hesham Amiri
13
+ * Pablo Fernandez
14
+ * Nick Reavill
15
+ * Marcel Sherf
16
+ * David Pitman
data/Gemfile.lock CHANGED
@@ -1,10 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neography (0.0.19)
5
- httparty (= 0.7.8)
4
+ neography (0.0.20)
5
+ crack (= 0.1.8)
6
+ httparty (= 0.8.1)
6
7
  json
7
8
  os
9
+ rake (>= 0.8.7)
8
10
  rubyzip
9
11
 
10
12
  GEM
@@ -12,9 +14,12 @@ GEM
12
14
  specs:
13
15
  crack (0.1.8)
14
16
  diff-lcs (1.1.3)
15
- httparty (0.7.8)
16
- crack (= 0.1.8)
17
+ httparty (0.8.1)
18
+ multi_json
19
+ multi_xml
17
20
  json (1.6.4)
21
+ multi_json (1.0.4)
22
+ multi_xml (0.4.1)
18
23
  net-http-spy (0.2.1)
19
24
  os (0.9.5)
20
25
  rake (0.8.7)
data/README.rdoc CHANGED
@@ -7,8 +7,10 @@ Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
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 by Andreas Ronge
8
8
 
9
9
  Complement to Neography are the:
10
- Neology Gem at https://github.com/lordkada/neology by Carlo Alberto Degli Atti
11
- Neoid Gem at https://github.com/elado/neoid by Elad Ossadon
10
+
11
+ * {Neo4j Active Record Adapter}[https://github.com/yournextleap/activerecord-neo4j-adapter] by Nikhil Lanjewar
12
+ * {Neology}[https://github.com/lordkada/neology] by Carlo Alberto Degli Atti
13
+ * {Neoid}[https://github.com/elado/neoid] by Elad Ossadon
12
14
 
13
15
  An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz
14
16
 
@@ -72,7 +74,9 @@ If you are not using Rails, then add:
72
74
 
73
75
  require 'neography/tasks'
74
76
 
75
- to your Rakefile to have access to these tasks.
77
+ to your Rakefile to have access to these tasks.
78
+
79
+ rake neo4j:install requires wget to be installed. It will download and install Neo4j into a neo4j directory in your project regardless of what version you choose.
76
80
 
77
81
 
78
82
  === Documentation
@@ -189,6 +193,8 @@ To Use:
189
193
  [:set_node_property, node2, {"name" => "Jerry"}] # Sets the property of two nodes
190
194
  @neo.batch [:create_unique_node, index_name, key, value,
191
195
  {"age" => 33, "name" => "Max"}] # Creates a unique node
196
+ @neo.batch [:get_node_relationships, node1, "out",
197
+ [:get_node_relationships, node2, "out"] # Get node relationships in a batch
192
198
  @neo.batch [:get_relationship, rel1],
193
199
  [:get_relationship, rel2] # Gets two relationships in a batch
194
200
  @neo.batch [:create_relationship, "friends",
@@ -272,6 +278,7 @@ The Neo4j ID is available by using node.neo_id .
272
278
  new_rel.start_node # Get the start/from node of a relationship
273
279
  new_rel.end_node # Get the end/to node of a relationship
274
280
  new_rel.other_node(n2) # Get the other node of a relationship
281
+ new_rel.attributes # Get the attributes of the relationship as an array
275
282
 
276
283
  existing_rel = Neography::Relationship.load(12) # Get an existing relationship by id
277
284
  existing_rel.del # Delete a relationship
@@ -341,6 +348,26 @@ Phase 2 way of doing these:
341
348
  * {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook_v2.rb]
342
349
  * {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin_v2.rb]
343
350
 
351
+ === Testing
352
+
353
+ To run testing locally you will need to have two instances of the server running. There is some
354
+ good advice on how to set up the a second instance on the
355
+ {neo4j site}[http://docs.neo4j.org/chunked/stable/server-installation.html#_multiple_server_instances_on_one_machine].
356
+ Connect to the second instance in your testing environment, for example:
357
+
358
+ if Rails.env.development?
359
+ @neo = Neography::Rest.new({:port => 7474})
360
+ elsif Rails.env.test?
361
+ @neo = Neography::Rest.new({:port => 7475})
362
+ end
363
+
364
+ Install the test-delete-db-extension plugin, as mentioned in the neo4j.org docs, if you want to use
365
+ the Rest clean_database method to empty your database between tests. In Rspec, for example,
366
+ put this in your spec_helper.rb:
367
+
368
+ config.before(:each) do
369
+ @neo.clean_database("yes_i_really_want_to_clean_the_database")
370
+ end
344
371
 
345
372
  === To Do
346
373
 
data/lib/neography.rb CHANGED
@@ -16,6 +16,7 @@ end
16
16
  DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]
17
17
 
18
18
  require 'cgi'
19
+ require 'crack'
19
20
  require 'httparty'
20
21
  require 'json'
21
22
  require 'logger'
@@ -23,6 +24,7 @@ require 'ostruct'
23
24
  require 'os'
24
25
  require 'zip/zipfilesystem'
25
26
 
27
+ require 'neography/crack_parser'
26
28
  require 'neography/config'
27
29
  require 'neography/rest'
28
30
  require 'neography/neography'
@@ -1,6 +1,6 @@
1
1
  module Neography
2
2
  class Config
3
- class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end
3
+ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end
4
4
 
5
5
  @protocol = 'http://'
6
6
  @server = 'localhost'
@@ -15,5 +15,6 @@ module Neography
15
15
  @authentication = {}
16
16
  @username = nil
17
17
  @password = nil
18
+ @parser = {:parser => CrackParser}
18
19
  end
19
20
  end
@@ -0,0 +1,7 @@
1
+ class CrackParser < HTTParty::Parser
2
+
3
+ protected
4
+ def json
5
+ Crack::JSON.parse(body)
6
+ end
7
+ end
@@ -55,6 +55,11 @@ module Neography
55
55
  def exist?
56
56
  !self.start_node.neo_server.get_relationship(self.neo_id).nil?
57
57
  end
58
+
59
+ def attributes
60
+ attrs = self.methods - OpenStruct.instance_methods - Neography::Relationship.instance_methods
61
+ attrs.values_at(*attrs.each_index.select {|i| i.even?})
62
+ end
58
63
 
59
64
  def other_node(node)
60
65
  if node == @start_node
@@ -65,4 +70,4 @@ module Neography
65
70
  end
66
71
 
67
72
  end
68
- end
73
+ end
@@ -1,8 +1,9 @@
1
1
  module Neography
2
+
2
3
  class Rest
3
4
  include HTTParty
4
-
5
- attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password
5
+
6
+ attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser
6
7
 
7
8
  def initialize(options=ENV['NEO4J_URL'] || {})
8
9
  init = {:protocol => Neography::Config.protocol,
@@ -16,7 +17,9 @@ module Neography
16
17
  :max_threads => Neography::Config.max_threads,
17
18
  :authentication => Neography::Config.authentication,
18
19
  :username => Neography::Config.username,
19
- :password => Neography::Config.password}
20
+ :password => Neography::Config.password,
21
+ :parser => Neography::Config.parser
22
+ }
20
23
 
21
24
  unless options.respond_to?(:each_pair)
22
25
  url = URI.parse(options)
@@ -44,6 +47,7 @@ module Neography
44
47
  @max_threads = init[:max_threads]
45
48
  @authentication = Hash.new
46
49
  @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
50
+ @parser = init[:parser]
47
51
  end
48
52
 
49
53
  def configure(protocol, server, port, directory)
@@ -382,6 +386,17 @@ module Neography
382
386
  options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
383
387
  post("/batch", options)
384
388
  end
389
+
390
+ # For testing (use a separate neo4j instance)
391
+ # call this before each test or spec
392
+ def clean_database(sanity_check = "not_really")
393
+ if sanity_check == "yes_i_really_want_to_clean_the_database"
394
+ delete("/cleandb/secret-key")
395
+ true
396
+ else
397
+ false
398
+ end
399
+ end
385
400
 
386
401
  private
387
402
 
@@ -415,6 +430,10 @@ module Neography
415
430
  {:method => "GET", :to => "/index/node/#{args[1]}/#{args[2]}/#{args[3]}"}
416
431
  when :get_relationship_index
417
432
  {:method => "GET", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{args[3]}"}
433
+ when :get_node_relationships
434
+ {:method => "GET", :to => "/node/#{get_id(args[1])}/relationships/#{args[2] || 'all'}"}
435
+ else
436
+ raise "Unknown option #{args[0]}"
418
437
  end
419
438
  end
420
439
 
@@ -435,7 +454,7 @@ module Neography
435
454
  @logger.error "Invalid data sent #{body}" if @log_enabled
436
455
  nil
437
456
  when 404
438
- @logger.error "#{body}" if @log_enabled
457
+ @logger.error "Not Found #{body}" if @log_enabled
439
458
  nil
440
459
  when 409
441
460
  @logger.error "Node could not be deleted (still has relationships?)" if @log_enabled
@@ -444,19 +463,19 @@ module Neography
444
463
  end
445
464
 
446
465
  def get(path,options={})
447
- evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication)))
466
+ evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
448
467
  end
449
468
 
450
469
  def post(path,options={})
451
- evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication)))
470
+ evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
452
471
  end
453
472
 
454
473
  def put(path,options={})
455
- evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication)))
474
+ evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
456
475
  end
457
476
 
458
477
  def delete(path,options={})
459
- evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication)))
478
+ evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
460
479
  end
461
480
 
462
481
  def get_id(id)
@@ -4,7 +4,7 @@ require 'os'
4
4
  namespace :neo4j do
5
5
  desc "Install Neo4j"
6
6
  task :install, :edition, :version do |t, args|
7
- args.with_defaults(:edition => "community", :version => "1.7.M01")
7
+ args.with_defaults(:edition => "community", :version => "1.7.M02")
8
8
  puts "Installing Neo4j-#{args[:edition]}-#{args[:version]}"
9
9
 
10
10
  if OS::Underlying.windows?
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
data/neography.gemspec CHANGED
@@ -21,8 +21,10 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "net-http-spy", "0.2.1"
24
+ s.add_development_dependency "rake", "~> 0.8.7"
25
+ s.add_dependency "crack", "0.1.8"
26
+ s.add_dependency "httparty", "0.8.1"
24
27
  s.add_dependency "rake", ">= 0.8.7"
25
- s.add_dependency "httparty", "~> 0.7.8"
26
28
  s.add_dependency "json"
27
29
  s.add_dependency "os"
28
30
  s.add_dependency "rubyzip"
@@ -311,6 +311,24 @@ describe Neography::Rest do
311
311
  [:add_relationship_to_index, "test_relationship_index", key, value, "{4}"]
312
312
  batch_result.should_not be_nil
313
313
  end
314
+
315
+ it "can get multiple relationships" do
316
+ node1 = @neo.create_node
317
+ node2 = @neo.create_node
318
+ node3 = @neo.create_node
319
+ new_relationship1 = @neo.create_relationship("friends", node1, node2)
320
+ new_relationship2 = @neo.create_relationship("brothers", node1, node3)
321
+ batch_result = @neo.batch [:get_node_relationships, node1]
322
+ batch_result.first["body"][0]["type"].should == "friends"
323
+ batch_result.first["body"][0]["start"].split('/').last.should == node1["self"].split('/').last
324
+ batch_result.first["body"][0]["end"].split('/').last.should == node2["self"].split('/').last
325
+ batch_result.first["body"][0]["self"].should == new_relationship1["self"]
326
+ batch_result.first["body"][1]["type"].should == "brothers"
327
+ batch_result.first["body"][1]["start"].split('/').last.should == node1["self"].split('/').last
328
+ batch_result.first["body"][1]["end"].split('/').last.should == node3["self"].split('/').last
329
+ batch_result.first["body"][1]["self"].should == new_relationship2["self"]
330
+ end
331
+
314
332
  end
315
333
 
316
334
  end
metadata CHANGED
@@ -1,100 +1,167 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: neography
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.24
3
+ version: !ruby/object:Gem::Version
4
+ hash: 45
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 25
10
+ version: 0.0.25
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Max De Marzi
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-03-22 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-04-04 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rspec
16
- requirement: &81537140 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
22
32
  type: :development
23
- prerelease: false
24
- version_requirements: *81537140
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: net-http-spy
27
- requirement: &81536810 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - =
31
- - !ruby/object:Gem::Version
39
+ requirements:
40
+ - - "="
41
+ - !ruby/object:Gem::Version
42
+ hash: 21
43
+ segments:
44
+ - 0
45
+ - 2
46
+ - 1
32
47
  version: 0.2.1
33
48
  type: :development
34
- prerelease: false
35
- version_requirements: *81536810
36
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
37
51
  name: rake
38
- requirement: &81536470 !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 49
59
+ segments:
60
+ - 0
61
+ - 8
62
+ - 7
43
63
  version: 0.8.7
44
- type: :runtime
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: crack
45
68
  prerelease: false
46
- version_requirements: *81536470
47
- - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - "="
73
+ - !ruby/object:Gem::Version
74
+ hash: 11
75
+ segments:
76
+ - 0
77
+ - 1
78
+ - 8
79
+ version: 0.1.8
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
48
83
  name: httparty
49
- requirement: &81535920 !ruby/object:Gem::Requirement
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
50
86
  none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.7.8
87
+ requirements:
88
+ - - "="
89
+ - !ruby/object:Gem::Version
90
+ hash: 61
91
+ segments:
92
+ - 0
93
+ - 8
94
+ - 1
95
+ version: 0.8.1
55
96
  type: :runtime
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
56
100
  prerelease: false
57
- version_requirements: *81535920
58
- - !ruby/object:Gem::Dependency
59
- name: json
60
- requirement: &81535730 !ruby/object:Gem::Requirement
101
+ requirement: &id006 !ruby/object:Gem::Requirement
61
102
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 49
107
+ segments:
108
+ - 0
109
+ - 8
110
+ - 7
111
+ version: 0.8.7
66
112
  type: :runtime
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: json
67
116
  prerelease: false
68
- version_requirements: *81535730
69
- - !ruby/object:Gem::Dependency
70
- name: os
71
- requirement: &81518230 !ruby/object:Gem::Requirement
117
+ requirement: &id007 !ruby/object:Gem::Requirement
72
118
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
77
126
  type: :runtime
127
+ version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: os
78
130
  prerelease: false
79
- version_requirements: *81518230
80
- - !ruby/object:Gem::Dependency
81
- name: rubyzip
82
- requirement: &81517920 !ruby/object:Gem::Requirement
131
+ requirement: &id008 !ruby/object:Gem::Requirement
83
132
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
88
140
  type: :runtime
141
+ version_requirements: *id008
142
+ - !ruby/object:Gem::Dependency
143
+ name: rubyzip
89
144
  prerelease: false
90
- version_requirements: *81517920
91
- description: A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/
92
- for more details.
145
+ requirement: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ type: :runtime
155
+ version_requirements: *id009
156
+ description: A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/ for more details.
93
157
  email: maxdemarzi@gmail.com
94
158
  executables: []
159
+
95
160
  extensions: []
161
+
96
162
  extra_rdoc_files: []
97
- files:
163
+
164
+ files:
98
165
  - .gitignore
99
166
  - .project
100
167
  - .travis.yml
@@ -113,6 +180,7 @@ files:
113
180
  - examples/traversal_example2.rb
114
181
  - lib/neography.rb
115
182
  - lib/neography/config.rb
183
+ - lib/neography/crack_parser.rb
116
184
  - lib/neography/equal.rb
117
185
  - lib/neography/index.rb
118
186
  - lib/neography/neography.rb
@@ -150,26 +218,36 @@ files:
150
218
  - spec/spec_helper.rb
151
219
  homepage: http://rubygems.org/gems/neography
152
220
  licenses: []
221
+
153
222
  post_install_message:
154
223
  rdoc_options: []
155
- require_paths:
224
+
225
+ require_paths:
156
226
  - lib
157
- required_ruby_version: !ruby/object:Gem::Requirement
227
+ required_ruby_version: !ruby/object:Gem::Requirement
158
228
  none: false
159
- requirements:
160
- - - ! '>='
161
- - !ruby/object:Gem::Version
162
- version: '0'
163
- required_rubygems_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ hash: 3
233
+ segments:
234
+ - 0
235
+ version: "0"
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
237
  none: false
165
- requirements:
166
- - - ! '>='
167
- - !ruby/object:Gem::Version
168
- version: '0'
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ hash: 3
242
+ segments:
243
+ - 0
244
+ version: "0"
169
245
  requirements: []
246
+
170
247
  rubyforge_project: neography
171
- rubygems_version: 1.8.10
248
+ rubygems_version: 1.8.17
172
249
  signing_key:
173
250
  specification_version: 3
174
251
  summary: ruby wrapper to Neo4j Rest API
175
252
  test_files: []
253
+