amaranth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +7 -0
- data/amaranth.gemspec +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/amaranth.rb +8 -0
- data/lib/amaranth/config.rb +5 -0
- data/lib/amaranth/project.rb +39 -0
- data/lib/amaranth/request.rb +39 -0
- data/lib/amaranth/team.rb +26 -0
- data/lib/amaranth/version.rb +3 -0
- data/lib/amaranth/video.rb +76 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fbcb3bfd0d621e2c3a6c7e4236787b2582ce1c3
|
4
|
+
data.tar.gz: ea9e65e7356762f769f3e92d82e9580109b9dcc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 605def05c4af919d5048586db6b98f6288927961585d55a741e38b053ef9287278604a5002eda143646c48999090d900cd22a5eb1565573c366023db8c84d12e
|
7
|
+
data.tar.gz: 07e1af87aae56a482b24b266eebf0e23d43ecf17e04b638c9f485f7b4324c160f89d573e14f6539586864b1f0b3cf19b39848f7c0e41ebf63c9c910106201019
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Micah Geisel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Amaranth
|
2
|
+
[![Build Status](https://travis-ci.org/botandrose/amaranth.svg)](https://travis-ci.org/botandrose/amaranth)
|
3
|
+
|
4
|
+
Library for accessing the Amara REST API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'amaranth'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install amaranth
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/botandrose/amaranth/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/amaranth.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'amaranth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "amaranth"
|
8
|
+
spec.version = Amaranth::VERSION
|
9
|
+
spec.authors = ["Micah Geisel"]
|
10
|
+
spec.email = ["micah@botandrose.com"]
|
11
|
+
|
12
|
+
spec.summary = "Library for accessing the Amara REST API"
|
13
|
+
spec.homepage = "https://github.com/botandrose/amaranth"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "webmock", "~> 1.0"
|
24
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "amaranth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/amaranth.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "amaranth/request"
|
2
|
+
|
3
|
+
module Amaranth
|
4
|
+
class Project < Struct.new(:name, :slug, :team_slug)
|
5
|
+
def self.all team_slug:
|
6
|
+
Request.get("/api/teams/#{team_slug}/projects/").map do |attributes|
|
7
|
+
attributes = attributes.keep_if { |key, value| members.include? key.to_sym }
|
8
|
+
attributes["team_slug"] = team_slug
|
9
|
+
new attributes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.delete team_slug:, slug:
|
14
|
+
Request.delete("/api/teams/#{team_slug}/projects/#{slug}/")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create attributes
|
18
|
+
team_slug = attributes.delete(:team_slug)
|
19
|
+
if Request.post("/api/teams/#{team_slug}/projects/", attributes)
|
20
|
+
new attributes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find team_slug:, slug:
|
25
|
+
all(team_slug: team_slug).find { |project| project.slug == slug }
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize attributes={}
|
29
|
+
attributes.each do |key, value|
|
30
|
+
self[key] = value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def videos
|
35
|
+
Video.all(team_slug: team_slug, project_slug: slug)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "amaranth/config"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
module Amaranth
|
6
|
+
class RequestError < StandardError; end
|
7
|
+
|
8
|
+
class Request
|
9
|
+
def self.get path
|
10
|
+
result = request(Net::HTTP::Get.new(path))
|
11
|
+
JSON.parse(result.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.post path, body
|
15
|
+
result = request(Net::HTTP::Post.new(path), JSON.dump(body))
|
16
|
+
result.code == "201" or raise Amaranth::RequestError, result.body
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.put path, body
|
20
|
+
result = request(Net::HTTP::Put.new(path), JSON.dump(body))
|
21
|
+
result.code == "200" or raise Amaranth::RequestError, result.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.delete path
|
25
|
+
result = request(Net::HTTP::Delete.new(path))
|
26
|
+
result.code == "200" or raise Amaranth::RequestError, result.body
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.request req, body = nil
|
30
|
+
Net::HTTP.start("www.amara.org") do |http|
|
31
|
+
req["Content-Type"] = "application/json"
|
32
|
+
req["X-api-username"] = Amaranth.api_username
|
33
|
+
req["X-api-key"] = Amaranth.api_key
|
34
|
+
req.body = body
|
35
|
+
http.request(req)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "amaranth/request"
|
2
|
+
|
3
|
+
module Amaranth
|
4
|
+
class Team < Struct.new(:name, :slug)
|
5
|
+
def self.find_by_slug slug
|
6
|
+
if attributes = Request.get("/api/teams/#{slug}/")
|
7
|
+
new attributes.keep_if { |key, value| members.include? key.to_sym }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize attributes={}
|
12
|
+
attributes.each do |key, value|
|
13
|
+
self[key] = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def projects
|
18
|
+
Project.all(team_slug: slug)
|
19
|
+
end
|
20
|
+
|
21
|
+
def videos
|
22
|
+
Video.all(team_slug: slug)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "amaranth/request"
|
2
|
+
require "open-uri"
|
3
|
+
|
4
|
+
module Amaranth
|
5
|
+
class Video < Struct.new(:id, :title, :description, :duration, :primary_audio_language_code, :thumbnail, :team, :project, :all_urls, :languages)
|
6
|
+
def self.all team_slug: nil, project_slug: nil
|
7
|
+
url = "https://www.amara.org/api/videos/?limit=100"
|
8
|
+
url += "&team=#{team_slug}" if team_slug
|
9
|
+
url += "&project=#{project_slug}" if project_slug
|
10
|
+
fetch(url).map do |attributes|
|
11
|
+
new attributes.keep_if { |key, value| members.include? key.to_sym }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
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
|
+
def self.create attributes
|
24
|
+
Request.post("/api/videos/", attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_by_video_url video_url
|
28
|
+
if json = Request.get("/api/videos/?video_url=#{video_url}")
|
29
|
+
attributes = json["objects"].first
|
30
|
+
new attributes.keep_if { |key, value| members.include? key.to_sym }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create_or_update_by_video_url video_url, attributes
|
35
|
+
Amaranth::Video.create attributes.merge(video_url: video_url)
|
36
|
+
rescue Amaranth::RequestError => exception
|
37
|
+
raise unless exception.message.include?("Video already exists")
|
38
|
+
Amaranth::Video.find_by_video_url(video_url).update(attributes)
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize attributes={}
|
42
|
+
attributes.each do |key, value|
|
43
|
+
self[key] = value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update attributes={}
|
48
|
+
attributes.each do |key, value|
|
49
|
+
self[key] = value
|
50
|
+
end
|
51
|
+
save
|
52
|
+
end
|
53
|
+
|
54
|
+
def save
|
55
|
+
if persisted?
|
56
|
+
save_existing
|
57
|
+
else
|
58
|
+
raise NotImplementedError
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def persisted?
|
63
|
+
id.to_s.length > 0
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
READONLY_ATTRIBUTES = %i(all_urls languages)
|
69
|
+
|
70
|
+
def save_existing
|
71
|
+
attributes = to_h.delete_if { |key, _| READONLY_ATTRIBUTES.include?(key) }
|
72
|
+
Request.put("/api/videos/#{id}/", attributes)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amaranth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah Geisel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- micah@botandrose.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- amaranth.gemspec
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/amaranth.rb
|
73
|
+
- lib/amaranth/config.rb
|
74
|
+
- lib/amaranth/project.rb
|
75
|
+
- lib/amaranth/request.rb
|
76
|
+
- lib/amaranth/team.rb
|
77
|
+
- lib/amaranth/version.rb
|
78
|
+
- lib/amaranth/video.rb
|
79
|
+
homepage: https://github.com/botandrose/amaranth
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.8
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Library for accessing the Amara REST API
|
103
|
+
test_files: []
|