neography 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/README.md +7 -2
- data/lib/neography.rb +1 -1
- data/lib/neography/config.rb +1 -1
- data/lib/neography/connection.rb +20 -10
- data/lib/neography/multi_json_parser.rb +2 -3
- data/lib/neography/rest.rb +0 -1
- data/lib/neography/tasks.rb +2 -2
- data/lib/neography/version.rb +1 -1
- data/neography.gemspec +2 -1
- data/spec/integration/rest_header_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/config_spec.rb +2 -2
- data/spec/unit/connection_spec.rb +23 -24
- metadata +21 -5
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Neography
|
2
|
+
=========
|
3
|
+
|
4
|
+
- [](https://rubygems.org/gems/neography)
|
5
|
+
- [](http://travis-ci.org/maxdemarzi/neography)
|
6
|
+
- [](https://codeclimate.com/github/maxdemarzi/neography)
|
7
|
+
- [](https://coveralls.io/r/maxdemarzi/neography)
|
3
8
|
|
4
9
|
## Welcome to Neography
|
5
10
|
|
data/lib/neography.rb
CHANGED
data/lib/neography/config.rb
CHANGED
data/lib/neography/connection.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Neography
|
2
2
|
class Connection
|
3
|
-
|
4
3
|
USER_AGENT = "Neography/#{Neography::VERSION}"
|
5
4
|
|
6
5
|
attr_accessor :protocol, :server, :port, :directory,
|
@@ -8,11 +7,12 @@ module Neography
|
|
8
7
|
:log_file, :log_enabled, :logger,
|
9
8
|
:max_threads,
|
10
9
|
:authentication, :username, :password,
|
11
|
-
:parser
|
10
|
+
:parser, :client
|
12
11
|
|
13
12
|
def initialize(options = ENV['NEO4J_URL'] || {})
|
14
13
|
config = merge_configuration(options)
|
15
14
|
save_local_configuration(config)
|
15
|
+
@client = HTTPClient.new
|
16
16
|
end
|
17
17
|
|
18
18
|
def configure(protocol, server, port, directory)
|
@@ -27,27 +27,37 @@ module Neography
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def merge_options(options)
|
30
|
-
merged_options = options.merge!(@authentication)
|
30
|
+
merged_options = options.merge!(@authentication)#.merge!(@parser)
|
31
31
|
merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
|
32
32
|
merged_options
|
33
33
|
end
|
34
34
|
|
35
35
|
def get(path, options={})
|
36
|
-
|
36
|
+
authenticate(configuration + path)
|
37
|
+
evaluate_response(@client.get(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
|
37
38
|
end
|
38
39
|
|
39
40
|
def post(path, options={})
|
40
|
-
|
41
|
+
authenticate(configuration + path)
|
42
|
+
evaluate_response(@client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
|
41
43
|
end
|
42
44
|
|
43
45
|
def put(path, options={})
|
44
|
-
|
46
|
+
authenticate(configuration + path)
|
47
|
+
evaluate_response(@client.put(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
|
45
48
|
end
|
46
49
|
|
47
50
|
def delete(path, options={})
|
48
|
-
|
51
|
+
authenticate(configuration + path)
|
52
|
+
evaluate_response(@client.delete(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
|
49
53
|
end
|
50
54
|
|
55
|
+
def authenticate(path)
|
56
|
+
@client.set_auth(path,
|
57
|
+
@authentication[@authentication.keys.first][:username],
|
58
|
+
@authentication[@authentication.keys.first][:password]) unless @authentication.empty?
|
59
|
+
end
|
60
|
+
|
51
61
|
private
|
52
62
|
|
53
63
|
def merge_configuration(options)
|
@@ -91,10 +101,10 @@ module Neography
|
|
91
101
|
case code
|
92
102
|
when 200
|
93
103
|
@logger.debug "OK" if @log_enabled
|
94
|
-
response.parsed_response
|
104
|
+
@parser.json(body) #response.parsed_response
|
95
105
|
when 201
|
96
106
|
@logger.debug "OK, created #{body}" if @log_enabled
|
97
|
-
response.parsed_response
|
107
|
+
@parser.json(body) #response.parsed_response
|
98
108
|
when 204
|
99
109
|
@logger.debug "OK, no content returned" if @log_enabled
|
100
110
|
nil
|
@@ -110,7 +120,7 @@ module Neography
|
|
110
120
|
message = "No error message returned from server."
|
111
121
|
stacktrace = ""
|
112
122
|
else
|
113
|
-
parsed_body =
|
123
|
+
parsed_body = @parser.json(body)
|
114
124
|
message = parsed_body["message"]
|
115
125
|
stacktrace = parsed_body["stacktrace"]
|
116
126
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
class MultiJsonParser
|
1
|
+
class MultiJsonParser
|
2
2
|
|
3
|
-
protected
|
4
3
|
|
5
4
|
# I know this looks pretty ugly, but we have issues with Neo4j returning true, false,
|
6
5
|
# plain numbers and plain strings, which is considered by some JSON libraries to be
|
@@ -8,7 +7,7 @@ class MultiJsonParser < HTTParty::Parser
|
|
8
7
|
# This ugly hack deals with the problem. Send me a Pull Request if you
|
9
8
|
# come up with a nicer solution... please!
|
10
9
|
#
|
11
|
-
def json
|
10
|
+
def self.json(body)
|
12
11
|
begin
|
13
12
|
MultiJson.load(body)
|
14
13
|
rescue MultiJson::DecodeError, ArgumentError
|
data/lib/neography/rest.rb
CHANGED
data/lib/neography/tasks.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# borrowed from architect4r
|
2
2
|
require 'os'
|
3
|
-
require '
|
3
|
+
require 'httpclient'
|
4
4
|
require 'zip/zip'
|
5
5
|
|
6
6
|
namespace :neo4j do
|
@@ -14,7 +14,7 @@ namespace :neo4j do
|
|
14
14
|
unless File.exist?('neo4j.zip')
|
15
15
|
df = File.open('neo4j.zip', 'wb')
|
16
16
|
begin
|
17
|
-
df <<
|
17
|
+
df << HTTPClient.new.get("http://dist.neo4j.org/neo4j-#{args[:edition]}-#{args[:version]}-windows.zip")
|
18
18
|
ensure
|
19
19
|
df.close()
|
20
20
|
end
|
data/lib/neography/version.rb
CHANGED
data/neography.gemspec
CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "rspec", ">= 2.11"
|
23
23
|
s.add_development_dependency "net-http-spy", "0.2.1"
|
24
24
|
s.add_development_dependency "rake", ">= 0.8.7"
|
25
|
-
s.
|
25
|
+
s.add_development_dependency "coveralls"
|
26
|
+
s.add_dependency "httpclient", ">= 2.3.3"
|
26
27
|
s.add_dependency "rake", ">= 0.8.7"
|
27
28
|
s.add_dependency "json", ">= 1.6.0"
|
28
29
|
s.add_dependency "os", ">= 0.9.6"
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Neography::Connection do
|
4
4
|
|
5
5
|
it "should not add a content-type header if there's no existing headers" do
|
6
|
-
subject.merge_options({}).keys.should == [
|
6
|
+
subject.merge_options({}).keys.should == []
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should add a content type if there's existing headers" do
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/config_spec.rb
CHANGED
@@ -19,7 +19,7 @@ module Neography
|
|
19
19
|
its(:authentication) { should == nil }
|
20
20
|
its(:username) { should == nil }
|
21
21
|
its(:password) { should == nil }
|
22
|
-
its(:parser) { should ==
|
22
|
+
its(:parser) { should == MultiJsonParser}
|
23
23
|
|
24
24
|
it "has a hash representation" do
|
25
25
|
expected_hash = {
|
@@ -35,7 +35,7 @@ module Neography
|
|
35
35
|
:authentication => nil,
|
36
36
|
:username => nil,
|
37
37
|
:password => nil,
|
38
|
-
:parser =>
|
38
|
+
:parser => MultiJsonParser
|
39
39
|
}
|
40
40
|
config.to_hash.should == expected_hash
|
41
41
|
end
|
@@ -78,22 +78,22 @@ module Neography
|
|
78
78
|
context "requests" do
|
79
79
|
|
80
80
|
it "does a GET request" do
|
81
|
-
|
81
|
+
connection.client.should_receive(:get).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
|
82
82
|
connection.get("/foo/bar")
|
83
83
|
end
|
84
84
|
|
85
85
|
it "does a POST request" do
|
86
|
-
|
86
|
+
connection.client.should_receive(:post).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
|
87
87
|
connection.post("/foo/bar")
|
88
88
|
end
|
89
89
|
|
90
90
|
it "does a PUT request" do
|
91
|
-
|
91
|
+
connection.client.should_receive(:put).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
|
92
92
|
connection.put("/foo/bar")
|
93
93
|
end
|
94
94
|
|
95
95
|
it "does a DELETE request" do
|
96
|
-
|
96
|
+
connection.client.should_receive(:delete).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
|
97
97
|
connection.delete("/foo/bar")
|
98
98
|
end
|
99
99
|
|
@@ -107,25 +107,24 @@ module Neography
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it "does requests with authentication" do
|
110
|
-
|
110
|
+
connection.client.should_receive(:set_auth).with(
|
111
111
|
"http://localhost:7474/db/data/foo/bar",
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
"foo",
|
113
|
+
"bar") { stub.as_null_object }
|
114
|
+
|
115
|
+
connection.client.should_receive(:get).with(
|
116
|
+
"http://localhost:7474/db/data/foo/bar", nil, nil
|
117
|
+
) { stub.as_null_object }
|
118
118
|
|
119
119
|
connection.get("/foo/bar")
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
it "adds the User-Agent to the headers" do
|
124
|
-
|
124
|
+
connection.client.should_receive(:get).with(
|
125
125
|
"http://localhost:7474/db/data/foo/bar",
|
126
|
-
{
|
127
|
-
|
128
|
-
}) { stub.as_null_object }
|
126
|
+
nil, { "User-Agent" => "Neography/#{Neography::VERSION}" }
|
127
|
+
) { stub.as_null_object }
|
129
128
|
|
130
129
|
connection.get("/foo/bar", :headers => {})
|
131
130
|
end
|
@@ -134,7 +133,7 @@ module Neography
|
|
134
133
|
|
135
134
|
it "raises NodeNotFoundException" do
|
136
135
|
response = error_response(code: 404, message: "a message", exception: "NodeNotFoundException")
|
137
|
-
|
136
|
+
connection.client.stub(:get).and_return(response)
|
138
137
|
expect {
|
139
138
|
connection.get("/foo/bar")
|
140
139
|
}.to raise_error NodeNotFoundException
|
@@ -142,7 +141,7 @@ module Neography
|
|
142
141
|
|
143
142
|
it "raises OperationFailureException" do
|
144
143
|
response = error_response(code: 409, message: "a message", exception: "OperationFailureException")
|
145
|
-
|
144
|
+
connection.client.stub(:get).and_return(response)
|
146
145
|
expect {
|
147
146
|
connection.get("/foo/bar")
|
148
147
|
}.to raise_error OperationFailureException
|
@@ -150,7 +149,7 @@ module Neography
|
|
150
149
|
|
151
150
|
it "raises PropertyValueException" do
|
152
151
|
response = error_response(code: 400, message: "a message", exception: "PropertyValueException")
|
153
|
-
|
152
|
+
connection.client.stub(:get).and_return(response)
|
154
153
|
expect {
|
155
154
|
connection.get("/foo/bar")
|
156
155
|
}.to raise_error PropertyValueException
|
@@ -158,7 +157,7 @@ module Neography
|
|
158
157
|
|
159
158
|
it "raises NoSuchPropertyException" do
|
160
159
|
response = error_response(code: 404, message: "a message", exception: "NoSuchPropertyException")
|
161
|
-
|
160
|
+
connection.client.stub(:get).and_return(response)
|
162
161
|
expect {
|
163
162
|
connection.get("/foo/bar")
|
164
163
|
}.to raise_error NoSuchPropertyException
|
@@ -166,7 +165,7 @@ module Neography
|
|
166
165
|
|
167
166
|
it "raises RelationshipNotFoundException" do
|
168
167
|
response = error_response(code: 404, message: "a message", exception: "RelationshipNotFoundException")
|
169
|
-
|
168
|
+
connection.client.stub(:get).and_return(response)
|
170
169
|
expect {
|
171
170
|
connection.get("/foo/bar")
|
172
171
|
}.to raise_error RelationshipNotFoundException
|
@@ -174,7 +173,7 @@ module Neography
|
|
174
173
|
|
175
174
|
it "raises BadInputException" do
|
176
175
|
response = error_response(code: 400, message: "a message", exception: "BadInputException")
|
177
|
-
|
176
|
+
connection.client.stub(:get).and_return(response)
|
178
177
|
expect {
|
179
178
|
connection.get("/foo/bar")
|
180
179
|
}.to raise_error BadInputException
|
@@ -182,7 +181,7 @@ module Neography
|
|
182
181
|
|
183
182
|
it "raises UnauthorizedError" do
|
184
183
|
response = error_response(code: 401)
|
185
|
-
|
184
|
+
connection.client.stub(:get).and_return(response)
|
186
185
|
expect {
|
187
186
|
connection.get("/foo/bar")
|
188
187
|
}.to raise_error UnauthorizedError
|
@@ -190,7 +189,7 @@ module Neography
|
|
190
189
|
|
191
190
|
it "raises NeographyError in all other cases" do
|
192
191
|
response = error_response(code: 418, message: "I'm a teapot.")
|
193
|
-
|
192
|
+
connection.client.stub(:get).and_return(response)
|
194
193
|
expect {
|
195
194
|
connection.get("/foo/bar")
|
196
195
|
}.to raise_error NeographyError
|
@@ -198,7 +197,7 @@ module Neography
|
|
198
197
|
|
199
198
|
it "raises BadInputException" do
|
200
199
|
response = error_response(code: 500, message: "a message", exception: "JsonParseException")
|
201
|
-
|
200
|
+
connection.client.stub(:get).and_return(response)
|
202
201
|
expect {
|
203
202
|
connection.get("/foo/bar")
|
204
203
|
}.to raise_error NeographyError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -60,13 +60,29 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.7
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: coveralls
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: httpclient
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.3.3
|
70
86
|
type: :runtime
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ! '>='
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
93
|
+
version: 2.3.3
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: rake
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|