nxt_http_client 1.0.3 → 1.1.0

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
  SHA256:
3
- metadata.gz: 4260cb5f0853f547f8ab196f0c7d4cb66fc34f3c1aba748d3e0836183ee68f18
4
- data.tar.gz: ef7c3095fe541847fc57eb4ba807f1f9a2e9b3d7413b08980d619805339c4557
3
+ metadata.gz: 6cccf6ffc8c507e36f58161ef7bd6b6412312015f5cf53d26f9ac2ea52244b8c
4
+ data.tar.gz: bc67df2f1885c7a49dabbdf4b49f823ec2f6bd1acba006295b847a1d181ed4aa
5
5
  SHA512:
6
- metadata.gz: 57806fbcb6fe0f44a47c820a24d4036ca6ae9dc24d1c9cbaa746ecff4567e29aba8f4a000885f461fa6dccf1d049e77c1528d5df0ccecdc731ce81e0b95d7795
7
- data.tar.gz: 97452f30577ad9f0ae35a62be8a82e6c7cf0a99a2d2c35e69d90c6fb0d290f74cdb1c7b787c0ffdfc4d3196255d6f56069f3ebc59e315f83af1bb6a7581c2c19
6
+ metadata.gz: 9ed4b1e266af12b23d2d7e4cbfd448a0ae5e9e9cf9fd48358f06b2d515e1d58e8db68fe29742f28908b30f9e93f51e9de9d181c30302c2b098647d23f3417631
7
+ data.tar.gz: f0f391aa5e8ea47fea76d197442b95799a9c6e9d17723dc958612d42dc499c872082b968a906a65f1367f07817ea304bb52d41addc0b1273e2bbb89460c041f4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v1.1.0 2023-04-03
2
+ - Introduce a Typhoeus::Hydra interface for batch executions
3
+
4
+ # v1.0.4 2022-06-08
5
+ - Fix bug where callbacks were shared between unrelated child client class ([#130](https://github.com/nxt-insurance/nxt_http_client/pull/130))
6
+
1
7
  # v1.0.3 2022-02-08
2
8
 
3
9
  - Relax dependency version constraints, allow activesupport < 8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_http_client (1.0.3)
4
+ nxt_http_client (1.1.0)
5
5
  activesupport (< 8.0)
6
6
  nxt_registry
7
7
  typhoeus
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.1)
12
+ activesupport (7.0.4.3)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
@@ -17,18 +17,18 @@ GEM
17
17
  addressable (2.8.0)
18
18
  public_suffix (>= 2.0.2, < 5.0)
19
19
  coderay (1.1.3)
20
- concurrent-ruby (1.1.9)
20
+ concurrent-ruby (1.2.2)
21
21
  crack (0.4.5)
22
22
  rexml
23
23
  diff-lcs (1.5.0)
24
- ethon (0.15.0)
24
+ ethon (0.16.0)
25
25
  ffi (>= 1.15.0)
26
26
  ffi (1.15.5)
27
27
  hashdiff (1.0.1)
28
- i18n (1.9.1)
28
+ i18n (1.12.0)
29
29
  concurrent-ruby (~> 1.0)
30
30
  method_source (1.0.0)
31
- minitest (5.15.0)
31
+ minitest (5.18.0)
32
32
  nxt_registry (0.3.10)
33
33
  activesupport
34
34
  nxt_vcr_harness (0.1.4)
@@ -37,38 +37,40 @@ GEM
37
37
  pry (0.14.1)
38
38
  coderay (~> 1.1)
39
39
  method_source (~> 1.0)
40
- public_suffix (4.0.6)
40
+ public_suffix (4.0.7)
41
41
  rake (13.0.6)
42
42
  redis (4.6.0)
43
43
  rexml (3.2.5)
44
- rspec (3.10.0)
45
- rspec-core (~> 3.10.0)
46
- rspec-expectations (~> 3.10.0)
47
- rspec-mocks (~> 3.10.0)
48
- rspec-core (3.10.2)
49
- rspec-support (~> 3.10.0)
50
- rspec-expectations (3.10.2)
44
+ rspec (3.11.0)
45
+ rspec-core (~> 3.11.0)
46
+ rspec-expectations (~> 3.11.0)
47
+ rspec-mocks (~> 3.11.0)
48
+ rspec-core (3.11.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-expectations (3.11.0)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.10.0)
53
- rspec-mocks (3.10.3)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-mocks (3.11.1)
54
54
  diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.10.0)
56
- rspec-support (3.10.3)
55
+ rspec-support (~> 3.11.0)
56
+ rspec-support (3.11.0)
57
57
  rspec_junit_formatter (0.5.1)
58
58
  rspec-core (>= 2, < 4, != 2.12.0)
59
- timecop (0.9.4)
59
+ timecop (0.9.5)
60
60
  typhoeus (1.4.0)
61
61
  ethon (>= 0.9.0)
62
- tzinfo (2.0.4)
62
+ tzinfo (2.0.6)
63
63
  concurrent-ruby (~> 1.0)
64
- vcr (6.0.0)
64
+ vcr (6.1.0)
65
65
  webmock (3.14.0)
66
66
  addressable (>= 2.8.0)
67
67
  crack (>= 0.3.2)
68
68
  hashdiff (>= 0.4.0, < 2.0.0)
69
69
 
70
70
  PLATFORMS
71
+ ruby
71
72
  x86_64-darwin-19
73
+ x86_64-darwin-20
72
74
  x86_64-linux
73
75
 
74
76
  DEPENDENCIES
@@ -0,0 +1,26 @@
1
+ module NxtHttpClient
2
+ def self.execute_in_batch(*client_instances, ignore_around_callbacks: false, raise_errors: true)
3
+ client_map = Hash.new do |hash, key|
4
+ hash[key] = { request: nil, error: nil, result: nil }
5
+ end
6
+
7
+ client_instances.each do |client|
8
+ client.singleton_class.include(NxtHttpClient::Client::BatchPatch)
9
+ client.assign_batch_data(client_map[client], ignore_around_callbacks)
10
+ end
11
+
12
+ hydra = Typhoeus::Hydra.new
13
+
14
+ client_instances.each do |client|
15
+ client.call.tap do |request|
16
+ hydra.queue(request)
17
+ end
18
+ end
19
+
20
+ hydra.run
21
+
22
+ client_map.map do |client, response_data|
23
+ client.finish(response_data[:request], response_data[:result], response_data[:error], raise_errors: raise_errors)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,55 @@
1
+ module NxtHttpClient
2
+ class Client
3
+ module BatchPatch
4
+ attr_reader :callback_map, :ignore_around_callbacks
5
+
6
+ def assign_batch_data(callback_map, ignore_around_callbacks)
7
+ @callback_map = callback_map
8
+ @ignore_around_callbacks = ignore_around_callbacks
9
+ end
10
+
11
+ def fire(url = '', **opts, &block)
12
+ response_handler = build_response_handler(opts[:response_handler], &block)
13
+ request = build_request(url, **opts.except(:response_handler))
14
+ callback_map[:request] = request
15
+
16
+ setup_on_headers_callback(request, response_handler)
17
+ setup_on_body_callback(request, response_handler)
18
+
19
+ request.on_complete do |response|
20
+ callback_map[:result] = callback_or_response(response, response_handler)
21
+ rescue StandardError => e
22
+ callback_map[:error] = e
23
+ end
24
+
25
+ if callbacks.any_around_callbacks? && ignore_around_callbacks != true
26
+ raise(
27
+ ArgumentError,
28
+ <<~TXT
29
+ `around_fire` callbacks are not supported when firing batches. \
30
+ Pass `ignore_around_callbacks: true` to `execute_in_batch` \
31
+ in order to acknowledge and muffle this.
32
+ TXT
33
+ )
34
+ end
35
+
36
+ run_before_fire_callbacks(request, response_handler)
37
+
38
+ request
39
+ end
40
+
41
+ def finish(request, result, error, raise_errors: true)
42
+ result = run_after_fire_callbacks(request, request.response, result, error)
43
+
44
+ case [error, raise_errors]
45
+ in [nil, _]
46
+ result
47
+ in [_, true]
48
+ raise error
49
+ in [_, false]
50
+ error
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -30,6 +30,10 @@ module NxtHttpClient
30
30
  end
31
31
  end
32
32
 
33
+ def any_around_callbacks?
34
+ registry.resolve(:around).any?
35
+ end
36
+
33
37
  def any_after_callbacks?
34
38
  registry.resolve(:after).any?
35
39
  end
@@ -46,6 +50,11 @@ module NxtHttpClient
46
50
  callback_chain.call
47
51
  end
48
52
 
53
+ def initialize_copy(original)
54
+ @registry = original.instance_variable_get(:@registry).clone
55
+ super
56
+ end
57
+
49
58
  private
50
59
 
51
60
  attr_reader :registry
@@ -1,3 +1,3 @@
1
1
  module NxtHttpClient
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -11,6 +11,8 @@ require 'nxt_http_client/logger'
11
11
  require 'nxt_http_client/fire_callbacks'
12
12
  require 'nxt_http_client/client_dsl'
13
13
  require 'nxt_http_client/client'
14
+ require 'nxt_http_client/client/batch_patch'
15
+ require 'nxt_http_client/batch_execution'
14
16
  require 'nxt_http_client/error'
15
17
 
16
18
  module NxtHttpClient
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
8
8
  - Nils Sommer
9
9
  - Raphael Kallensee
10
10
  - Luetfi Demirci
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-02-08 00:00:00.000000000 Z
14
+ date: 2023-04-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus
@@ -216,7 +216,9 @@ files:
216
216
  - bin/console
217
217
  - bin/setup
218
218
  - lib/nxt_http_client.rb
219
+ - lib/nxt_http_client/batch_execution.rb
219
220
  - lib/nxt_http_client/client.rb
221
+ - lib/nxt_http_client/client/batch_patch.rb
220
222
  - lib/nxt_http_client/client_dsl.rb
221
223
  - lib/nxt_http_client/config.rb
222
224
  - lib/nxt_http_client/error.rb
@@ -234,7 +236,7 @@ metadata:
234
236
  allowed_push_host: https://rubygems.org
235
237
  homepage_uri: https://github.com/nxt-insurance
236
238
  source_code_uri: https://github.com/nxt-insurance/nxt_http_client
237
- post_install_message:
239
+ post_install_message:
238
240
  rdoc_options: []
239
241
  require_paths:
240
242
  - lib
@@ -250,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
252
  version: '0'
251
253
  requirements: []
252
254
  rubygems_version: 3.1.6
253
- signing_key:
255
+ signing_key:
254
256
  specification_version: 4
255
257
  summary: NxtHttpClinet is a simple DSL on top the typhoeus http gem
256
258
  test_files: []