amara 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +11 -0
- data/amara.gemspec +30 -0
- data/lib/.DS_Store +0 -0
- data/lib/amara.rb +45 -0
- data/lib/amara/api.rb +103 -0
- data/lib/amara/api_factory.rb +13 -0
- data/lib/amara/client.rb +19 -0
- data/lib/amara/configuration.rb +61 -0
- data/lib/amara/connection.rb +46 -0
- data/lib/amara/languages.rb +6 -0
- data/lib/amara/response.rb +112 -0
- data/lib/amara/teams.rb +15 -0
- data/lib/amara/teams/members.rb +6 -0
- data/lib/amara/teams/projects.rb +6 -0
- data/lib/amara/version.rb +5 -0
- data/lib/amara/videos.rb +20 -0
- data/lib/amara/videos/languages.rb +11 -0
- data/lib/amara/videos/languages/subtitles.rb +6 -0
- data/lib/amara/videos/urls.rb +6 -0
- data/test/api_test.rb +73 -0
- data/test/client_test.rb +12 -0
- data/test/teams/projects_test.rb +33 -0
- data/test/teams_test.rb +57 -0
- data/test/test_helper.rb +8 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39b648a9d9d4ec8b3d696a4e3a74e3d299a4ad6e
|
4
|
+
data.tar.gz: 29c2865c646fdd2614d652c9cd53c8f24b2b07ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dd1b533b9c6eae14e2eeb194b01be2b3594b2c9d51c2f7e4d3e178901029b982b4d4f3df93c840f32ea50fbc4bff4637ee5b1db117b358a3504e9a58532d475
|
7
|
+
data.tar.gz: 81a23ab2d4a75b472a3ada63f86c25bb61306da07af21fafd852a393a506037b9179b1ff9fab038f6ab3c69759d1f7cbeb1639f470f3cbafa5d6e1065deb70d7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Kuklewicz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Amara
|
2
|
+
|
3
|
+
Ruby gem to access the Amara API.
|
4
|
+
|
5
|
+
http://www.amara.org/
|
6
|
+
http://amara.readthedocs.org/en/latest/api.html
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'amara'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install amara
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You need a user account and API key to use the API.
|
25
|
+
Some capabilities (e.g. creating a team) are only enabled for enterprise customers.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
amara = Amara::Client.new(api_username: 'amara_api_username', api_key: 'amara_api_key')
|
29
|
+
amara.videos
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
data/amara.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'amara/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "amara"
|
8
|
+
gem.version = Amara::VERSION
|
9
|
+
gem.authors = ["Andrew Kuklewicz"]
|
10
|
+
gem.email = ["andrew@prx.org"]
|
11
|
+
gem.description = %q{Access the amara.org API}
|
12
|
+
gem.summary = %q{Works with API v1.2, http://amara.readthedocs.org/en/latest/api.html}
|
13
|
+
gem.homepage = "https://github.com/PRX/amara"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency('faraday')
|
21
|
+
gem.add_runtime_dependency('faraday_middleware')
|
22
|
+
gem.add_runtime_dependency('multi_json')
|
23
|
+
gem.add_runtime_dependency('excon')
|
24
|
+
gem.add_runtime_dependency('hashie')
|
25
|
+
gem.add_runtime_dependency('activesupport')
|
26
|
+
|
27
|
+
gem.add_development_dependency('rake')
|
28
|
+
gem.add_development_dependency('minitest')
|
29
|
+
gem.add_development_dependency('webmock')
|
30
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/amara.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
require 'amara/version'
|
7
|
+
require 'amara/configuration'
|
8
|
+
require 'amara/connection'
|
9
|
+
require 'amara/response'
|
10
|
+
require 'amara/api'
|
11
|
+
require 'amara/api_factory'
|
12
|
+
require 'amara/languages'
|
13
|
+
require 'amara/teams'
|
14
|
+
require 'amara/teams/members'
|
15
|
+
require 'amara/teams/projects'
|
16
|
+
require 'amara/videos'
|
17
|
+
require 'amara/videos/languages'
|
18
|
+
require 'amara/videos/languages/subtitles'
|
19
|
+
require 'amara/videos/urls'
|
20
|
+
require 'amara/client'
|
21
|
+
|
22
|
+
module Amara
|
23
|
+
extend Configuration
|
24
|
+
|
25
|
+
HEADERS = {
|
26
|
+
:api_key => 'X-apikey',
|
27
|
+
:api_username => 'X-api-username'
|
28
|
+
}
|
29
|
+
|
30
|
+
TEAM_POLICIES = {
|
31
|
+
:open => 'Open',
|
32
|
+
:apply => 'Application',
|
33
|
+
:invite => 'Invitation by any team member',
|
34
|
+
:manager_invite => 'Invitation by manager',
|
35
|
+
:admin_invite => 'Invitation by admin'
|
36
|
+
}
|
37
|
+
|
38
|
+
POLICIES = {
|
39
|
+
:anyone => 'Anyone',
|
40
|
+
:member => 'Any team member',
|
41
|
+
:managers => 'Managers and admins',
|
42
|
+
:admins => 'Admins only'
|
43
|
+
}
|
44
|
+
|
45
|
+
end
|
data/lib/amara/api.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
class API
|
5
|
+
|
6
|
+
include Connection
|
7
|
+
|
8
|
+
attr_reader *Amara::Configuration.keys
|
9
|
+
|
10
|
+
attr_accessor :current_options
|
11
|
+
|
12
|
+
class_eval do
|
13
|
+
Amara::Configuration.keys.each do |key|
|
14
|
+
define_method "#{key}=" do |arg|
|
15
|
+
self.instance_variable_set("@#{key}", arg)
|
16
|
+
self.current_options.merge!({:"#{key}" => arg})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(options={}, &block)
|
22
|
+
apply_options(options)
|
23
|
+
yield(self) if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_options(options={})
|
27
|
+
self.current_options ||= ActiveSupport::HashWithIndifferentAccess.new(Amara.options)
|
28
|
+
self.current_options = current_options.merge(args_to_options(options))
|
29
|
+
Configuration.keys.each do |key|
|
30
|
+
send("#{key}=", current_options[key])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def request(method, path, params={}) # :nodoc:
|
35
|
+
unless (method && [:get, :post, :put, :patch, :delete].include?(method))
|
36
|
+
raise ArgumentError, "whoops, that isn't a valid http method: #{method}"
|
37
|
+
end
|
38
|
+
|
39
|
+
conn = connection((params[:options] || {}).merge(current_options))
|
40
|
+
request_path = (conn.path_prefix + '/' + path + '/').gsub(/\/+/, '/')
|
41
|
+
|
42
|
+
response = conn.send(method) do |request|
|
43
|
+
case method.to_sym
|
44
|
+
when :get, :delete
|
45
|
+
request.url(request_path, params)
|
46
|
+
when :post, :put
|
47
|
+
request.path = request_path
|
48
|
+
request.body = params[:data] unless params.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
Amara::Response.new(response, {api: self, method: method, path: path, params: params})
|
52
|
+
end
|
53
|
+
|
54
|
+
def base_path
|
55
|
+
parts = self.class.name.split("::").inject([]){|a, c|
|
56
|
+
if c != 'Amara'
|
57
|
+
base = c.downcase.underscore
|
58
|
+
a << base
|
59
|
+
a << current_options["#{base.singularize}_id"] if current_options["#{base.singularize}_id"]
|
60
|
+
end
|
61
|
+
a
|
62
|
+
}
|
63
|
+
parts.join('/')
|
64
|
+
end
|
65
|
+
|
66
|
+
def paginate(params={})
|
67
|
+
{limit: 20, offset: 0}.merge(params)
|
68
|
+
end
|
69
|
+
|
70
|
+
def list(params={})
|
71
|
+
self.current_options = current_options.merge(args_to_options(params))
|
72
|
+
request(:get, base_path, paginate(params))
|
73
|
+
end
|
74
|
+
|
75
|
+
def get(params={})
|
76
|
+
self.current_options = current_options.merge(args_to_options(params))
|
77
|
+
request(:get, base_path)
|
78
|
+
end
|
79
|
+
|
80
|
+
def create(params={})
|
81
|
+
self.current_options = current_options.merge(args_to_options(params))
|
82
|
+
request(:post, base_path, {data: params})
|
83
|
+
end
|
84
|
+
|
85
|
+
def update(params={})
|
86
|
+
self.current_options = current_options.merge(args_to_options(params))
|
87
|
+
request(:put, base_path, {data: params})
|
88
|
+
end
|
89
|
+
|
90
|
+
def delete(params={})
|
91
|
+
self.current_options = current_options.merge(args_to_options(params))
|
92
|
+
request(:delete, base_path)
|
93
|
+
end
|
94
|
+
|
95
|
+
def args_to_options(args)
|
96
|
+
params = if args.is_a?(String) || args.is_a?(Symbol)
|
97
|
+
{"#{self.class.name.demodulize.downcase.singularize}_id" => args}
|
98
|
+
elsif args.is_a?(Hash)
|
99
|
+
args
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/amara/client.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
class Client < API
|
5
|
+
|
6
|
+
def teams(params={}, &block)
|
7
|
+
@teams ||= ApiFactory.api('Amara::Teams', self, params, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
# def videos(params={}, &block)
|
11
|
+
# @videos ||= Videos.new(current_options.merge(args_to_options(params)), &block)
|
12
|
+
# end
|
13
|
+
|
14
|
+
def languages(params={}, &block)
|
15
|
+
@languages ||= ApiFactory.api('Amara::Languages', self, params, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:api_username,
|
8
|
+
:api_key,
|
9
|
+
:adapter,
|
10
|
+
:endpoint,
|
11
|
+
:user_agent
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
# this you need to get from amara - go register!
|
15
|
+
DEFAULT_API_USERNAME = nil
|
16
|
+
DEFAULT_API_KEY = nil
|
17
|
+
|
18
|
+
# Adapters are whatever Faraday supports - I like excon alot, so I'm defaulting it
|
19
|
+
DEFAULT_ADAPTER = :excon
|
20
|
+
|
21
|
+
# The api endpoint to get REST
|
22
|
+
DEFAULT_ENDPOINT = 'https://www.amara.org/api2/partners'.freeze
|
23
|
+
|
24
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
25
|
+
DEFAULT_USER_AGENT = "Amara Ruby Gem #{Amara::VERSION}".freeze
|
26
|
+
|
27
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
28
|
+
|
29
|
+
# Convenience method to allow for global setting of configuration options
|
30
|
+
def configure
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.extended(base)
|
35
|
+
base.reset!
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def keys
|
40
|
+
VALID_OPTIONS_KEYS
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def options
|
45
|
+
options = {}
|
46
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
47
|
+
options
|
48
|
+
end
|
49
|
+
|
50
|
+
# Reset configuration options to their defaults
|
51
|
+
def reset!
|
52
|
+
self.api_username = DEFAULT_API_USERNAME
|
53
|
+
self.api_key = DEFAULT_API_KEY
|
54
|
+
self.adapter = DEFAULT_ADAPTER
|
55
|
+
self.endpoint = DEFAULT_ENDPOINT
|
56
|
+
self.user_agent = DEFAULT_USER_AGENT
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
module Amara
|
6
|
+
module Connection
|
7
|
+
|
8
|
+
ALLOWED_OPTIONS = [
|
9
|
+
:headers,
|
10
|
+
:url,
|
11
|
+
:params,
|
12
|
+
:request,
|
13
|
+
:ssl
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def merge_default_options(opts={})
|
17
|
+
headers = opts.delete(:headers) || {}
|
18
|
+
options = {
|
19
|
+
:headers => {
|
20
|
+
'User-Agent' => user_agent,
|
21
|
+
'Accept' => "application/json",
|
22
|
+
'Content-Type' => "application/json"
|
23
|
+
},
|
24
|
+
:ssl => {:verify => false},
|
25
|
+
:url => endpoint
|
26
|
+
}.merge(opts)
|
27
|
+
options[:headers] = options[:headers].merge(headers)
|
28
|
+
Amara::HEADERS.each{|k,v| options[:headers][v] = options.delete(k) if options.key?(k)}
|
29
|
+
options
|
30
|
+
end
|
31
|
+
|
32
|
+
def connection(options={})
|
33
|
+
opts = merge_default_options(options)
|
34
|
+
Faraday::Connection.new(opts) do |connection|
|
35
|
+
connection.request :url_encoded
|
36
|
+
|
37
|
+
connection.response :mashify
|
38
|
+
connection.response :logger if ENV['DEBUG']
|
39
|
+
connection.response :json
|
40
|
+
|
41
|
+
connection.adapter(adapter)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
class Response
|
5
|
+
attr_accessor :raw, :request
|
6
|
+
|
7
|
+
def object
|
8
|
+
if objects.size == 0
|
9
|
+
nil
|
10
|
+
elsif objects.size == 1
|
11
|
+
objects.first
|
12
|
+
elsif objects.size > 1
|
13
|
+
objects
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(response, request={})
|
18
|
+
@raw = response
|
19
|
+
@request = request
|
20
|
+
|
21
|
+
check_for_error(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_for_error(response)
|
25
|
+
status_code_type = response.status.to_s[0]
|
26
|
+
case status_code_type
|
27
|
+
when "2"
|
28
|
+
# puts "all is well, status: #{response.status}"
|
29
|
+
when "4", "5"
|
30
|
+
raise "Whoops, error back from Amara: #{response.status}"
|
31
|
+
else
|
32
|
+
raise "Unrecongized status code: #{response.status}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def body
|
37
|
+
self.raw.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def object
|
41
|
+
body.objects.nil? ? body : body.objects
|
42
|
+
end
|
43
|
+
|
44
|
+
def objects
|
45
|
+
Array(self.object)
|
46
|
+
end
|
47
|
+
|
48
|
+
def [](key)
|
49
|
+
if self.object.is_a?(Array)
|
50
|
+
self.object[key]
|
51
|
+
else
|
52
|
+
self.object.send(:"#{key}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_key?(key)
|
57
|
+
self.object.is_a?(Hash) && self.object.has_key?(key)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Coerce any method calls for body attributes
|
61
|
+
#
|
62
|
+
def method_missing(method_name, *args, &block)
|
63
|
+
if self.has_key?(method_name.to_s)
|
64
|
+
self.[](method_name, &block)
|
65
|
+
elsif self.objects.respond_to?(method_name)
|
66
|
+
self.objects.send(method_name, *args, &block)
|
67
|
+
elsif self.request[:api].respond_to?(method_name)
|
68
|
+
self.request[:api].send(method_name, *args, &block)
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def offset
|
75
|
+
return 0 unless self.body.meta
|
76
|
+
self.body.meta.offset.to_i
|
77
|
+
end
|
78
|
+
|
79
|
+
def total_count
|
80
|
+
return 0 unless self.body.meta
|
81
|
+
self.body.meta.total_count.to_i
|
82
|
+
end
|
83
|
+
|
84
|
+
def limit
|
85
|
+
return 0 unless self.body.meta
|
86
|
+
self.body.meta.limit.to_i
|
87
|
+
end
|
88
|
+
|
89
|
+
def has_next_page?
|
90
|
+
(offset + limit) < total_count
|
91
|
+
end
|
92
|
+
|
93
|
+
def has_previous_page?
|
94
|
+
offset > 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def next_page
|
98
|
+
return nil unless has_next_page?
|
99
|
+
new_offset = [(offset + limit), total_count].min
|
100
|
+
new_response = request[:api].request(request[:method], request[:path], request[:params].merge({offset: new_offset, limit: limit}))
|
101
|
+
self.raw = new_response.raw
|
102
|
+
end
|
103
|
+
|
104
|
+
def previous_page
|
105
|
+
return nil unless has_previous_page?
|
106
|
+
new_offset = [(offset - limit), 0].max
|
107
|
+
new_response = request[:api].request(request[:method], request[:path], request[:params].merge({offset: new_offset, limit: limit}))
|
108
|
+
self.raw = new_response.raw
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/lib/amara/teams.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
class Teams < API
|
5
|
+
|
6
|
+
def members(options={}, &block)
|
7
|
+
@members ||= Teams::Members.new(current_options.merge(args_to_options(options)), &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def projects(options={}, &block)
|
11
|
+
@projects ||= Teams::Projects.new(current_options.merge(args_to_options(options)), &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/amara/videos.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Amara
|
4
|
+
class Videos < API
|
5
|
+
|
6
|
+
VIDEO_ATTRIBUTES = [:all_urls, :created, :description, :duration, :id, :languages, :original_language, :project, :resource_uri, :site_url, :team, :thumbnail, :title]
|
7
|
+
VIDEO_CREATE_PARAMS = [:duration, :primary_audio_language_code, :title, :video_url]
|
8
|
+
VIDEO_LIST_PARAMS = [:order_by, :project, :team, :video_url]
|
9
|
+
VIDEO_ORDERING = [:created, :title]
|
10
|
+
|
11
|
+
def languages(options={}, &block)
|
12
|
+
@languages ||= Videos::Languages.new(current_options.merge(args_to_options(options)), &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def urls(options={}, &block)
|
16
|
+
@urls ||= Videos::Urls.new(current_options.merge(args_to_options(options)), &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
4
|
+
|
5
|
+
# create dummy class based on the API
|
6
|
+
class TestApi < ::Amara::API
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Amara::API do
|
10
|
+
|
11
|
+
before {
|
12
|
+
@amara_api_username = ENV['AMARA_API_USERNAME'] || "testuser"
|
13
|
+
@amara_api_key = ENV['AMARA_API_KEY'] || "thisisatestkeyonly"
|
14
|
+
}
|
15
|
+
|
16
|
+
it "is initialized with defaults" do
|
17
|
+
oc = TestApi.new
|
18
|
+
oc.current_options.wont_be_nil
|
19
|
+
oc.current_options.must_equal HashWithIndifferentAccess.new(Amara.options)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is initialized with specific values" do
|
23
|
+
oc = TestApi.new(api_key: @amara_api_key, api_username: @amara_api_username)
|
24
|
+
oc.current_options.wont_be_nil
|
25
|
+
oc.current_options.wont_equal Amara.options
|
26
|
+
|
27
|
+
oc.current_options[:api_key].must_equal @amara_api_key
|
28
|
+
oc.api_key.must_equal @amara_api_key
|
29
|
+
|
30
|
+
oc.current_options[:api_username].must_equal @amara_api_username
|
31
|
+
oc.api_username.must_equal @amara_api_username
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a list and paginates through it" do
|
35
|
+
first_response = '{"meta": {"limit": 2, "next": "/api2/partners/api/?limit=2&offset=2", "offset": 0, "previous": null, "total_count": 5}, "objects": [{"id": 1}, {"id": 2}]}'
|
36
|
+
stub_request(:get, 'https://www.amara.org/api2/partners/api/?limit=2&offset=0').
|
37
|
+
to_return(body: first_response)
|
38
|
+
|
39
|
+
api = Amara::API.new(api_key: 'thisisakey', api_username: 'test_user')
|
40
|
+
# puts teams.list.raw.inspect
|
41
|
+
|
42
|
+
response = api.list(limit: 2)
|
43
|
+
response.objects.must_equal response.object
|
44
|
+
|
45
|
+
response.offset.must_equal 0
|
46
|
+
response.limit.must_equal 2
|
47
|
+
response.size.must_equal 2
|
48
|
+
response.first.id.must_equal 1
|
49
|
+
|
50
|
+
second_response = '{"meta": {"limit": 2, "next": "/api2/partners/api/?limit=2&offset=4", "offset": 2, "previous":"/api2/partners/api/?limit=2&offset=0", "total_count": 5}, "objects": [{"id": 3}, {"id": 4}]}'
|
51
|
+
stub_request(:get, 'https://www.amara.org/api2/partners/api/?limit=2&offset=2').
|
52
|
+
to_return(body: second_response)
|
53
|
+
|
54
|
+
response.must_be :has_next_page?
|
55
|
+
response.next_page
|
56
|
+
response.offset.must_equal 2
|
57
|
+
response.limit.must_equal 2
|
58
|
+
response.first.id.must_equal 3
|
59
|
+
|
60
|
+
third_response = '{"meta": {"limit": 2, "next": null, "offset": 4, "previous":"/api2/partners/api/?limit=2&offset=2", "total_count": 5}, "objects": [{"id": 5}]}'
|
61
|
+
stub_request(:get, 'https://www.amara.org/api2/partners/api/?limit=2&offset=4').
|
62
|
+
to_return(body: third_response)
|
63
|
+
|
64
|
+
response.must_be :has_next_page?
|
65
|
+
response.next_page
|
66
|
+
response.offset.must_equal 4
|
67
|
+
response.limit.must_equal 2
|
68
|
+
response.first.id.must_equal 5
|
69
|
+
|
70
|
+
response.wont_be :has_next_page?
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
|
+
|
5
|
+
require 'amara/api'
|
6
|
+
require 'amara/teams'
|
7
|
+
require 'amara/teams/projects'
|
8
|
+
|
9
|
+
require 'webmock/minitest'
|
10
|
+
|
11
|
+
describe Amara::Teams::Projects do
|
12
|
+
|
13
|
+
it "gets the base path for this subclass of API" do
|
14
|
+
teams = Amara::Teams::Projects.new(team_id: 'test-team')
|
15
|
+
teams.base_path.must_equal 'teams/test-team/projects'
|
16
|
+
|
17
|
+
teams = Amara::Teams::Projects.new(team_id: 'test-team', project_id: 'test-project')
|
18
|
+
teams.base_path.must_equal 'teams/test-team/projects/test-project'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "gets a list of projects for a team" do
|
22
|
+
|
23
|
+
first_response = '{"meta": {"limit": 2, "next": "/api2/partners/teams/test-team/projects/?limit=2&offset=2", "offset": 0, "previous": null, "total_count": 5}, "objects": [{"created": "2013-02-14T07:29:55"}, {"created": "2011-03-01T11:38:16"}]}'
|
24
|
+
|
25
|
+
stub_request(:get, "https://www.amara.org/api2/partners/teams/test-team/projects/?limit=2&offset=0").
|
26
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Host'=>'www.amara.org:443', 'User-Agent'=>'Amara Ruby Gem 0.0.1'}).
|
27
|
+
to_return(:status => 200, :body => "", :headers => {})
|
28
|
+
|
29
|
+
amara = Amara::Client.new
|
30
|
+
response = amara.teams('test-team').projects.list(limit: 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/teams_test.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
4
|
+
|
5
|
+
require 'amara/api'
|
6
|
+
require 'amara/teams'
|
7
|
+
|
8
|
+
require 'webmock/minitest'
|
9
|
+
|
10
|
+
describe Amara::Client do
|
11
|
+
|
12
|
+
it "gets the base path for this subclass of API" do
|
13
|
+
teams = Amara::Teams.new
|
14
|
+
teams.base_path.must_equal 'teams'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a list of teams" do
|
18
|
+
first_response = '{"meta": {"limit": 2, "next": "/api2/partners/team/?limit=2&offset=2", "offset": 0, "previous": null, "total_count": 5}, "objects": [{"created": "2013-02-14T07:29:55", "deleted": false, "description": "", "header_html_text": "", "is_moderated": false, "is_visible": true, "logo": null, "max_tasks_per_member": null, "membership_policy": "Open", "name": "", "projects_enabled": false, "resource_uri": "/api2/partners/teams/tedx-import/", "slug": "tedx-import", "subtitle_policy": "Anyone", "task_assign_policy": "Any team member", "task_expiration": null, "translate_policy": "Anyone", "video_policy": "Any team member", "workflow_enabled": false}, {"created": "2011-03-01T11:38:16", "deleted": false, "description": "", "header_html_text": "<style>\r\n#custom_header {\r\nbackground: transparent url(http://blog.universalsubtitles.org/wp-content/uploads/2011/03/aljazeera_header_bg.png) 0 0 no-repeat;\r\nwidth: 943px;\r\nheight: 237px;\r\nposition: relative;\r\n}\r\n\r\n.team-detail {\r\ndisplay: none;\r\n}\r\n\r\n#team_video_policy {\r\ndisplay: none;\r\n}\r\n\r\n#team_detail_managers {\r\ndisplay: none;\r\n}\r\n\r\n#team_member_policy {\r\ndisplay: none;\r\n}\r\n\r\n#team_volunteer_detail {\r\ndisplay: block;\r\n}\r\n\r\n#custom_header {\r\nmargin-bottom: 15px;\r\n}\r\n\r\n#team_title {\r\ndisplay: none;\r\n}\r\n\r\n#custom_header a#logo_link {\r\nwidth: 450px;\r\nheight: 91px;\r\ndisplay: block;\r\nposition: absolute;\r\ntop: 88px;\r\nleft: 95px;\r\ntext-indent: -99999px;\r\n}\r\n\r\n#custom_header #sidecol {\r\nwidth: 290px;\r\nheight: 200px;\r\nfloat: right;\r\nmargin: 30px 12px 0 0;\r\n}\r\n\r\n#custom_header #sidecol h1 {\r\nfont-size: 18px;\r\nfont-weight: bold;\r\ntext-shadow: 0 -1px 0 #f97f00;\r\ncolor: #FFF;\r\nmargin: 0 0 15px 0;\r\n}\r\n#custom_header #sidecol p {\r\nfont-size: 15px;\r\nline-height: 25px;\r\ntext-shadow: 0 -1px 0 #f97f00;\r\ncolor: #FFF;\r\nwidth: 280px;\r\n}\r\n</style>\r\n<div id=\"custom_header\">\r\n<a id=\"logo_link\" href=\"http://english.aljazeera.net\">Al Jazeera</a>\r\n<div id=\"sidecol\">\r\n<h1>Join the Translation Team</h1>\r\n<p>These are some of the popular Al Jazeera videos in English and Arabic, as well as other videos that complement Al Jazeera\'s news output from around the globe.</p>\r\n</div><!-- // sidecol -->\r\n</div><!-- // custom_header -->", "is_moderated": false, "is_visible": true, "logo": "http://s3.amazonaws.com/s3.userdata.staging.amara.org/teams/logo/6f94ad51700869bc359bbb750f1420e0a05493f1.png", "max_tasks_per_member": null, "membership_policy": "Open", "name": "Al Jazeera", "projects_enabled": false, "resource_uri": "/api2/partners/teams/al-jazeera/", "slug": "al-jazeera", "subtitle_policy": "Anyone", "task_assign_policy": "Any team member", "task_expiration": null, "translate_policy": "Anyone", "video_policy": "Admins only", "workflow_enabled": false}]}'
|
19
|
+
stub_request(:get, 'https://www.amara.org/api2/partners/teams/?limit=2&offset=0').
|
20
|
+
to_return(body: first_response)
|
21
|
+
|
22
|
+
teams = Amara::Teams.new(api_key: 'thisisakey', api_username: 'test_user')
|
23
|
+
# puts teams.list.raw.inspect
|
24
|
+
|
25
|
+
response = teams.list(limit: 2)
|
26
|
+
response.objects.must_equal response.object
|
27
|
+
|
28
|
+
response.offset.must_equal 0
|
29
|
+
response.limit.must_equal 2
|
30
|
+
response.size.must_equal 2
|
31
|
+
response.first.slug.must_equal "tedx-import"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a team" do
|
35
|
+
response = '{"created": "2013-02-14T07:29:55", "deleted": false, "description": "", "header_html_text": "", "is_moderated": false, "is_visible": true, "logo": null, "max_tasks_per_member": null, "membership_policy": "Open", "name": "", "projects_enabled": false, "resource_uri": "/api2/partners/teams/tedx-import/", "slug": "tedx-import", "subtitle_policy": "Anyone", "task_assign_policy": "Any team member", "task_expiration": null, "translate_policy": "Anyone", "video_policy": "Any team member", "workflow_enabled": false}'
|
36
|
+
stub_request(:get, "https://www.amara.org/api2/partners/teams/tedx-import/").
|
37
|
+
to_return(body: response)
|
38
|
+
|
39
|
+
teams = Amara::Teams.new(api_key: 'thisisakey', api_username: 'test_user')
|
40
|
+
# puts teams.list.raw.inspect
|
41
|
+
|
42
|
+
response = teams.get("tedx-import")
|
43
|
+
response.object.wont_be_nil
|
44
|
+
team = response.object
|
45
|
+
team.slug.must_equal 'tedx-import'
|
46
|
+
|
47
|
+
response = teams.get(team_id: "tedx-import")
|
48
|
+
response.object.wont_be_nil
|
49
|
+
team = response.object
|
50
|
+
team.slug.must_equal 'tedx-import'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "created a new team" do
|
54
|
+
create_response = '{"created": "2013-08-01T13:11:45.167206", "deleted": false, "description": "", "header_html_text": "", "is_moderated": false, "is_visible": true, "logo": null, "max_tasks_per_member": null, "membership_policy": "Open", "name": "prx test 1", "projects_enabled": false, "resource_uri": "/api2/partners/teams/prx-test-1/", "slug": "prx-test-1", "subtitle_policy": "Anyone", "task_assign_policy": "Any team member", "task_expiration": null, "translate_policy": "Anyone", "video_policy": "Any team member", "workflow_enabled": false}'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amara
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kuklewicz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: excon
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Access the amara.org API
|
140
|
+
email:
|
141
|
+
- andrew@prx.org
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- Gemfile
|
148
|
+
- LICENSE.txt
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- amara.gemspec
|
152
|
+
- lib/.DS_Store
|
153
|
+
- lib/amara.rb
|
154
|
+
- lib/amara/api.rb
|
155
|
+
- lib/amara/api_factory.rb
|
156
|
+
- lib/amara/client.rb
|
157
|
+
- lib/amara/configuration.rb
|
158
|
+
- lib/amara/connection.rb
|
159
|
+
- lib/amara/languages.rb
|
160
|
+
- lib/amara/response.rb
|
161
|
+
- lib/amara/teams.rb
|
162
|
+
- lib/amara/teams/members.rb
|
163
|
+
- lib/amara/teams/projects.rb
|
164
|
+
- lib/amara/version.rb
|
165
|
+
- lib/amara/videos.rb
|
166
|
+
- lib/amara/videos/languages.rb
|
167
|
+
- lib/amara/videos/languages/subtitles.rb
|
168
|
+
- lib/amara/videos/urls.rb
|
169
|
+
- test/api_test.rb
|
170
|
+
- test/client_test.rb
|
171
|
+
- test/teams/projects_test.rb
|
172
|
+
- test/teams_test.rb
|
173
|
+
- test/test_helper.rb
|
174
|
+
homepage: https://github.com/PRX/amara
|
175
|
+
licenses: []
|
176
|
+
metadata: {}
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.0.3
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: Works with API v1.2, http://amara.readthedocs.org/en/latest/api.html
|
197
|
+
test_files:
|
198
|
+
- test/api_test.rb
|
199
|
+
- test/client_test.rb
|
200
|
+
- test/teams/projects_test.rb
|
201
|
+
- test/teams_test.rb
|
202
|
+
- test/test_helper.rb
|