amaranth 0.3.0 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/amaranth.gemspec +1 -1
- data/bin/setup +0 -0
- data/lib/amaranth/collection.rb +45 -0
- data/lib/amaranth/project.rb +9 -10
- data/lib/amaranth/request.rb +1 -1
- data/lib/amaranth/version.rb +1 -1
- data/lib/amaranth/video.rb +18 -24
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bea88580a7f06515df9387ff76c565d07d8c58b7f2a28c86cc7a89d98248d138
|
4
|
+
data.tar.gz: 21acbfab6b730697f2ecad0290184341396831032f5d3d23ab728c92b2e71fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90719c85924793222d350857e0552ff1d14664e1222344f56a8cfe7b4635b7b627dcf740b60ddf9792ca562262c48d151f6fc69b45e0c1fa9ca29c09ebb38c3
|
7
|
+
data.tar.gz: 969f665cb658394e64f3492f0202d20976f4574c63de68fa78c9e5fc7916a368b216424de71ec4c950084e1aed3274800fb5cfc7291de7b1d74affe39b2ec7ad
|
data/amaranth.gemspec
CHANGED
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
|
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/request.rb
CHANGED
@@ -27,7 +27,7 @@ module Amaranth
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.request req, body = nil
|
30
|
-
Net::HTTP.start("
|
30
|
+
Net::HTTP.start("amara.org", use_ssl: true) do |http|
|
31
31
|
req["Content-Type"] = "application/json"
|
32
32
|
req["X-api-username"] = Amaranth.api_username
|
33
33
|
req["X-api-key"] = Amaranth.api_key
|
data/lib/amaranth/version.rb
CHANGED
data/lib/amaranth/video.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
require "amaranth/
|
2
|
-
require "open-uri"
|
1
|
+
require "amaranth/collection"
|
3
2
|
|
4
3
|
module Amaranth
|
5
|
-
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
|
+
|
6
16
|
def self.all team_slug: nil, project_slug: nil
|
7
|
-
url = "https://
|
17
|
+
url = "https://amara.org/api/videos/?limit=100"
|
8
18
|
url += "&team=#{team_slug}" if team_slug
|
9
19
|
url += "&project=#{project_slug}" if project_slug
|
10
20
|
fetch(url).map do |attributes|
|
11
|
-
new attributes.keep_if { |key, value|
|
21
|
+
new attributes.keep_if { |key, value| fields.include? key.to_sym }
|
12
22
|
end
|
13
23
|
end
|
14
24
|
|
15
|
-
private_class_method def self.fetch url
|
16
|
-
json = JSON.parse(open(url).read)
|
17
|
-
objects = json["objects"]
|
18
|
-
next_url = json["meta"]["next"]
|
19
|
-
objects += fetch(next_url) if next_url
|
20
|
-
objects
|
21
|
-
end
|
22
|
-
|
23
25
|
def self.create attributes
|
24
26
|
Request.post("/api/videos/", attributes)
|
25
27
|
end
|
@@ -27,27 +29,19 @@ module Amaranth
|
|
27
29
|
def self.find_by_video_url video_url
|
28
30
|
if json = Request.get("/api/videos/?video_url=#{video_url}")
|
29
31
|
attributes = json["objects"].first
|
30
|
-
new attributes.keep_if { |key, value|
|
32
|
+
new attributes.keep_if { |key, value| fields.include? key.to_sym }
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
def self.create_or_update_by_video_url video_url, attributes
|
35
37
|
Amaranth::Video.create attributes.merge(video_url: video_url)
|
36
38
|
rescue Amaranth::RequestError => exception
|
37
|
-
raise unless exception.message.include?("Video already
|
39
|
+
raise unless exception.message.include?("Video already ")
|
38
40
|
Amaranth::Video.find_by_video_url(video_url).update(attributes)
|
39
41
|
end
|
40
42
|
|
41
|
-
def initialize attributes={}
|
42
|
-
attributes.each do |key, value|
|
43
|
-
self[key] = value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
43
|
def update attributes={}
|
48
|
-
attributes
|
49
|
-
self[key] = value
|
50
|
-
end
|
44
|
+
self.attributes = attributes
|
51
45
|
save
|
52
46
|
end
|
53
47
|
|
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.3.
|
4
|
+
version: 0.3.4
|
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: 2021-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -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
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
72
|
- lib/amaranth.rb
|
73
|
+
- lib/amaranth/collection.rb
|
73
74
|
- lib/amaranth/config.rb
|
74
75
|
- lib/amaranth/project.rb
|
75
76
|
- lib/amaranth/request.rb
|
@@ -95,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.4.8
|
99
|
+
rubygems_version: 3.0.8
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Library for accessing the Amara REST API
|