neography 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 581fe5af6cd93c2dfeced6167fdf507c41dd508e
4
- data.tar.gz: a2cbef7d720a7988035fc199e89516ee7acce42d
3
+ metadata.gz: 8cb990bec3b2c9e7a9134d22360940ddd1e7f839
4
+ data.tar.gz: 39b4c012fbc1cb3281681c101987a3a0ec8a6f7f
5
5
  SHA512:
6
- metadata.gz: e51373c2a7cbe9a45b740f9ae8ac2af1d7738c5d3b4b2a00d977b6137b68df2a1fd3e15e118687ce19ac2f2d39eab7efac785697bc059ad5fc8cf998534b4082
7
- data.tar.gz: 91544b56b7f1f4d69ce9d0fadc438f4591721654176cb586ad8ddcd9a5b98d38697ab3f75dcfcf7d1358c94c30a613c5708f76164aef14e0e6f3e17f5d129cf4
6
+ metadata.gz: 837ea1e306b28344ac8474ae5624476191bd4506f53aa9c6ea2375b91d2e13119a4ae2986af0d2edc472abc765e85b5e316cfc37604292ad51f75c62ac699846
7
+ data.tar.gz: baa0fda9441fc33e46b0123b4ba3f34350dcfbf138755fef003c03fca980932f7a04fb89b88d27337b5c158062b52b0188336013a189320f13ab0d9a353cd880
@@ -6,7 +6,7 @@ module Neography
6
6
  :log_file, :log_enabled, :slow_log_threshold,
7
7
  :max_threads,
8
8
  :authentication, :username, :password,
9
- :parser
9
+ :parser, :max_execution_time
10
10
 
11
11
  def initialize
12
12
  set_defaults
@@ -27,7 +27,8 @@ module Neography
27
27
  :authentication => @authentication,
28
28
  :username => @username,
29
29
  :password => @password,
30
- :parser => @parser
30
+ :parser => @parser,
31
+ :max_execution_time => @max_execution_time
31
32
  }
32
33
  end
33
34
 
@@ -48,6 +49,7 @@ module Neography
48
49
  @username = nil
49
50
  @password = nil
50
51
  @parser = MultiJsonParser
52
+ @max_execution_time = 6000
51
53
  end
52
54
 
53
55
  end
@@ -29,22 +29,24 @@ module Neography
29
29
  end
30
30
 
31
31
  def configuration
32
- @configuration ||= "#{@protocol}#{@server}:#{@port}#{@directory}/db/data"
32
+ @configuration ||= "#{@protocol}#{@server}:#{@port}#{@directory}"
33
33
  end
34
34
 
35
35
  def merge_options(options)
36
36
  merged_options = options.merge!(@authentication)
37
37
  merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
38
38
  merged_options[:headers].merge!('X-Stream' => true) if merged_options[:headers]
39
+ merged_options[:headers].merge!(@max_execution_time) if merged_options[:headers]
39
40
  merged_options
40
41
  end
41
42
 
42
43
  ACTIONS.each do |action|
43
- define_method(action) do |path, options = {}|
44
- query_path = configuration + path
44
+ define_method(action) do |path, options = {}|
45
+ base = path.start_with?("/unmanaged") ? "" : "/db/data"
46
+ query_path = configuration + base + path
45
47
  query_body = merge_options(options)[:body]
46
48
  log path, query_body do
47
- evaluate_response(@client.send(action.to_sym, query_path, query_body, merge_options(options)[:headers]))
49
+ evaluate_response(@client.send(action.to_sym, query_path, query_body, merge_options(options)[:headers]), path, query_body)
48
50
  end
49
51
  end
50
52
  end
@@ -88,6 +90,7 @@ module Neography
88
90
  @max_threads = config[:max_threads]
89
91
  @parser = config[:parser]
90
92
 
93
+ @max_execution_time = { 'max-execution-time' => config[:max_execution_time] }
91
94
  @user_agent = { "User-Agent" => USER_AGENT }
92
95
 
93
96
  @authentication = {}
@@ -110,7 +113,7 @@ module Neography
110
113
  return_result(code, result)
111
114
  end
112
115
 
113
- def evaluate_response(response)
116
+ def evaluate_response(response, path, query_body)
114
117
  if response.http_header.request_uri.request_uri == "/db/data/batch"
115
118
  code, body, parsed = handle_batch(response)
116
119
  else
@@ -118,7 +121,7 @@ module Neography
118
121
  body = response.body.force_encoding("UTF-8")
119
122
  parsed = false
120
123
  end
121
- return_result(response, code, body, parsed)
124
+ return_result(response, code, body, parsed, path, query_body)
122
125
  end
123
126
 
124
127
  def handle_batch(response)
@@ -133,7 +136,7 @@ module Neography
133
136
  return code, body, true
134
137
  end
135
138
 
136
- def return_result(response, code, body, parsed)
139
+ def return_result(response, code, body, parsed, path, query_body)
137
140
  case code
138
141
  when 200
139
142
  @logger.debug "OK, created #{body}" if @log_enabled
@@ -147,20 +150,23 @@ module Neography
147
150
  @logger.debug "OK, no content returned" if @log_enabled
148
151
  nil
149
152
  when 400..500
150
- handle_4xx_500_response(response, code, body)
153
+ handle_4xx_500_response(response, code, body, path, query_body)
151
154
  nil
152
155
  end
153
156
  end
154
157
 
155
- def handle_4xx_500_response(response, code, body)
158
+ def handle_4xx_500_response(response, code, body, path, query_body)
159
+ index = 0
160
+ request = {:path => path, :body => query_body}
156
161
  if body.nil? or body == ""
157
162
  parsed_body = {"message" => "No error message returned from server.",
158
163
  "stacktrace" => "No stacktrace returned from server." }
159
164
  elsif body.is_a? Hash
160
165
  parsed_body = body
161
166
  elsif body.is_a? Array
162
- body.each do |result|
167
+ body.each_with_index do |result, idx|
163
168
  if result["status"] >= 400
169
+ index = idx
164
170
  parsed_body = result["body"] || result
165
171
  break
166
172
  end
@@ -173,10 +179,10 @@ module Neography
173
179
  stacktrace = parsed_body["stacktrace"]
174
180
 
175
181
  @logger.error "#{response.dump} error: #{body}" if @log_enabled
176
- raise_errors(code, parsed_body["exception"], message, stacktrace)
182
+ raise_errors(code, parsed_body["exception"], message, stacktrace, request, index)
177
183
  end
178
184
 
179
- def raise_errors(code, exception, message, stacktrace)
185
+ def raise_errors(code, exception, message, stacktrace, request, index)
180
186
  error = nil
181
187
  case code
182
188
  when 401
@@ -199,7 +205,7 @@ module Neography
199
205
  NeographyError
200
206
  end
201
207
 
202
- raise error.new(message, code, stacktrace)
208
+ raise error.new(message, code, stacktrace, request, index)
203
209
  end
204
210
 
205
211
  def parse_string_options(options)
@@ -1,12 +1,14 @@
1
1
  module Neography
2
2
 
3
3
  class NeographyError < StandardError
4
- attr_reader :message, :code, :stacktrace
4
+ attr_reader :message, :code, :stacktrace, :request, :index
5
5
 
6
- def initialize(message = nil, code = nil, stacktrace = nil)
6
+ def initialize(message = nil, code = nil, stacktrace = nil, request = nil, index = 0)
7
7
  @message = message
8
8
  @code = code
9
9
  @stacktrace = stacktrace
10
+ @request = request
11
+ @index = index
10
12
  end
11
13
  end
12
14
 
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "1.3.4"
2
+ VERSION = "1.3.5"
3
3
  end
data/neography.gemspec CHANGED
@@ -22,12 +22,17 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_development_dependency "rspec", ">= 2.11"
24
24
  s.add_development_dependency "net-http-spy", "0.2.1"
25
- s.add_development_dependency "rake", ">= 0.8.7"
26
25
  s.add_development_dependency "coveralls"
27
26
  s.add_dependency "httpclient", ">= 2.3.3"
28
- s.add_dependency "rake", ">= 0.8.7"
29
27
  s.add_dependency "json", ">= 1.7.7"
30
28
  s.add_dependency "os", ">= 0.9.6"
31
- s.add_dependency "rubyzip", "~> 1.0.0"
29
+ s.add_dependency "rubyzip", ">= 1.0.0"
32
30
  s.add_dependency "multi_json", ">= 1.3.2"
31
+
32
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
33
+ s.add_runtime_dependency 'rake', '>= 0.8.7'
34
+ else
35
+ s.add_development_dependency "rake", ">= 0.8.7"
36
+ s.add_dependency "rake", ">= 0.8.7"
37
+ end
33
38
  end
@@ -34,10 +34,11 @@ describe Neography::Index do
34
34
  end
35
35
 
36
36
  it "can find a node in an index with brackets" do
37
+ key = generate_text(6)
37
38
  value = "Sen. Roy Blunt [R-MO]"
38
39
  new_node = Neography::Node.create("name" => value)
39
- new_node.add_to_index("node_test_index", "name", value)
40
- existing_node = Neography::Node.find("node_test_index", "name", value)
40
+ new_node.add_to_index(key, "name", value)
41
+ existing_node = Neography::Node.find(key, "name", value)
41
42
  existing_node.name.should == value
42
43
  end
43
44
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Neography::Rest do
4
4
  before(:each) do
5
- @neo = Neography::Rest.new(:log_enabled => true)
5
+ @neo = Neography::Rest.new
6
6
  end
7
7
 
8
8
  describe "simple batch" do
@@ -482,6 +482,20 @@ describe Neography::Rest do
482
482
  [:create_node, {:street1=>"94437 Kemmer Crossing", :street2=>"Apt. 333", :city=>"Abshireton", :state=>"AA", :zip=>"65820", :_type=>"Address", :created_at=>1335269478}],
483
483
  [:create_relationship, "has", "{0}", "{2}", {}]
484
484
  }.to raise_error(Neography::NeographyError)
485
+
486
+ begin
487
+ batch_result = @neo.batch [:create_unique_node, "person", "ssn", "000-00-0001", {:first_name=>"Jane", :last_name=>"Doe", :ssn=>"000-00-0001", :_type=>"Person", :created_at=>1335269478}],
488
+ [:add_node_to_index, "person_ssn", "ssn", "000-00-0001", "{0}"],
489
+ [:create_node, {:street1=>"94437 Kemmer Crossing", :street2=>"Apt. 333", :city=>"Abshireton", :state=>"AA", :zip=>"65820", :_type=>"Address", :created_at=>1335269478}],
490
+ [:create_relationship, "has", "{0}", "{2}", {}]
491
+ rescue Neography::NeographyError => e
492
+ e.message.should == "Not Found"
493
+ e.code.should == 404
494
+ e.stacktrace.should be_nil
495
+ e.request[:path].should == "/batch"
496
+ e.request[:body].should_not be_nil
497
+ e.index.should == 3
498
+ end
485
499
  end
486
500
 
487
501
  end
@@ -8,7 +8,7 @@ describe Neography::Connection do
8
8
 
9
9
  it "should add a content type if there's existing headers" do
10
10
  subject.merge_options({:headers => {'Content-Type' => 'foo/bar'}})[:headers].should ==
11
- {'Content-Type' => "foo/bar", "User-Agent" => "Neography/#{Neography::VERSION}" , "X-Stream"=>true}
11
+ {'Content-Type' => "foo/bar", "User-Agent" => "Neography/#{Neography::VERSION}" , "X-Stream"=>true, "max-execution-time"=>6000}
12
12
  end
13
13
 
14
14
  end
@@ -30,7 +30,7 @@ describe Neography::Rest do
30
30
  name = generate_text(6)
31
31
  new_index = @neo.create_node_index(name)
32
32
  new_index.should_not be_nil
33
- new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
33
+ new_index["template"].should == "#{@neo.configuration}/db/data/index/node/#{name}/{key}/{value}"
34
34
  new_index["provider"].should == "lucene"
35
35
  new_index["type"].should == "exact"
36
36
  end
@@ -39,7 +39,7 @@ describe Neography::Rest do
39
39
  name = generate_text(6)
40
40
  new_index = @neo.create_node_index(name, "fulltext","lucene")
41
41
  new_index.should_not be_nil
42
- new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
42
+ new_index["template"].should == "#{@neo.configuration}/db/data/index/node/#{name}/{key}/{value}"
43
43
  new_index["provider"].should == "lucene"
44
44
  new_index["type"].should == "fulltext"
45
45
  end
@@ -48,7 +48,7 @@ describe Neography::Rest do
48
48
  name = generate_text(6)
49
49
  new_index = @neo.create_node_index(name, "fulltext","lucene", extra: 'extra-value')
50
50
  new_index.should_not be_nil
51
- new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
51
+ new_index["template"].should == "#{@neo.configuration}/db/data/index/node/#{name}/{key}/{value}"
52
52
  new_index["provider"].should == "lucene"
53
53
  new_index["extra"].should == "extra-value"
54
54
  new_index["type"].should == "fulltext"
@@ -58,7 +58,7 @@ describe Neography::Rest do
58
58
  name = generate_text(6)
59
59
  new_index = @neo.create_relationship_index(name)
60
60
  new_index.should_not be_nil
61
- new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
61
+ new_index["template"].should == "#{@neo.configuration}/db/data/index/relationship/#{name}/{key}/{value}"
62
62
  new_index["provider"].should == "lucene"
63
63
  new_index["type"].should == "exact"
64
64
  end
@@ -67,7 +67,7 @@ describe Neography::Rest do
67
67
  name = generate_text(6)
68
68
  new_index = @neo.create_relationship_index(name, "fulltext","lucene")
69
69
  new_index.should_not be_nil
70
- new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
70
+ new_index["template"].should == "#{@neo.configuration}/db/data/index/relationship/#{name}/{key}/{value}"
71
71
  new_index["provider"].should == "lucene"
72
72
  new_index["type"].should == "fulltext"
73
73
  end
@@ -21,6 +21,7 @@ module Neography
21
21
  its(:username) { should == nil }
22
22
  its(:password) { should == nil }
23
23
  its(:parser) { should == MultiJsonParser}
24
+ its(:max_execution_time) { should == 6000 }
24
25
 
25
26
  it "has a hash representation" do
26
27
  expected_hash = {
@@ -37,7 +38,8 @@ module Neography
37
38
  :authentication => nil,
38
39
  :username => nil,
39
40
  :password => nil,
40
- :parser => MultiJsonParser
41
+ :parser => MultiJsonParser,
42
+ :max_execution_time => 6000
41
43
  }
42
44
  config.to_hash.should == expected_hash
43
45
  end
@@ -8,7 +8,7 @@ module Neography
8
8
  context "defaults" do
9
9
 
10
10
  it "intializes with defaults" do
11
- connection.configuration.should == "http://localhost:7474/db/data"
11
+ connection.configuration.should == "http://localhost:7474"
12
12
  end
13
13
 
14
14
  end
@@ -38,7 +38,7 @@ module Neography
38
38
  end
39
39
 
40
40
  it "accepts all options in a hash" do
41
- connection.configuration.should == "https://foobar:4242/dir/db/data"
41
+ connection.configuration.should == "https://foobar:4242/dir"
42
42
 
43
43
  connection.protocol.should == "https://"
44
44
  connection.server.should == "foobar"
@@ -65,7 +65,7 @@ module Neography
65
65
  let(:options) { "https://user:pass@somehost:8585/path" }
66
66
 
67
67
  it "accepts a string as configuration" do
68
- connection.configuration.should == "https://somehost:8585/path/db/data"
68
+ connection.configuration.should == "https://somehost:8585/path"
69
69
  connection.authentication.should == {
70
70
  :basic_auth => {
71
71
  :username => "user",
@@ -125,7 +125,7 @@ module Neography
125
125
  it "adds the User-Agent to the headers" do
126
126
  connection.client.should_receive(:get).with(
127
127
  "http://localhost:7474/db/data/foo/bar",
128
- nil, { "User-Agent" => "Neography/#{Neography::VERSION}", "X-Stream"=>true}
128
+ nil, { "User-Agent" => "Neography/#{Neography::VERSION}", "X-Stream"=>true, "max-execution-time"=>6000}
129
129
  ) { double.as_null_object }
130
130
 
131
131
  connection.get("/foo/bar", :headers => {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max De Marzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-27 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.1
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: 0.8.7
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: 0.8.7
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: coveralls
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - '>='
81
67
  - !ruby/object:Gem::Version
82
68
  version: 2.3.3
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: 0.8.7
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: 0.8.7
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: json
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,14 +98,14 @@ dependencies:
126
98
  name: rubyzip
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
- - - ~>
101
+ - - '>='
130
102
  - !ruby/object:Gem::Version
131
103
  version: 1.0.0
132
104
  type: :runtime
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
- - - ~>
108
+ - - '>='
137
109
  - !ruby/object:Gem::Version
138
110
  version: 1.0.0
139
111
  - !ruby/object:Gem::Dependency
@@ -150,6 +122,20 @@ dependencies:
150
122
  - - '>='
151
123
  - !ruby/object:Gem::Version
152
124
  version: 1.3.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.8.7
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.8.7
153
139
  description: A Ruby wrapper to the Neo4j Rest API see http://docs.neo4j.org/chunked/stable/rest-api.html
154
140
  for more details.
155
141
  email: maxdemarzi@gmail.com
@@ -296,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
282
  version: '0'
297
283
  requirements: []
298
284
  rubyforge_project: neography
299
- rubygems_version: 2.0.6
285
+ rubygems_version: 2.0.3
300
286
  signing_key:
301
287
  specification_version: 4
302
288
  summary: ruby wrapper to Neo4j Rest API