w3c_api 0.2.0 → 0.3.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/lib/w3c_api/hal.rb +41 -3
- data/lib/w3c_api/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aca3cfabd692c0eaada3c4a188537a3609bd49f79001e15394648e05651a604a
|
|
4
|
+
data.tar.gz: cf15b6dc9c61577fd758d014e501b95891be435665b68e28d9b33343f3101381
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8d9c16aeb023ee84208ee83d9448514e7f527673a882234aa1621f736c526b19f129086ceb1657ed17ec5b016c220a1c86ebb1046a9c34cc7c581da9eb271ed
|
|
7
|
+
data.tar.gz: 4a1055ebd67f8afdb6ecb33da8088ecb0b7b0ffdfd694e52f7dbd1e9e8d79d44c6fb9729a06acafbdb00667e6338da97fa2cd410eff776b65ea53bc925ceff3c
|
data/lib/w3c_api/hal.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "singleton"
|
|
4
|
+
require "faraday/retry"
|
|
4
5
|
require "lutaml/hal"
|
|
5
6
|
require_relative "models"
|
|
6
7
|
|
|
@@ -50,18 +51,55 @@ module W3cApi
|
|
|
50
51
|
def client
|
|
51
52
|
@client ||= Lutaml::Hal::Client.new(
|
|
52
53
|
api_url: API_URL,
|
|
54
|
+
connection: connection,
|
|
53
55
|
rate_limiting: rate_limiting_options,
|
|
54
56
|
)
|
|
55
57
|
end
|
|
56
58
|
|
|
59
|
+
# Faraday connection mirroring lutaml-hal's default middleware stack, with a
|
|
60
|
+
# retry layer for the failures lutaml-hal's RateLimiter does not cover: the
|
|
61
|
+
# W3C API signals rate-limiting with HTTP 403, plus transient connection and
|
|
62
|
+
# timeout errors. (lutaml-hal still retries 429 and 5xx.) Owning retries here
|
|
63
|
+
# means every consumer of the client is resilient without its own wrapper.
|
|
64
|
+
def connection
|
|
65
|
+
@connection ||= Faraday.new(url: API_URL.delete_suffix("/")) do |conn|
|
|
66
|
+
conn.request :retry, retry_options
|
|
67
|
+
conn.use Faraday::FollowRedirects::Middleware
|
|
68
|
+
conn.request :json
|
|
69
|
+
conn.response :json, content_type: /\bjson$/
|
|
70
|
+
conn.adapter Faraday.default_adapter
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Retry policy for the W3C-specific transient failures (HTTP 403 and
|
|
75
|
+
# connection/timeout). Grows 1, 2, 4, 8, 16s, matching rate_limiting_options.
|
|
76
|
+
def retry_options
|
|
77
|
+
{
|
|
78
|
+
max: 5,
|
|
79
|
+
interval: 1.0,
|
|
80
|
+
backoff_factor: 2,
|
|
81
|
+
max_interval: 30.0,
|
|
82
|
+
retry_statuses: [403],
|
|
83
|
+
exceptions: [
|
|
84
|
+
Errno::ETIMEDOUT, Timeout::Error,
|
|
85
|
+
Faraday::TimeoutError, Faraday::ConnectionFailed
|
|
86
|
+
],
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
57
90
|
# Configure rate limiting options
|
|
91
|
+
#
|
|
92
|
+
# lutaml-hal's RateLimiter retries 429 and 5xx responses with exponential
|
|
93
|
+
# backoff (base_delay * backoff_factor**(attempt - 1), capped at max_delay).
|
|
94
|
+
# These defaults grow 1, 2, 4, 8, 16s so a rate-limited or briefly
|
|
95
|
+
# overloaded W3C API is given real room to recover during a bulk crawl.
|
|
58
96
|
def rate_limiting_options
|
|
59
97
|
@rate_limiting_options ||= {
|
|
60
98
|
enabled: true,
|
|
61
99
|
max_retries: 5,
|
|
62
|
-
base_delay: 0
|
|
63
|
-
max_delay:
|
|
64
|
-
backoff_factor:
|
|
100
|
+
base_delay: 1.0,
|
|
101
|
+
max_delay: 30.0,
|
|
102
|
+
backoff_factor: 2.0,
|
|
65
103
|
}
|
|
66
104
|
end
|
|
67
105
|
|
data/lib/w3c_api/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: w3c_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -38,20 +38,34 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: faraday-retry
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2.0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2.0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: lutaml-hal
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
44
58
|
requirements:
|
|
45
59
|
- - "~>"
|
|
46
60
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
61
|
+
version: 0.2.0
|
|
48
62
|
type: :runtime
|
|
49
63
|
prerelease: false
|
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
65
|
requirements:
|
|
52
66
|
- - "~>"
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
68
|
+
version: 0.2.0
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: lutaml-model
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|