neo4jr-social 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -9
- data/Rakefile +11 -8
- data/VERSION +1 -1
- data/config/warble.rb +4 -4
- data/jetty-runtime/webapps/neo4jr-social.war +0 -0
- data/lib/neo4jr-social.rb +1 -1
- data/lib/neo4jr-social/format_handler.rb +4 -4
- data/lib/neo4jr-social/self_documentor.rb +1 -1
- data/lib/neo4jr-social/service.rb +12 -11
- data/neo4jr-social.gemspec +11 -12
- data/spec/service_spec.rb +15 -1
- metadata +10 -10
data/README.rdoc
CHANGED
@@ -10,6 +10,43 @@ Neo4jr-Social was built in JRuby but is language agnostic and is designed to run
|
|
10
10
|
|
11
11
|
* Java
|
12
12
|
* JRuby: http://jruby.org
|
13
|
+
* sudo aptitude install jruby1.2 rake rubygems
|
14
|
+
|
15
|
+
=== Building
|
16
|
+
|
17
|
+
* install rvm (see http://rvm.beginrescueend.com/rvm/install/)
|
18
|
+
|
19
|
+
Once done, use rvm to install latest jruby and required gems
|
20
|
+
|
21
|
+
* rvm install jruby
|
22
|
+
* rvm use --default jruby
|
23
|
+
* gem install jruby-openssl
|
24
|
+
* gem install rake
|
25
|
+
* gem install rspec
|
26
|
+
* gem install test-client
|
27
|
+
* gem install rack-test
|
28
|
+
* gem install json-jruby -v 1.4.1
|
29
|
+
* gem install jeweler
|
30
|
+
* gem install warbler
|
31
|
+
* gem install rcov
|
32
|
+
|
33
|
+
Building the code and documentation
|
34
|
+
|
35
|
+
* rake -T # optional, lists possible tasks
|
36
|
+
* rake gemspec
|
37
|
+
* rake rcov --debug
|
38
|
+
* rake rdoc
|
39
|
+
* rake warify
|
40
|
+
* rake build
|
41
|
+
|
42
|
+
Or short version (without documentation)
|
43
|
+
|
44
|
+
* rake gemspec warify build
|
45
|
+
|
46
|
+
=== Installing
|
47
|
+
Install Ruby Gem: neo4jr-social
|
48
|
+
|
49
|
+
* gem install neo4jr-social
|
13
50
|
|
14
51
|
== Running Neo4jr-Social
|
15
52
|
|
@@ -23,17 +60,12 @@ You can also start the service and specify the directory of where the neo4j data
|
|
23
60
|
|
24
61
|
Run start-neo4jr-social --help to see all options
|
25
62
|
|
26
|
-
=== API
|
27
|
-
|
28
|
-
The service is documented at http://wiki.github.com/mdeiters/neo4jr-social/
|
29
|
-
|
30
63
|
== Contributors
|
31
64
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
* Blog : http://www.theagiledeveloper.com
|
65
|
+
https://github.com/mdeiters
|
66
|
+
https://github.com/klobuczek
|
67
|
+
https://github.com/gregormelhorn
|
68
|
+
https://github.com/mikkorantalainen
|
37
69
|
|
38
70
|
== Copyright
|
39
71
|
|
data/Rakefile
CHANGED
@@ -8,16 +8,17 @@ begin
|
|
8
8
|
Jeweler::Tasks.new do |gem|
|
9
9
|
gem.name = "neo4jr-social"
|
10
10
|
gem.summary = %Q{A self-containted and lightweight REST interface to Neo4j using JRuby.}
|
11
|
-
gem.description = %Q{A self-containted and lightweight REST interface to Neo4j using JRuby.}
|
12
|
-
gem.description = %Q{A self-containted lightweight REST interface to Neo4j using JRuby }
|
13
11
|
gem.email = "matthew_deiters@mckinsey.com"
|
14
12
|
gem.homepage = "http://github.com/mdeiters/neo4jr-social"
|
15
13
|
gem.authors = ["Matthew Deiters"]
|
16
14
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
15
|
gem.add_development_dependency "rest-client"
|
18
|
-
gem.
|
19
|
-
gem.
|
20
|
-
gem.
|
16
|
+
gem.add_development_dependency 'neo4jr-simple', "0.2.2" unless ENV['neo4jr_simple']
|
17
|
+
gem.add_development_dependency 'sinatra', ">= 1.0"
|
18
|
+
gem.add_development_dependency 'json-jruby', ">= 1.4.1"
|
19
|
+
# gem.add_dependency 'neo4jr-simple', "0.2.2" unless ENV['neo4jr_simple']
|
20
|
+
# gem.add_dependency 'sinatra', ">= 1.0"
|
21
|
+
# gem.add_dependency 'json-jruby', ">= 1.4.1"
|
21
22
|
end
|
22
23
|
Jeweler::GemcutterTasks.new
|
23
24
|
rescue LoadError
|
@@ -51,10 +52,12 @@ Rake::RDocTask.new do |rdoc|
|
|
51
52
|
end
|
52
53
|
|
53
54
|
task :warify do
|
55
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
56
|
+
|
54
57
|
commands = ['rm -rf tmp']
|
55
58
|
commands << 'warble'
|
56
|
-
commands << 'rm jetty-runtime/webapps/neo4jr-social.war'
|
57
|
-
commands << '
|
59
|
+
commands << 'rm -f jetty-runtime/webapps/neo4jr-social.war'
|
60
|
+
commands << 'mkdir -p jetty-runtime/webapps/; mv neo4jr-social.war $_'
|
58
61
|
commands.each do |command|
|
59
62
|
STDERR.puts("Executing: #{command}")
|
60
63
|
`#{command}`
|
@@ -65,4 +68,4 @@ namespace :development do
|
|
65
68
|
task :start => :warify do
|
66
69
|
`bin/start-neo4jr-social`
|
67
70
|
end
|
68
|
-
end
|
71
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/config/warble.rb
CHANGED
@@ -3,9 +3,9 @@ Warbler::Config.new do |config|
|
|
3
3
|
config.dirs = %w(lib)
|
4
4
|
config.includes = FileList["config.ru"]
|
5
5
|
|
6
|
-
config.gems
|
7
|
-
config.gems
|
8
|
-
config.gems
|
6
|
+
config.gems << Gem::Dependency.new("sinatra", ">= 1.0")
|
7
|
+
config.gems << Gem::Dependency.new("json-jruby", ">= 1.4.1")
|
8
|
+
config.gems << Gem::Dependency.new("neo4jr-simple", ">= 0.2.2")
|
9
9
|
|
10
10
|
config.gem_dependencies = true
|
11
11
|
config.webxml.booter = :rack
|
@@ -15,4 +15,4 @@ Warbler::Config.new do |config|
|
|
15
15
|
# that you fix these values when running a production server!
|
16
16
|
# config.webxml.jruby.min.runtimes = 2
|
17
17
|
# config.webxml.jruby.max.runtimes = 4
|
18
|
-
end
|
18
|
+
end
|
Binary file
|
data/lib/neo4jr-social.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Neo4jr
|
2
2
|
module FormatHandler
|
3
3
|
def self.registered(app)
|
4
|
-
app.send :
|
4
|
+
app.send :mime_type, :json, 'application/json'
|
5
5
|
app.set :assume_xhr_is_js, true
|
6
6
|
app.helpers self
|
7
7
|
app.before do
|
@@ -25,11 +25,11 @@ module Neo4jr
|
|
25
25
|
|
26
26
|
def format(val=nil)
|
27
27
|
unless val.nil?
|
28
|
-
|
29
|
-
fail "Unknown
|
28
|
+
type = mime_type(val)
|
29
|
+
fail "Unknown mime type #{val}\nTry registering the extension with a mime type" if type.nil?
|
30
30
|
|
31
31
|
@format = val.to_sym
|
32
|
-
response['Content-Type'].sub!(/^[^;]+/,
|
32
|
+
response['Content-Type'].sub!(/^[^;]+/, type)
|
33
33
|
end
|
34
34
|
|
35
35
|
@format
|
@@ -27,7 +27,7 @@ module Neo4jr
|
|
27
27
|
|
28
28
|
def self.route_added(verb, path, proc)
|
29
29
|
if [:get, :post, :put, :delete].include?(verb.downcase.to_sym)
|
30
|
-
document = {:path => path, :description => (@capture || '').to_s}
|
30
|
+
document = {:path => path, :description => verb.upcase.to_sym.to_s + ": " + (@capture || '').to_s}
|
31
31
|
document[:required] = @capture_required_param if @capture_required_param
|
32
32
|
document[:optional] = @capture_optional_param if @capture_optional_param
|
33
33
|
(@@document ||= []) << document
|
@@ -55,16 +55,14 @@ module Neo4jr
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe "
|
59
|
-
|
60
|
-
required_param :type, "this is the type of the relationship, i.e. 'friends'. This can be any string that is sensible in your domain."
|
61
|
-
optional_param "Any other parameters you supply in the body of the POST will be added as properties to the relationship. For example if you were making 'friend' relationships and wanted to add a date since the friendship started you could pass a 'since' parameter in the POST."
|
58
|
+
describe "Returns relationships to other nodes for the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id."
|
59
|
+
optional_param :type, "Specify a type if only certain relationships are of interest"
|
62
60
|
get '/nodes/:node_id/relationships' do
|
63
61
|
relationships = Neo4jr::DB.execute do |neo|
|
64
62
|
node = neo.find_node(param_node_id)
|
65
63
|
if param_relationship_type
|
66
64
|
relationship_type = RelationshipType.instance(param_relationship_type)
|
67
|
-
node.getRelationships(
|
65
|
+
node.getRelationships(relationship_type.to_a).hashify_objects
|
68
66
|
else
|
69
67
|
node.getRelationships.hashify_objects
|
70
68
|
end
|
@@ -72,8 +70,10 @@ module Neo4jr
|
|
72
70
|
relationships.to_json
|
73
71
|
end
|
74
72
|
|
75
|
-
describe "
|
76
|
-
|
73
|
+
describe "Creates a relations for the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id. This is how you designate how two nodes are related to each other."
|
74
|
+
required_param :to, 'This is the node id of the node you want to make a relationship to. This is a one-way relationship. If you want both nodes to be.'
|
75
|
+
required_param :type, "this is the type of the relationship, i.e. 'friends'. This can be any string that is sensible in your domain."
|
76
|
+
optional_param "Any other parameters you supply in the body of the POST will be added as properties to the relationship. For example if you were making 'friend' relationships and wanted to add a date since the friendship started you could pass a 'since' parameter in the POST."
|
77
77
|
post '/nodes/:node_id/relationships' do
|
78
78
|
relationships = Neo4jr::DB.execute do |neo|
|
79
79
|
node = neo.find_node(param_node_id)
|
@@ -90,13 +90,13 @@ module Neo4jr
|
|
90
90
|
required_param :to, "the id of the node that your trying to find a path to from the starting node, :node_id"
|
91
91
|
required_param :type, "the type of relationships between nodes to follow"
|
92
92
|
optional_param :depth, "the maximum degrees of separation to find, the default is 2 degrees. Note: There may be performance impacts if this number is to high."
|
93
|
-
optional_param :direction, "
|
93
|
+
optional_param :direction, "the direction of relationships to follow, the default is 'both'"
|
94
94
|
get '/nodes/:node_id/paths' do
|
95
95
|
paths = Neo4jr::DB.execute do |neo|
|
96
96
|
start_node = neo.find_node(param_node_id)
|
97
97
|
end_node = neo.find_node(param_to_node_id)
|
98
|
-
shortest_path = AllSimplePaths.new(start_node, end_node,
|
99
|
-
to_hash shortest_path.getPaths
|
98
|
+
shortest_path = AllSimplePaths.new(start_node, end_node, relationship_types.first, param_direction)
|
99
|
+
to_hash shortest_path.getPaths(param_depth)
|
100
100
|
end
|
101
101
|
paths.to_json
|
102
102
|
end
|
@@ -104,6 +104,7 @@ module Neo4jr
|
|
104
104
|
describe "This returns the first of the shortest path of two nodes that are connected to each other"
|
105
105
|
required_param :to, "the id of the node that your trying to find a path to from the starting node, :node_id"
|
106
106
|
required_param :type, "the type of relationships between nodes to follow"
|
107
|
+
optional_param :direction, "the direction of relationships to follow, the default is 'both'"
|
107
108
|
get '/nodes/:node_id/shortest_path' do
|
108
109
|
path = Neo4jr::DB.execute do |neo|
|
109
110
|
dijkstra = Dijkstra.new(
|
@@ -113,7 +114,7 @@ module Neo4jr
|
|
113
114
|
Neo4jr::SimpleEvaluator.new,
|
114
115
|
DoubleAdder.new,
|
115
116
|
DoubleComparator.new,
|
116
|
-
|
117
|
+
param_direction,
|
117
118
|
relationship_types)
|
118
119
|
(p=dijkstra.getPath) and {:path => p.map{|n| n.to_hash }, :cost => dijkstra.getCost}
|
119
120
|
end
|
data/neo4jr-social.gemspec
CHANGED
@@ -5,13 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{neo4jr-social}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matthew Deiters"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-06}
|
13
13
|
s.default_executable = %q{start-neo4jr-social}
|
14
|
-
s.description = %q{A self-containted lightweight REST interface to Neo4j using JRuby }
|
15
14
|
s.email = %q{matthew_deiters@mckinsey.com}
|
16
15
|
s.executables = ["start-neo4jr-social"]
|
17
16
|
s.extra_rdoc_files = [
|
@@ -77,22 +76,22 @@ Gem::Specification.new do |s|
|
|
77
76
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
78
77
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
79
78
|
s.add_development_dependency(%q<rest-client>, [">= 0"])
|
80
|
-
s.
|
81
|
-
s.
|
82
|
-
s.
|
79
|
+
s.add_development_dependency(%q<neo4jr-simple>, ["= 0.2.2"])
|
80
|
+
s.add_development_dependency(%q<sinatra>, [">= 1.0"])
|
81
|
+
s.add_development_dependency(%q<json-jruby>, [">= 1.4.1"])
|
83
82
|
else
|
84
83
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
85
84
|
s.add_dependency(%q<rest-client>, [">= 0"])
|
86
|
-
s.add_dependency(%q<neo4jr-simple>, ["= 0.2.
|
87
|
-
s.add_dependency(%q<sinatra>, [">= 0"])
|
88
|
-
s.add_dependency(%q<
|
85
|
+
s.add_dependency(%q<neo4jr-simple>, ["= 0.2.2"])
|
86
|
+
s.add_dependency(%q<sinatra>, [">= 1.0"])
|
87
|
+
s.add_dependency(%q<json-jruby>, [">= 1.4.1"])
|
89
88
|
end
|
90
89
|
else
|
91
90
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
92
91
|
s.add_dependency(%q<rest-client>, [">= 0"])
|
93
|
-
s.add_dependency(%q<neo4jr-simple>, ["= 0.2.
|
94
|
-
s.add_dependency(%q<sinatra>, [">= 0"])
|
95
|
-
s.add_dependency(%q<
|
92
|
+
s.add_dependency(%q<neo4jr-simple>, ["= 0.2.2"])
|
93
|
+
s.add_dependency(%q<sinatra>, [">= 1.0"])
|
94
|
+
s.add_dependency(%q<json-jruby>, [">= 1.4.1"])
|
96
95
|
end
|
97
96
|
end
|
98
97
|
|
data/spec/service_spec.rb
CHANGED
@@ -103,7 +103,21 @@ describe Neo4jr::Service do
|
|
103
103
|
path_to_cruise[2]['name'].should == 'Tina Fey'
|
104
104
|
path_to_cruise[3]['type'].should == 'friends'
|
105
105
|
path_to_cruise[4]['name'].should == 'Tom Cruise'
|
106
|
-
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "uses the direction of paths to follow when given for shortest path" do
|
109
|
+
# only fey to cruise is a friend
|
110
|
+
post "/nodes/#{fey['node_id']}/relationships", { :to => cruise['node_id'], :type => 'friends' }
|
111
|
+
|
112
|
+
get "/nodes/#{cruise['node_id']}/shortest_path?type=friends&to=#{fey['node_id']}&direction=incoming"
|
113
|
+
path_to_fey = response_to_ruby['path']
|
114
|
+
path_to_fey[0]['name'].should == 'Tom Cruise'
|
115
|
+
path_to_fey[1]['type'].should == 'friends'
|
116
|
+
path_to_fey[2]['name'].should == 'Tina Fey'
|
117
|
+
|
118
|
+
get "/nodes/#{cruise['node_id']}/shortest_path?type=friends&to=#{fey['node_id']}&direction=outgoing"
|
119
|
+
last_response.body.should == 'null'
|
120
|
+
end
|
107
121
|
end
|
108
122
|
|
109
123
|
describe 'getting paths between nodes' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4jr-social
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Deiters
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-06-06 00:00:00 -07:00
|
13
13
|
default_executable: start-neo4jr-social
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -34,35 +34,35 @@ dependencies:
|
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: neo4jr-simple
|
37
|
-
type: :
|
37
|
+
type: :development
|
38
38
|
version_requirement:
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - "="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.2.
|
43
|
+
version: 0.2.2
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: sinatra
|
47
|
-
type: :
|
47
|
+
type: :development
|
48
48
|
version_requirement:
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: "0"
|
53
|
+
version: "1.0"
|
54
54
|
version:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
type: :
|
56
|
+
name: json-jruby
|
57
|
+
type: :development
|
58
58
|
version_requirement:
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: 1.4.1
|
64
64
|
version:
|
65
|
-
description:
|
65
|
+
description:
|
66
66
|
email: matthew_deiters@mckinsey.com
|
67
67
|
executables:
|
68
68
|
- start-neo4jr-social
|