funnel_http 0.3.2 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44a84685adf7f414a48d3b4db7a56192a6172874629529922b8bc937c5b0db9f
4
- data.tar.gz: d0b7baca3c2947aa1b9b724915d598d9f702c6c7a45fcef1a0323fdae67cb845
3
+ metadata.gz: a8e58f7f5762729ef1447c52424e00f63abbad0e57bff3d627e1257045c44da5
4
+ data.tar.gz: 960f3a22cfaa73eef6afabfb1758b38b0feb715e4485c73cecf3374ee5b4be83
5
5
  SHA512:
6
- metadata.gz: 1e47ca273145f8a5cf96d357d128d9a208fb50d23c9315f43b3bda8698cf7bbf4ddb4bcf3148fd01fec82a5c8e91aea9808423b430d9a26cf81ae2d1962e9c67
7
- data.tar.gz: 97d7ace5558bbd6e3f7e09901660e58db6e2dbe7fd57cc7b9a9777ea8915f2dc4d3db47517234ab7d625e15f2522fc0483ca975becde55b53bf80c2c80bde766
6
+ metadata.gz: 802019c07462641eba8b376ca087bbfbb6210ab5cc40bf239a2a7f4234bdf5787d5448e61090a4d58e12383b19ad177e0b99cffef7262ebb50874d54e721bf3d
7
+ data.tar.gz: ffbd6c6b3b29176a13686a0e4d91de7268f0cf4663f1f47fa080b38ca8a7cbe9223de47116da84e94ecb1560cb8c59f150f787705bfc063604c7a715e96cce68
data/.golangci.yml CHANGED
@@ -1,18 +1,31 @@
1
- linters-settings:
2
- revive:
3
- rules:
4
- - name: exported
5
- arguments:
6
- - disableStutteringCheck
7
-
1
+ version: "2"
8
2
  linters:
9
3
  enable:
10
- - gofmt
11
4
  - revive
12
5
  - testifylint
13
6
  - wrapcheck
14
-
15
- issues:
16
- include:
17
- - EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
18
- - EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments
7
+ settings:
8
+ revive:
9
+ rules:
10
+ - name: exported
11
+ arguments:
12
+ - disableStutteringCheck
13
+ exclusions:
14
+ generated: lax
15
+ presets:
16
+ - common-false-positives
17
+ - legacy
18
+ - std-error-handling
19
+ paths:
20
+ - third_party$
21
+ - builtin$
22
+ - examples$
23
+ formatters:
24
+ enable:
25
+ - gofmt
26
+ exclusions:
27
+ generated: lax
28
+ paths:
29
+ - third_party$
30
+ - builtin$
31
+ - examples$
data/CHANGELOG.md CHANGED
@@ -1,7 +1,20 @@
1
1
  ## [Unreleased]
2
- [full changelog](http://github.com/sue445/funnel_http/compare/v0.3.2...main)
2
+ [full changelog](http://github.com/sue445/funnel_http/compare/v0.5.0...main)
3
3
 
4
- ## [0.3.1](https://github.com/sue445/funnel_http/releases/tag/v0.3.2) - 2025-03-22
4
+ ## [0.5.0](https://github.com/sue445/funnel_http/releases/tag/v0.5.0) - 2025-04-14
5
+ [full changelog](http://github.com/sue445/funnel_http/compare/v0.4.0...v0.5.0)
6
+
7
+ * Impl `FunnelHttp::Client#perform!`
8
+ * https://github.com/sue445/funnel_http/pull/81
9
+
10
+ ## [0.4.0](https://github.com/sue445/funnel_http/releases/tag/v0.4.0) - 2025-04-13
11
+ [full changelog](http://github.com/sue445/funnel_http/compare/v0.3.2...v0.4.0)
12
+
13
+ * Add request url to response
14
+ * https://github.com/sue445/funnel_http/pull/80
15
+ * Update Go dependencies
16
+
17
+ ## [0.3.2](https://github.com/sue445/funnel_http/releases/tag/v0.3.2) - 2025-03-22
5
18
  [full changelog](http://github.com/sue445/funnel_http/compare/v0.3.1...v0.3.2)
6
19
 
7
20
  * Fix `Ruby::BlockBodyTypeMismatch` in rbs
data/README.md CHANGED
@@ -33,13 +33,13 @@ client = FunnelHttp::Client.new
33
33
  requests = [
34
34
  {
35
35
  method: :get,
36
- uri: "https://example.com/api/user/1",
36
+ url: "https://example.com/api/user/1",
37
37
  },
38
38
 
39
39
  # with request header
40
- {
41
- method: :get,
42
- uri: "https://example.com/api/user/2",
40
+ {
41
+ method: :get,
42
+ url: "https://example.com/api/user/2",
43
43
  header: {
44
44
  "Authorization" => "Bearer xxxxxxxx",
45
45
  "X-Multiple-Values" => ["1st value", "2nd value"],
@@ -49,7 +49,7 @@ requests = [
49
49
  # with request body
50
50
  {
51
51
  method: :post,
52
- uri: "https://example.com/api/user",
52
+ url: "https://example.com/api/user",
53
53
  header: {
54
54
  "Authorization" => "Bearer xxxxxxxx",
55
55
  "Content-Type" => "application/json",
@@ -60,10 +60,13 @@ requests = [
60
60
 
61
61
  responses = client.perform(requests)
62
62
  # => [
63
- # { status_code: 200, body: "Response of /api/user/1", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
64
- # { status_code: 200, body: "Response of /api/user/2", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
65
- # { status_code: 200, body: "Response of /api/user", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
63
+ # { url: "https://example.com/api/user/1", status_code: 200, body: "Response of /api/user/1", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
64
+ # { url: "https://example.com/api/user/2", status_code: 200, body: "Response of /api/user/2", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
65
+ # { url: "https://example.com/api/user", status_code: 200, body: "Response of /api/user", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
66
66
  # ]
67
+
68
+ # `#perform!` raise errors when http requests returns error status code (4xx, 5xx)
69
+ responses = client.perform!(requests)
67
70
  ```
68
71
 
69
72
  ## Customize
@@ -44,6 +44,7 @@ func rb_funnel_http_run_requests(self C.VALUE, rbAry C.VALUE) C.VALUE {
44
44
 
45
45
  ruby.RbHashAset(rbHash, ruby.RbId2Sym(ruby.RbIntern("status_code")), ruby.INT2NUM(response.StatusCode))
46
46
  ruby.RbHashAset(rbHash, ruby.RbId2Sym(ruby.RbIntern("body")), ruby.String2Value(string(response.Body)))
47
+ ruby.RbHashAset(rbHash, ruby.RbId2Sym(ruby.RbIntern("url")), ruby.String2Value(string(response.URL)))
47
48
 
48
49
  rbHashHeader := ruby.RbHashNew()
49
50
  ruby.RbGcRegisterAddress(&rbHashHeader)
@@ -6,10 +6,10 @@ toolchain go1.24.0
6
6
 
7
7
  require (
8
8
  github.com/cockroachdb/errors v1.11.3
9
- github.com/jarcoal/httpmock v1.3.1
9
+ github.com/jarcoal/httpmock v1.4.0
10
10
  github.com/ruby-go-gem/go-gem-wrapper v0.7.2
11
11
  github.com/stretchr/testify v1.10.0
12
- golang.org/x/sync v0.12.0
12
+ golang.org/x/sync v0.13.0
13
13
  )
14
14
 
15
15
  require (
@@ -15,16 +15,16 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
15
15
  github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
16
16
  github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
17
17
  github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
18
- github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
19
- github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
18
+ github.com/jarcoal/httpmock v1.4.0 h1:BvhqnH0JAYbNudL2GMJKgOHe2CtKlzJ/5rWKyp+hc2k=
19
+ github.com/jarcoal/httpmock v1.4.0/go.mod h1:ftW1xULwo+j0R0JJkJIIi7UKigZUXCLLanykgjwBXL0=
20
20
  github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
21
21
  github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
22
22
  github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
23
23
  github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
24
24
  github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
25
25
  github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
26
- github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g=
27
- github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
26
+ github.com/maxatome/go-testdeep v1.14.0 h1:rRlLv1+kI8eOI3OaBXZwb3O7xY3exRzdW5QyX48g9wI=
27
+ github.com/maxatome/go-testdeep v1.14.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
28
28
  github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
29
29
  github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
30
30
  github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -52,8 +52,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
52
52
  golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
53
53
  golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
54
54
  golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
55
- golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
56
- golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
55
+ golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
56
+ golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
57
57
  golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
58
58
  golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
59
59
  golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -18,6 +18,7 @@ type Request struct {
18
18
 
19
19
  // Response is proxy between CRuby and Go
20
20
  type Response struct {
21
+ URL string
21
22
  StatusCode int
22
23
  Header map[string][]string
23
24
  Body []byte
@@ -58,6 +59,7 @@ func RunRequests(httpClient *http.Client, requests []Request) ([]Response, error
58
59
  return errors.WithStack(err)
59
60
  }
60
61
 
62
+ responses[i].URL = request.URL
61
63
  responses[i].Body = buf
62
64
  responses[i].Header = map[string][]string{}
63
65
 
@@ -37,13 +37,50 @@ module FunnelHttp
37
37
  # @option request :body [String, nil] Request body
38
38
  #
39
39
  # @return [Array<Hash<Symbol => Object>>] `Array` of following `Hash`
40
+ # @return [String] `:url` Request url
40
41
  # @return [Integer] `:status_code`
41
42
  # @return [String] `:body` Response body
42
43
  # @return [Hash{String => Array<String>}] `:header` Response header
44
+ #
45
+ # @note `#perform` doesn't raise errors when http requests returns error status code (4xx, 5xx)
43
46
  def perform(requests)
44
47
  ext_client.run_requests(normalize_requests(requests))
45
48
  end
46
49
 
50
+ # perform HTTP requests in parallel
51
+ #
52
+ # @overload perform(requests)
53
+ # @param requests [Array<Hash{Symbol => Object}>] `Array` of following `Hash`
54
+ # @option requests :method [String, Symbol] **[required]** Request method (e.g. `:get`, `"POST"`)
55
+ # @option requests :url [String] **[required]** Request url
56
+ # @option requests :header [Hash{String => String, Array<String>}, nil] Request header
57
+ # @option requests :body [String, nil] Request body
58
+ #
59
+ # @overload perform(request)
60
+ # @param request [Hash{Symbol => Object}]
61
+ # @option request :method [String, Symbol] **[required]** Request method (e.g. `:get`, `"POST"`)
62
+ # @option request :url [String] **[required]** Request url
63
+ # @option request :header [Hash{String => String, Array<String>}, nil] Request header
64
+ # @option request :body [String, nil] Request body
65
+ #
66
+ # @return [Array<Hash<Symbol => Object>>] `Array` of following `Hash`
67
+ # @return [String] `:url` Request url
68
+ # @return [Integer] `:status_code`
69
+ # @return [String] `:body` Response body
70
+ # @return [Hash{String => Array<String>}] `:header` Response header
71
+ #
72
+ # @raise [FunnelHttp::HttpAggregateError] 1+ errors returned out of multiple requests
73
+ #
74
+ # @note `#perform!` raise errors when http requests returns error status code (4xx, 5xx)
75
+ def perform!(requests)
76
+ responses = perform(requests)
77
+
78
+ error_responses = responses.select { |res| res[:status_code] >= 400 }
79
+ raise HttpAggregateError, error_responses unless error_responses.empty?
80
+
81
+ responses
82
+ end
83
+
47
84
  # @overload normalize_requests(requests)
48
85
  # @param requests [Array<Hash{Symbol => Object}>] `Array` of following `Hash`
49
86
  # @option requests :method [String, Symbol] **[required]** Request method (e.g. `:get`, `"POST"`)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunnelHttp
4
+ class Error < StandardError; end
5
+
6
+ # Aggregates multiple http errors
7
+ class HttpAggregateError < Error
8
+ # @!attribute [r] error_responses
9
+ # @return [Array<Hash<Symbol => Object>>] `Array` of following `Hash`
10
+ # @return [String] `:url` Request url
11
+ # @return [Integer] `:status_code`
12
+ # @return [String] `:body` Response body
13
+ # @return [Hash{String => Array<String>}] `:header` Response header
14
+ attr_reader :error_responses
15
+
16
+ # @param error_responses [Array<Hash<Symbol => Object>>]
17
+ def initialize(error_responses)
18
+ @error_responses = error_responses
19
+ super(HttpAggregateError.generate_error_message(error_responses))
20
+ end
21
+
22
+ # Generate error message for `StandardError#initialize`
23
+ #
24
+ # @param error_responses [Array<Hash<Symbol => Object>>]
25
+ #
26
+ # @return [String]
27
+ def self.generate_error_message(error_responses)
28
+ error_responses.map { |res| "#{res[:url]} (#{res[:status_code]} error)" }.join(", ")
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FunnelHttp
4
- VERSION = "0.3.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/funnel_http.rb CHANGED
@@ -3,11 +3,10 @@
3
3
  require_relative "funnel_http/version"
4
4
  require_relative "funnel_http/client"
5
5
  require_relative "funnel_http/ext"
6
+ require_relative "funnel_http/errors"
6
7
  require_relative "funnel_http/funnel_http"
7
8
 
8
9
  module FunnelHttp
9
- class Error < StandardError; end
10
-
11
10
  USER_AGENT = "funnel_http/#{FunnelHttp::VERSION} (+https://github.com/sue445/funnel_http)"
12
11
 
13
12
  # Your code goes here...
@@ -6,7 +6,7 @@ gems:
6
6
  source:
7
7
  type: git
8
8
  name: ruby/gem_rbs_collection
9
- revision: a8dd6bcebdae31ce6adc8887ef16c7ee6e1b9a6d
9
+ revision: cefa5dea1094880e2386c6d296c743d10eb0cf9d
10
10
  remote: https://github.com/ruby/gem_rbs_collection.git
11
11
  repo_dir: gems
12
12
  - name: cgi
@@ -18,7 +18,7 @@ gems:
18
18
  source:
19
19
  type: git
20
20
  name: ruby/gem_rbs_collection
21
- revision: a8dd6bcebdae31ce6adc8887ef16c7ee6e1b9a6d
21
+ revision: cefa5dea1094880e2386c6d296c743d10eb0cf9d
22
22
  remote: https://github.com/ruby/gem_rbs_collection.git
23
23
  repo_dir: gems
24
24
  - name: fileutils
@@ -38,7 +38,7 @@ gems:
38
38
  source:
39
39
  type: git
40
40
  name: ruby/gem_rbs_collection
41
- revision: a8dd6bcebdae31ce6adc8887ef16c7ee6e1b9a6d
41
+ revision: cefa5dea1094880e2386c6d296c743d10eb0cf9d
42
42
  remote: https://github.com/ruby/gem_rbs_collection.git
43
43
  repo_dir: gems
44
44
  - name: rake
@@ -46,7 +46,7 @@ gems:
46
46
  source:
47
47
  type: git
48
48
  name: ruby/gem_rbs_collection
49
- revision: a8dd6bcebdae31ce6adc8887ef16c7ee6e1b9a6d
49
+ revision: cefa5dea1094880e2386c6d296c743d10eb0cf9d
50
50
  remote: https://github.com/ruby/gem_rbs_collection.git
51
51
  repo_dir: gems
52
52
  - name: sinatra
@@ -54,7 +54,7 @@ gems:
54
54
  source:
55
55
  type: git
56
56
  name: ruby/gem_rbs_collection
57
- revision: a8dd6bcebdae31ce6adc8887ef16c7ee6e1b9a6d
57
+ revision: cefa5dea1094880e2386c6d296c743d10eb0cf9d
58
58
  remote: https://github.com/ruby/gem_rbs_collection.git
59
59
  repo_dir: gems
60
60
  - name: stringio
@@ -10,6 +10,8 @@ module FunnelHttp
10
10
 
11
11
  def perform: (fuzzy_request | Array[fuzzy_request] requests) -> Array[response]
12
12
 
13
+ def perform!: (fuzzy_request | Array[fuzzy_request] requests) -> Array[response]
14
+
13
15
  def normalize_requests: (fuzzy_request | Array[fuzzy_request] arg) -> Array[strict_request]
14
16
 
15
17
  private
@@ -0,0 +1,14 @@
1
+ module FunnelHttp
2
+ class Error < StandardError
3
+ end
4
+
5
+ class HttpAggregateError < Error
6
+ @error_responses: Array[response]
7
+
8
+ attr_accessor error_responses: Array[response]
9
+
10
+ def initialize: (Array[response] error_responses) -> void
11
+
12
+ def self.generate_error_message: (Array[response] error_responses) -> String
13
+ end
14
+ end
data/sig/funnel_http.rbs CHANGED
@@ -2,9 +2,6 @@ module FunnelHttp
2
2
  VERSION: String
3
3
  USER_AGENT: String
4
4
 
5
- class Error < StandardError
6
- end
7
-
8
5
  type fuzzy_header = Hash[String, String | Array[String]]
9
6
 
10
7
  type fuzzy_request = {
@@ -24,6 +21,7 @@ module FunnelHttp
24
21
  }
25
22
 
26
23
  type response = {
24
+ url: String,
27
25
  status_code: Integer,
28
26
  body: String,
29
27
  header: strict_header
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funnel_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-21 00:00:00.000000000 Z
10
+ date: 2025-04-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: go_gem
@@ -202,12 +202,14 @@ files:
202
202
  - ext/funnel_http/run_requests.go
203
203
  - lib/funnel_http.rb
204
204
  - lib/funnel_http/client.rb
205
+ - lib/funnel_http/errors.rb
205
206
  - lib/funnel_http/ext.rb
206
207
  - lib/funnel_http/version.rb
207
208
  - rbs_collection.lock.yaml
208
209
  - rbs_collection.yaml
209
210
  - sig/funnel_http.rbs
210
211
  - sig/funnel_http/client.rbs
212
+ - sig/funnel_http/errors.rbs
211
213
  - sig/funnel_http/ext.rbs
212
214
  homepage: https://github.com/sue445/funnel_http
213
215
  licenses: