amaranth 0.3.4 → 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: bea88580a7f06515df9387ff76c565d07d8c58b7f2a28c86cc7a89d98248d138
4
- data.tar.gz: 21acbfab6b730697f2ecad0290184341396831032f5d3d23ab728c92b2e71fb7
3
+ metadata.gz: 6c16c24781575326519c5ab7cbc37fba8f40638834e342b3430cc69738a7e257
4
+ data.tar.gz: 7b46a95519ecd9150bfd447387df73a99f5656be644bed20ab4f5ba8864eb2b6
5
5
  SHA512:
6
- metadata.gz: a90719c85924793222d350857e0552ff1d14664e1222344f56a8cfe7b4635b7b627dcf740b60ddf9792ca562262c48d151f6fc69b45e0c1fa9ca29c09ebb38c3
7
- data.tar.gz: 969f665cb658394e64f3492f0202d20976f4574c63de68fa78c9e5fc7916a368b216424de71ec4c950084e1aed3274800fb5cfc7291de7b1d74affe39b2ec7ad
6
+ metadata.gz: e342ec27957ab3a229cc62483600f5b82db557037014bc466b34f8182979db6909e0dd3f127df946fac6cded35da3b2748b7e6a2aec91d97ce5fd242cf6e482b
7
+ data.tar.gz: 97ad051f175662417cce7009aedfeee5a18ae6f1f4bba7af0176fe38f80499606fa586f28bf9d6d0e006d220318dcffa15bd9fc7a8838caaba38698327418a39
@@ -0,0 +1,18 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: [ 3.1, 3.2, 3.3 ]
9
+
10
+ runs-on: ubuntu-24.04
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
17
+ - run: bundle exec rake
18
+
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Amaranth
2
- [![Build Status](https://travis-ci.org/botandrose/amaranth.svg)](https://travis-ci.org/botandrose/amaranth)
2
+ [![CI Status](https://github.com/botandrose/amaranth/actions/workflows/ci.yml/badge.svg)](https://github.com/botandrose/amaranth/actions/workflows/ci.yml)
3
3
 
4
4
  Library for accessing the Amara REST API.
5
5
 
data/amaranth.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rake"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
  spec.add_development_dependency "webmock", "~> 2.0"
24
24
  end
@@ -0,0 +1,22 @@
1
+ require "amaranth/request"
2
+
3
+ module Amaranth
4
+ class Language < Collection
5
+ def self.all video_id:
6
+ fetch("/api/videos/#{video_id}/languages/").map do |attributes|
7
+ new attributes.keep_if { |key, value| fields.include? key.to_sym }
8
+ end
9
+ end
10
+
11
+ field :name
12
+ field :title
13
+ field :description
14
+ field :language_code
15
+ field :versions
16
+ field :created
17
+
18
+ def updated_at
19
+ versions.map { |hash| hash["created"] }.max
20
+ end
21
+ end
22
+ 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
@@ -1,3 +1,3 @@
1
1
  module Amaranth
2
- VERSION = "0.3.4"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -57,6 +57,10 @@ module Amaranth
57
57
  id.to_s.length > 0
58
58
  end
59
59
 
60
+ def fetch_languages
61
+ Language.all(video_id: id)
62
+ end
63
+
60
64
  private
61
65
 
62
66
  READONLY_ATTRIBUTES = %i(all_urls languages)
data/lib/amaranth.rb CHANGED
@@ -3,6 +3,7 @@ require "amaranth/config"
3
3
  require "amaranth/team"
4
4
  require "amaranth/project"
5
5
  require "amaranth/video"
6
+ require "amaranth/language"
6
7
 
7
8
  module Amaranth
8
9
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amaranth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
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: 2021-09-22 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '10.0'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '10.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,13 +52,14 @@ 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: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/ci.yml"
62
63
  - ".gitignore"
63
64
  - ".rspec"
64
65
  - ".travis.yml"
@@ -72,6 +73,7 @@ files:
72
73
  - lib/amaranth.rb
73
74
  - lib/amaranth/collection.rb
74
75
  - lib/amaranth/config.rb
76
+ - lib/amaranth/language.rb
75
77
  - lib/amaranth/project.rb
76
78
  - lib/amaranth/request.rb
77
79
  - lib/amaranth/team.rb
@@ -81,7 +83,7 @@ homepage: https://github.com/botandrose/amaranth
81
83
  licenses:
82
84
  - MIT
83
85
  metadata: {}
84
- post_install_message:
86
+ post_install_message:
85
87
  rdoc_options: []
86
88
  require_paths:
87
89
  - lib
@@ -96,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  - !ruby/object:Gem::Version
97
99
  version: '0'
98
100
  requirements: []
99
- rubygems_version: 3.0.8
100
- signing_key:
101
+ rubygems_version: 3.5.11
102
+ signing_key:
101
103
  specification_version: 4
102
104
  summary: Library for accessing the Amara REST API
103
105
  test_files: []