amaranth 0.4.0 → 0.6.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/activity.rb +20 -0
- data/lib/amaranth/request.rb +23 -0
- data/lib/amaranth/team.rb +4 -0
- data/lib/amaranth/version.rb +1 -1
- data/lib/amaranth.rb +1 -0
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8c817cee07b1548c915ae7645140bf6ce0b67571fce3973da219b1ebcfea628
|
|
4
|
+
data.tar.gz: d8fae1968ea6e37d01255b9b35e0db7856e4ea954bd8dff2abe47f22d2c3ad46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1512d5148fd516eea11bd6e7c79477a61ab12f1e0c4a79c1d1a42cc54a33b6db6b16115c0b1c80e4b3be42f0cf153925712ae4276e75b6dd1830e4212bfaa46c
|
|
7
|
+
data.tar.gz: 38e03f37f6b1ea50f76aa0c2d604e219520cc43b80f9502139c649d689e95cb62828a2dc406ffcaa2537da05957c80a53718bf3e75997c5296ce7a77501965d7
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "amaranth/collection"
|
|
2
|
+
require "time"
|
|
3
|
+
|
|
4
|
+
module Amaranth
|
|
5
|
+
class Activity < Collection
|
|
6
|
+
def self.all team_slug:, type: nil, after: nil
|
|
7
|
+
url = "/api/teams/#{team_slug}/activity/?limit=100"
|
|
8
|
+
url += "&type=#{type}" if type
|
|
9
|
+
url += "&after=#{after.getutc.iso8601}" if after
|
|
10
|
+
fetch(url).map do |attributes|
|
|
11
|
+
new attributes.keep_if { |key, value| fields.include? key.to_sym }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
field :type
|
|
16
|
+
field :date
|
|
17
|
+
field :video
|
|
18
|
+
field :language
|
|
19
|
+
end
|
|
20
|
+
end
|
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/team.rb
CHANGED
data/lib/amaranth/version.rb
CHANGED
data/lib/amaranth.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.6.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-11-13 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: []
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- bin/console
|
|
72
72
|
- bin/setup
|
|
73
73
|
- lib/amaranth.rb
|
|
74
|
+
- lib/amaranth/activity.rb
|
|
74
75
|
- lib/amaranth/collection.rb
|
|
75
76
|
- lib/amaranth/config.rb
|
|
76
77
|
- lib/amaranth/language.rb
|
|
@@ -83,7 +84,7 @@ homepage: https://github.com/botandrose/amaranth
|
|
|
83
84
|
licenses:
|
|
84
85
|
- MIT
|
|
85
86
|
metadata: {}
|
|
86
|
-
post_install_message:
|
|
87
|
+
post_install_message:
|
|
87
88
|
rdoc_options: []
|
|
88
89
|
require_paths:
|
|
89
90
|
- lib
|
|
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
100
|
version: '0'
|
|
100
101
|
requirements: []
|
|
101
102
|
rubygems_version: 3.5.11
|
|
102
|
-
signing_key:
|
|
103
|
+
signing_key:
|
|
103
104
|
specification_version: 4
|
|
104
105
|
summary: Library for accessing the Amara REST API
|
|
105
106
|
test_files: []
|