amaranth 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/.github/workflows/ci.yml +1 -1
- data/lib/amaranth/request.rb +23 -0
- data/lib/amaranth/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c16c24781575326519c5ab7cbc37fba8f40638834e342b3430cc69738a7e257
|
|
4
|
+
data.tar.gz: 7b46a95519ecd9150bfd447387df73a99f5656be644bed20ab4f5ba8864eb2b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e342ec27957ab3a229cc62483600f5b82db557037014bc466b34f8182979db6909e0dd3f127df946fac6cded35da3b2748b7e6a2aec91d97ce5fd242cf6e482b
|
|
7
|
+
data.tar.gz: 97ad051f175662417cce7009aedfeee5a18ae6f1f4bba7af0176fe38f80499606fa586f28bf9d6d0e006d220318dcffa15bd9fc7a8838caaba38698327418a39
|
data/.github/workflows/ci.yml
CHANGED
data/lib/amaranth/request.rb
CHANGED
|
@@ -4,10 +4,15 @@ require "net/http"
|
|
|
4
4
|
|
|
5
5
|
module Amaranth
|
|
6
6
|
class RequestError < StandardError; end
|
|
7
|
+
class RateLimitError < RequestError; end
|
|
7
8
|
|
|
8
9
|
class Request
|
|
10
|
+
MAX_RETRIES = 5
|
|
11
|
+
BASE_DELAY = 1
|
|
12
|
+
|
|
9
13
|
def self.get path
|
|
10
14
|
result = request(Net::HTTP::Get.new(path))
|
|
15
|
+
result.is_a?(Net::HTTPSuccess) or raise Amaranth::RequestError, "#{result.code}: #{result.body}"
|
|
11
16
|
JSON.parse(result.body)
|
|
12
17
|
end
|
|
13
18
|
|
|
@@ -27,6 +32,19 @@ module Amaranth
|
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
def self.request req, body = nil
|
|
35
|
+
retries = 0
|
|
36
|
+
loop do
|
|
37
|
+
response = perform(req, body)
|
|
38
|
+
return response unless response.code == "429"
|
|
39
|
+
if retries >= MAX_RETRIES
|
|
40
|
+
raise Amaranth::RateLimitError, "429 Too Many Requests: #{req.method} #{req.path}"
|
|
41
|
+
end
|
|
42
|
+
sleep retry_delay(response, retries)
|
|
43
|
+
retries += 1
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private_class_method def self.perform req, body
|
|
30
48
|
Net::HTTP.start("amara.org", use_ssl: true) do |http|
|
|
31
49
|
req["Content-Type"] = "application/json"
|
|
32
50
|
req["X-api-username"] = Amaranth.api_username
|
|
@@ -35,5 +53,10 @@ module Amaranth
|
|
|
35
53
|
http.request(req)
|
|
36
54
|
end
|
|
37
55
|
end
|
|
56
|
+
|
|
57
|
+
private_class_method def self.retry_delay response, retries
|
|
58
|
+
seconds = response["Retry-After"].to_i
|
|
59
|
+
seconds > 0 ? seconds : BASE_DELAY * (2 ** retries)
|
|
60
|
+
end
|
|
38
61
|
end
|
|
39
62
|
end
|
data/lib/amaranth/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: amaranth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Geisel
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -52,7 +52,7 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '2.0'
|
|
55
|
-
description:
|
|
55
|
+
description:
|
|
56
56
|
email:
|
|
57
57
|
- micah@botandrose.com
|
|
58
58
|
executables: []
|
|
@@ -83,7 +83,7 @@ homepage: https://github.com/botandrose/amaranth
|
|
|
83
83
|
licenses:
|
|
84
84
|
- MIT
|
|
85
85
|
metadata: {}
|
|
86
|
-
post_install_message:
|
|
86
|
+
post_install_message:
|
|
87
87
|
rdoc_options: []
|
|
88
88
|
require_paths:
|
|
89
89
|
- lib
|
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
99
|
version: '0'
|
|
100
100
|
requirements: []
|
|
101
101
|
rubygems_version: 3.5.11
|
|
102
|
-
signing_key:
|
|
102
|
+
signing_key:
|
|
103
103
|
specification_version: 4
|
|
104
104
|
summary: Library for accessing the Amara REST API
|
|
105
105
|
test_files: []
|