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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaace21a6d9ecce8ac3b00cecc5e93a1394921d1db873a4d2c990710b3a4b48c
4
- data.tar.gz: '0193b5e271ad99c2866a37be07e88d642e790bad9b7c840f7aededcd3f297962'
3
+ metadata.gz: 6c16c24781575326519c5ab7cbc37fba8f40638834e342b3430cc69738a7e257
4
+ data.tar.gz: 7b46a95519ecd9150bfd447387df73a99f5656be644bed20ab4f5ba8864eb2b6
5
5
  SHA512:
6
- metadata.gz: 2349bf5398e9ace3197354d99a8afd44ada51d583380370f95caf3c2b27f24b1763575924ed7b02207485a406f0cfde5f885bdbb577ade3ff68f0a40fec7d7f6
7
- data.tar.gz: 6721e6c34658a5ff4f7cadc780427fb91d7cb4590154b6931e8f808d3b59634707e55cc9eac0cafe4cc838ac0b12523e30ccbf4eecc089aeca77f4a2426a08b2
6
+ metadata.gz: e342ec27957ab3a229cc62483600f5b82db557037014bc466b34f8182979db6909e0dd3f127df946fac6cded35da3b2748b7e6a2aec91d97ce5fd242cf6e482b
7
+ data.tar.gz: 97ad051f175662417cce7009aedfeee5a18ae6f1f4bba7af0176fe38f80499606fa586f28bf9d6d0e006d220318dcffa15bd9fc7a8838caaba38698327418a39
@@ -7,7 +7,7 @@ jobs:
7
7
  matrix:
8
8
  ruby: [ 3.1, 3.2, 3.3 ]
9
9
 
10
- runs-on: ubuntu-22.04
10
+ runs-on: ubuntu-24.04
11
11
  steps:
12
12
  - uses: actions/checkout@v3
13
13
  - uses: ruby/setup-ruby@v1
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Amaranth
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.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: 2024-09-12 00:00:00.000000000 Z
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: []