funnel_http 0.4.0 → 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 +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +3 -0
- data/lib/funnel_http/client.rb +36 -0
- data/lib/funnel_http/errors.rb +31 -0
- data/lib/funnel_http/version.rb +1 -1
- data/lib/funnel_http.rb +1 -2
- data/sig/funnel_http/client.rbs +2 -0
- data/sig/funnel_http/errors.rbs +14 -0
- data/sig/funnel_http.rbs +0 -3
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e58f7f5762729ef1447c52424e00f63abbad0e57bff3d627e1257045c44da5
|
4
|
+
data.tar.gz: 960f3a22cfaa73eef6afabfb1758b38b0feb715e4485c73cecf3374ee5b4be83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 802019c07462641eba8b376ca087bbfbb6210ab5cc40bf239a2a7f4234bdf5787d5448e61090a4d58e12383b19ad177e0b99cffef7262ebb50874d54e721bf3d
|
7
|
+
data.tar.gz: ffbd6c6b3b29176a13686a0e4d91de7268f0cf4663f1f47fa080b38ca8a7cbe9223de47116da84e94ecb1560cb8c59f150f787705bfc063604c7a715e96cce68
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
|
-
[full changelog](http://github.com/sue445/funnel_http/compare/v0.
|
2
|
+
[full changelog](http://github.com/sue445/funnel_http/compare/v0.5.0...main)
|
3
|
+
|
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
|
3
9
|
|
4
10
|
## [0.4.0](https://github.com/sue445/funnel_http/releases/tag/v0.4.0) - 2025-04-13
|
5
11
|
[full changelog](http://github.com/sue445/funnel_http/compare/v0.3.2...v0.4.0)
|
data/README.md
CHANGED
@@ -64,6 +64,9 @@ responses = client.perform(requests)
|
|
64
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
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
|
data/lib/funnel_http/client.rb
CHANGED
@@ -41,10 +41,46 @@ module FunnelHttp
|
|
41
41
|
# @return [Integer] `:status_code`
|
42
42
|
# @return [String] `:body` Response body
|
43
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)
|
44
46
|
def perform(requests)
|
45
47
|
ext_client.run_requests(normalize_requests(requests))
|
46
48
|
end
|
47
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
|
+
|
48
84
|
# @overload normalize_requests(requests)
|
49
85
|
# @param requests [Array<Hash{Symbol => Object}>] `Array` of following `Hash`
|
50
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
|
data/lib/funnel_http/version.rb
CHANGED
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...
|
data/sig/funnel_http/client.rbs
CHANGED
@@ -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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funnel_http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sue445
|
@@ -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:
|