amaranth 0.3.3 → 0.4.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 +5 -5
- data/.github/workflows/ci.yml +18 -0
- data/README.md +1 -1
- data/amaranth.gemspec +2 -2
- data/bin/setup +0 -0
- data/lib/amaranth/collection.rb +45 -0
- data/lib/amaranth/language.rb +22 -0
- data/lib/amaranth/project.rb +9 -10
- data/lib/amaranth/version.rb +1 -1
- data/lib/amaranth/video.rb +20 -21
- data/lib/amaranth.rb +1 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eaace21a6d9ecce8ac3b00cecc5e93a1394921d1db873a4d2c990710b3a4b48c
|
4
|
+
data.tar.gz: '0193b5e271ad99c2866a37be07e88d642e790bad9b7c840f7aededcd3f297962'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2349bf5398e9ace3197354d99a8afd44ada51d583380370f95caf3c2b27f24b1763575924ed7b02207485a406f0cfde5f885bdbb577ade3ff68f0a40fec7d7f6
|
7
|
+
data.tar.gz: 6721e6c34658a5ff4f7cadc780427fb91d7cb4590154b6931e8f808d3b59634707e55cc9eac0cafe4cc838ac0b12523e30ccbf4eecc089aeca77f4a2426a08b2
|
@@ -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-22.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
|
-
[](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"
|
21
|
+
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
-
spec.add_development_dependency "webmock", "~>
|
23
|
+
spec.add_development_dependency "webmock", "~> 2.0"
|
24
24
|
end
|
data/bin/setup
CHANGED
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "amaranth/request"
|
2
|
+
|
3
|
+
module Amaranth
|
4
|
+
class Collection
|
5
|
+
private_class_method def self.fetch url
|
6
|
+
json = Request.get(url)
|
7
|
+
objects = json["objects"]
|
8
|
+
next_url = json["meta"]["next"]
|
9
|
+
objects += fetch(next_url) if next_url
|
10
|
+
objects
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.field key
|
14
|
+
@fields ||= []
|
15
|
+
@fields << key
|
16
|
+
attr_accessor key
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.fields
|
20
|
+
@fields
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize attributes={}
|
24
|
+
self.attributes = attributes
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes= attributes
|
28
|
+
attributes.each do |key, value|
|
29
|
+
send :"#{key}=", value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def == other
|
34
|
+
self.attributes == other.attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributes
|
38
|
+
self.class.fields.reduce({}) do |attrs, key|
|
39
|
+
attrs.merge key => send(key)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :to_h, :attributes
|
44
|
+
end
|
45
|
+
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
|
data/lib/amaranth/project.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
require "amaranth/
|
1
|
+
require "amaranth/collection"
|
2
2
|
|
3
3
|
module Amaranth
|
4
|
-
class Project <
|
4
|
+
class Project < Collection
|
5
|
+
field :name
|
6
|
+
field :slug
|
7
|
+
field :team_slug
|
8
|
+
|
5
9
|
def self.all team_slug:
|
6
|
-
|
7
|
-
|
10
|
+
url = "/api/teams/#{team_slug}/projects/?limit=100"
|
11
|
+
fetch(url).map do |attributes|
|
12
|
+
attributes = attributes.keep_if { |key, value| fields.include? key.to_sym }
|
8
13
|
attributes["team_slug"] = team_slug
|
9
14
|
new attributes
|
10
15
|
end
|
@@ -25,12 +30,6 @@ module Amaranth
|
|
25
30
|
all(team_slug: team_slug).find { |project| project.slug == slug }
|
26
31
|
end
|
27
32
|
|
28
|
-
def initialize attributes={}
|
29
|
-
attributes.each do |key, value|
|
30
|
-
self[key] = value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
33
|
def videos
|
35
34
|
Video.all(team_slug: team_slug, project_slug: slug)
|
36
35
|
end
|
data/lib/amaranth/version.rb
CHANGED
data/lib/amaranth/video.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
require "amaranth/
|
1
|
+
require "amaranth/collection"
|
2
2
|
|
3
3
|
module Amaranth
|
4
|
-
class Video <
|
4
|
+
class Video < Collection
|
5
|
+
field :id
|
6
|
+
field :title
|
7
|
+
field :description
|
8
|
+
field :duration
|
9
|
+
field :primary_audio_language_code
|
10
|
+
field :thumbnail
|
11
|
+
field :team
|
12
|
+
field :project
|
13
|
+
field :all_urls
|
14
|
+
field :languages
|
15
|
+
|
5
16
|
def self.all team_slug: nil, project_slug: nil
|
6
17
|
url = "https://amara.org/api/videos/?limit=100"
|
7
18
|
url += "&team=#{team_slug}" if team_slug
|
8
19
|
url += "&project=#{project_slug}" if project_slug
|
9
20
|
fetch(url).map do |attributes|
|
10
|
-
new attributes.keep_if { |key, value|
|
21
|
+
new attributes.keep_if { |key, value| fields.include? key.to_sym }
|
11
22
|
end
|
12
23
|
end
|
13
24
|
|
14
|
-
private_class_method def self.fetch url
|
15
|
-
json = Request.get(url)
|
16
|
-
objects = json["objects"]
|
17
|
-
next_url = json["meta"]["next"]
|
18
|
-
objects += fetch(next_url) if next_url
|
19
|
-
objects
|
20
|
-
end
|
21
|
-
|
22
25
|
def self.create attributes
|
23
26
|
Request.post("/api/videos/", attributes)
|
24
27
|
end
|
@@ -26,7 +29,7 @@ module Amaranth
|
|
26
29
|
def self.find_by_video_url video_url
|
27
30
|
if json = Request.get("/api/videos/?video_url=#{video_url}")
|
28
31
|
attributes = json["objects"].first
|
29
|
-
new attributes.keep_if { |key, value|
|
32
|
+
new attributes.keep_if { |key, value| fields.include? key.to_sym }
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
@@ -37,16 +40,8 @@ module Amaranth
|
|
37
40
|
Amaranth::Video.find_by_video_url(video_url).update(attributes)
|
38
41
|
end
|
39
42
|
|
40
|
-
def initialize attributes={}
|
41
|
-
attributes.each do |key, value|
|
42
|
-
self[key] = value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
43
|
def update attributes={}
|
47
|
-
attributes
|
48
|
-
self[key] = value
|
49
|
-
end
|
44
|
+
self.attributes = attributes
|
50
45
|
save
|
51
46
|
end
|
52
47
|
|
@@ -62,6 +57,10 @@ module Amaranth
|
|
62
57
|
id.to_s.length > 0
|
63
58
|
end
|
64
59
|
|
60
|
+
def fetch_languages
|
61
|
+
Language.all(video_id: id)
|
62
|
+
end
|
63
|
+
|
65
64
|
private
|
66
65
|
|
67
66
|
READONLY_ATTRIBUTES = %i(all_urls languages)
|
data/lib/amaranth.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-12 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: '
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.0'
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- micah@botandrose.com
|
@@ -59,6 +59,7 @@ 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"
|
@@ -70,7 +71,9 @@ files:
|
|
70
71
|
- bin/console
|
71
72
|
- bin/setup
|
72
73
|
- lib/amaranth.rb
|
74
|
+
- lib/amaranth/collection.rb
|
73
75
|
- lib/amaranth/config.rb
|
76
|
+
- lib/amaranth/language.rb
|
74
77
|
- lib/amaranth/project.rb
|
75
78
|
- lib/amaranth/request.rb
|
76
79
|
- lib/amaranth/team.rb
|
@@ -95,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '0'
|
97
100
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.4.8
|
101
|
+
rubygems_version: 3.5.11
|
100
102
|
signing_key:
|
101
103
|
specification_version: 4
|
102
104
|
summary: Library for accessing the Amara REST API
|