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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaace21a6d9ecce8ac3b00cecc5e93a1394921d1db873a4d2c990710b3a4b48c
4
- data.tar.gz: '0193b5e271ad99c2866a37be07e88d642e790bad9b7c840f7aededcd3f297962'
3
+ metadata.gz: b8c817cee07b1548c915ae7645140bf6ce0b67571fce3973da219b1ebcfea628
4
+ data.tar.gz: d8fae1968ea6e37d01255b9b35e0db7856e4ea954bd8dff2abe47f22d2c3ad46
5
5
  SHA512:
6
- metadata.gz: 2349bf5398e9ace3197354d99a8afd44ada51d583380370f95caf3c2b27f24b1763575924ed7b02207485a406f0cfde5f885bdbb577ade3ff68f0a40fec7d7f6
7
- data.tar.gz: 6721e6c34658a5ff4f7cadc780427fb91d7cb4590154b6931e8f808d3b59634707e55cc9eac0cafe4cc838ac0b12523e30ccbf4eecc089aeca77f4a2426a08b2
6
+ metadata.gz: 1512d5148fd516eea11bd6e7c79477a61ab12f1e0c4a79c1d1a42cc54a33b6db6b16115c0b1c80e4b3be42f0cf153925712ae4276e75b6dd1830e4212bfaa46c
7
+ data.tar.gz: 38e03f37f6b1ea50f76aa0c2d604e219520cc43b80f9502139c649d689e95cb62828a2dc406ffcaa2537da05957c80a53718bf3e75997c5296ce7a77501965d7
@@ -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
@@ -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
@@ -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
@@ -21,6 +21,10 @@ module Amaranth
21
21
  def videos
22
22
  Video.all(team_slug: slug)
23
23
  end
24
+
25
+ def activity type: nil, after: nil
26
+ Activity.all(team_slug: slug, type: type, after: after)
27
+ end
24
28
  end
25
29
  end
26
30
 
@@ -1,3 +1,3 @@
1
1
  module Amaranth
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/amaranth.rb CHANGED
@@ -4,6 +4,7 @@ require "amaranth/team"
4
4
  require "amaranth/project"
5
5
  require "amaranth/video"
6
6
  require "amaranth/language"
7
+ require "amaranth/activity"
7
8
 
8
9
  module Amaranth
9
10
  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.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: 2024-09-12 00:00:00.000000000 Z
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: []