boltless 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docker-compose.yml +1 -0
- data/lib/boltless/configuration.rb +13 -0
- data/lib/boltless/request.rb +5 -2
- data/lib/boltless/version.rb +1 -1
- data/spec/boltless/request_spec.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90c7aeff2f28dedaef95fce6b671e669e1f0cb91f0de16071a72670396f8eecd
|
4
|
+
data.tar.gz: bcd593ed5d27c734fdd5efabb324a2cc60890efc0230fd085c38f4b276a1782b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf67a5be73475d94c5860a44e7c73fb0efccba46f452f559a5db9bfca56805d5a21ce518c5355970b47a267556c206369b6222cfc0c792eac46ba51a199ad6d
|
7
|
+
data.tar.gz: b616566ff140b20482d084516deae237e4c54302fe9480c06d4aa9a4da5978fdf4c2660c26bf20d99d782c76193f9e133dd3b1a27a7674761b52eb348ee39b08
|
data/docker-compose.yml
CHANGED
@@ -65,5 +65,18 @@ module Boltless
|
|
65
65
|
connection
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
# We allow to check/modify the raw neo4j response body string before it
|
70
|
+
# gets JSON parsed and handled. This may be handy for some low-level
|
71
|
+
# analyses on the raw responses. The first argument of the user defined
|
72
|
+
# block will be the raw response body string and the second it the full
|
73
|
+
# HTTP response object (+HTTP::Response+). The user defined block MUST
|
74
|
+
# return a JSON parsable string (eg. the original input) in order to
|
75
|
+
# continue regular processing.
|
76
|
+
config_accessor(:raw_response_handler) do
|
77
|
+
proc do |body, _response|
|
78
|
+
body
|
79
|
+
end
|
80
|
+
end
|
68
81
|
end
|
69
82
|
end
|
data/lib/boltless/request.rb
CHANGED
@@ -238,8 +238,11 @@ module Boltless
|
|
238
238
|
# handling (error, raw result, restructured result)
|
239
239
|
# rubocop:disable Metrics/AbcSize dito
|
240
240
|
def handle_response_body(res, tx_id: nil)
|
241
|
-
# Parse the response body as a whole
|
242
|
-
|
241
|
+
# Parse the response body as a whole, which is returned by
|
242
|
+
# the configured raw response handler
|
243
|
+
body = FastJsonparser.parse(
|
244
|
+
Boltless.configuration.raw_response_handler.call(res.to_s, res)
|
245
|
+
)
|
243
246
|
|
244
247
|
# When we hit some response errors, we handle them and
|
245
248
|
# re-raise in a wrapped exception
|
data/lib/boltless/version.rb
CHANGED
@@ -472,6 +472,7 @@ RSpec.describe Boltless::Request do
|
|
472
472
|
|
473
473
|
describe '#handle_response_body' do
|
474
474
|
let(:action) { instance.handle_response_body(response, tx_id: tx_id) }
|
475
|
+
let(:safe_action) { suppress(StandardError) { action } }
|
475
476
|
|
476
477
|
context 'with invalid JSON response' do
|
477
478
|
let(:body) { '<html>Service unavailable</html>' }
|
@@ -598,6 +599,35 @@ RSpec.describe Boltless::Request do
|
|
598
599
|
all(be_a(Boltless::Errors::ResponseError))
|
599
600
|
end
|
600
601
|
end
|
602
|
+
|
603
|
+
context 'with a custom raw response handler' do
|
604
|
+
let(:body) { { test: true }.to_json }
|
605
|
+
let(:handler) { proc { 'test!' } }
|
606
|
+
|
607
|
+
before { Boltless.configuration.raw_response_handler = handler }
|
608
|
+
|
609
|
+
it 'uses the raw response handler return value for parsing' do
|
610
|
+
expect(FastJsonparser).to \
|
611
|
+
receive(:parse).with('test!').once.and_call_original
|
612
|
+
safe_action
|
613
|
+
end
|
614
|
+
|
615
|
+
it 'passes over the raw response body' do
|
616
|
+
Boltless.configuration.raw_response_handler = proc do |body, _res|
|
617
|
+
expect(body).to be_eql('{"test":true}')
|
618
|
+
body
|
619
|
+
end
|
620
|
+
action
|
621
|
+
end
|
622
|
+
|
623
|
+
it 'passes over the raw response' do
|
624
|
+
Boltless.configuration.raw_response_handler = proc do |body, res|
|
625
|
+
expect(res).to be_a(HTTP::Response)
|
626
|
+
body
|
627
|
+
end
|
628
|
+
action
|
629
|
+
end
|
630
|
+
end
|
601
631
|
end
|
602
632
|
|
603
633
|
describe '#serialize_body' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boltless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hermann Mayer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|