amara 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb71839ee3ae5733b9a9cf50421a0d8dae793773
4
- data.tar.gz: 50244918e66cb0378bae5a1a751aca9fe16f4068
3
+ metadata.gz: 6cd6ab24e7e99f8366d46abe69365bed8f663837
4
+ data.tar.gz: 3e79c86e57e157e5a2cf4900bbb2cff53db291d4
5
5
  SHA512:
6
- metadata.gz: be6217c3aafff5c865fd9a788249a9d3f033b9ce21b204fcff87959437ac24312486cf8903541c8157d3c20f7da01d8f496e30bd1c53881374dfc0707cb581b3
7
- data.tar.gz: 4fac54ac1e87d09581392502ec04904a127d7adb81e3bd007c19cbb1782354fd014d8d7c3390db323ebdbce9a42c763c57c42f190556c4e62feb680209091a5d
6
+ metadata.gz: 3db329af8e80bed9175df220a782f26561788ad499fc77a72e09556ce6a293f52fb009e885645fe8dde0c216600247fb0c8f96fa1a280519757cd02ed077869f
7
+ data.tar.gz: 632e1937893a11752655146393fc9975a31346f0ed213bb9754841c82fa6db7213f776f89bd68bec4e8f918d6df4903dfefb4720fdf5eb7765f85a153c05ca35
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Ruby gem to access the Amara API.
4
4
 
5
5
  http://www.amara.org/
6
+
6
7
  http://amara.readthedocs.org/en/latest/api.html
7
8
 
8
9
  ## Installation
@@ -24,9 +25,81 @@ Or install it yourself as:
24
25
  You need a user account and API key to use the API.
25
26
  Some capabilities (e.g. creating a team) are only enabled for enterprise customers.
26
27
 
28
+ You can use the API on these top level and nested entities (see the client.rb for top level) that match the APi docs:
29
+
27
30
  ```ruby
28
- amara = Amara::Client.new(api_username: 'amara_api_username', api_key: 'amara_api_key')
31
+ amara = Amara::Client.new
32
+
29
33
  amara.videos
34
+ amara.videos.languages
35
+ amara.videos.languages.subtitles
36
+ amara.videos.urls
37
+
38
+ amara.users
39
+
40
+ amara.teams
41
+ amara.teams.applications
42
+ amara.teams.members
43
+ amara.teams.projects
44
+ amara.teams.safe_members
45
+ amara.teams.tasks
46
+
47
+ amara.activity
48
+
49
+ amara.languages
50
+
51
+ amara.message
52
+ ```
53
+
54
+ For each type of entity, you get the following methods: `list`, `get`, `create`, `update`, and `delete`.
55
+
56
+ All these method calls return an `Amara::Response` instance.
57
+
58
+ Entities may be nested, and params passed in for each nesting.
59
+ params to an entity can be a Hash of options, or a string, in which case it is treated like the id of that entity type.
60
+
61
+ Here is an example of how to get the English subtitles for a video with a certain id.
62
+ It shows the use of nested entities, string id params for each entity, and the get method called with no query params:
63
+ ```ruby
64
+ amara = Amara::Client.new(api_username: 'amara_api_username', api_key: 'amara_api_key')
65
+
66
+ # get the English subtitles for a video
67
+ amara.videos('yourVideoId').languages('en').subtitles.get
68
+
69
+ ```
70
+
71
+ Here are some more examples of listing and creating a video:
72
+ ```ruby
73
+ # get a list of videos
74
+ amara = Amara::Client.new(api_username: 'amara_api_username', api_key: 'amara_api_key')
75
+ response = amara.videos
76
+ videos = response.objects.list
77
+
78
+ # amara responses for a 'list' are paged, get the next page like this:
79
+ more_videos = response.next_page
80
+
81
+
82
+ # create a video
83
+ response = amara.videos.create({
84
+ team: 'my-team-name',
85
+ title: 'title',
86
+ video_url: 'https://archive.org/download/example/example.ogg',
87
+ primary_audio_language_code: 'en'
88
+ })
89
+ video = response.object
90
+ ```
91
+
92
+ You can do these same operations for Teams and other entities.
93
+ The gem defines lists of `Amara::POLICIES` and `Amara::TEAM_POLICIES` you can use in your requests:
94
+ ```ruby
95
+ # create a team
96
+ new_team = amara.teams.create(
97
+ slug: 'prx-test-1',
98
+ name: 'prx test 1',
99
+ is_visible: false,
100
+ membership_policy: Amara::TEAM_POLICIES[:invite]
101
+ )
102
+
30
103
  ```
31
104
 
32
105
  ## Contributing
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Amara
4
+ class Activity < API
5
+ end
6
+ end
@@ -3,6 +3,18 @@
3
3
  module Amara
4
4
  class Client < API
5
5
 
6
+ def activity(params={}, &block)
7
+ @activity ||= ApiFactory.api('Amara::Activity', self, params, &block)
8
+ end
9
+
10
+ def languages(params={}, &block)
11
+ @languages ||= ApiFactory.api('Amara::Languages', self, params, &block)
12
+ end
13
+
14
+ def message(params={}, &block)
15
+ @message ||= ApiFactory.api('Amara::Message', self, params, &block)
16
+ end
17
+
6
18
  def teams(params={}, &block)
7
19
  @teams ||= ApiFactory.api('Amara::Teams', self, params, &block)
8
20
  end
@@ -11,8 +23,8 @@ module Amara
11
23
  @videos ||= ApiFactory.api('Amara::Videos', self, params, &block)
12
24
  end
13
25
 
14
- def languages(params={}, &block)
15
- @languages ||= ApiFactory.api('Amara::Languages', self, params, &block)
26
+ def users(params={}, &block)
27
+ @users ||= ApiFactory.api('Amara::Users', self, params, &block)
16
28
  end
17
29
 
18
30
  end
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Amara
4
+ class Message < API
5
+ end
6
+ end
@@ -3,6 +3,10 @@
3
3
  module Amara
4
4
  class Teams < API
5
5
 
6
+ def applications(params={}, &block)
7
+ @applications ||= ApiFactory.api('Amara::Teams::Applications', self, params, &block)
8
+ end
9
+
6
10
  def members(params={}, &block)
7
11
  @members ||= ApiFactory.api('Amara::Teams::Members', self, params, &block)
8
12
  end
@@ -15,5 +19,9 @@ module Amara
15
19
  @safe_members ||= ApiFactory.api('Amara::Teams::SafeMembers', self, params, &block)
16
20
  end
17
21
 
22
+ def tasks(params={}, &block)
23
+ @tasks ||= ApiFactory.api('Amara::Teams::Tasks', self, params, &block)
24
+ end
25
+
18
26
  end
19
27
  end
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Amara
4
+ class Teams::Applications < API
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Amara
4
+ class Teams::Tasks < API
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Amara
4
+ class Users < API
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Amara
4
- VERSION = "0.0.4"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -8,11 +8,11 @@ module Amara
8
8
  VIDEO_LIST_PARAMS = [:order_by, :project, :team, :video_url]
9
9
  VIDEO_ORDERING = [:created, :title]
10
10
 
11
- def languages(options={}, &block)
11
+ def languages(params={}, &block)
12
12
  @languages ||= ApiFactory.api('Amara::Videos::Languages', self, params, &block)
13
13
  end
14
14
 
15
- def urls(options={}, &block)
15
+ def urls(params={}, &block)
16
16
  @urls ||= ApiFactory.api('Amara::Videos::Urls', self, params, &block)
17
17
  end
18
18
 
@@ -3,7 +3,7 @@
3
3
  module Amara
4
4
  class Videos::Languages < API
5
5
 
6
- def subtitles(options={}, &block)
6
+ def subtitles(params={}, &block)
7
7
  @subtitles ||= ApiFactory.api('Amara::Videos::Languages::Subtitles', self, params, &block)
8
8
  end
9
9
 
@@ -31,25 +31,36 @@ describe Amara::Teams do
31
31
  end
32
32
 
33
33
  it "returns a team" do
34
- 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}'
35
- stub_request(:get, "https://www.amara.org/api2/partners/teams/tedx-import/").
34
+ 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": "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}'
35
+ stub_request(:get, "https://www.amara.org/api2/partners/teams/prx-test-1/").
36
36
  to_return(body: response)
37
37
 
38
38
  teams = Amara::Teams.new(api_key: 'thisisakey', api_username: 'test_user')
39
39
 
40
- response = teams.get("tedx-import")
40
+ response = teams.get("prx-test-1")
41
41
  response.object.wont_be_nil
42
42
  team = response.object
43
- team.slug.must_equal 'tedx-import'
43
+ team.slug.must_equal 'prx-test-1'
44
44
 
45
- response = teams.get(team_id: "tedx-import")
45
+ response = teams.get(team_id: "prx-test-1")
46
46
  response.object.wont_be_nil
47
47
  team = response.object
48
- team.slug.must_equal 'tedx-import'
48
+ team.slug.must_equal 'prx-test-1'
49
49
  end
50
50
 
51
51
  it "created a new team" do
52
52
  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}'
53
+
54
+ stub_request(:post, "https://www.amara.org/api2/partners/teams/").
55
+ with(:body => "{\"slug\":\"prx-test-1\",\"name\":\"prx test 1\"}",
56
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Host'=>'www.amara.org:443', 'User-Agent'=>'Amara Ruby Gem 0.1.0', 'X-Api-Username'=>'test_user', 'X-Apikey'=>'thisisakey'}).
57
+ to_return(:status => 200, :body => create_response, :headers => {})
58
+
59
+
60
+ teams = Amara::Teams.new(api_key: 'thisisakey', api_username: 'test_user')
61
+
62
+ response = teams.create(slug: 'prx-test-1', name: 'prx test 1')
63
+
53
64
  end
54
65
 
55
66
  end
@@ -0,0 +1,85 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
4
+
5
+ require 'amara/api'
6
+ require 'amara/videos'
7
+
8
+ require 'webmock/minitest'
9
+
10
+ describe Amara::Videos do
11
+
12
+ it "gets the base path for this subclass of API" do
13
+ videos = Amara::Videos.new
14
+ videos.base_path.must_equal 'videos'
15
+ end
16
+
17
+ it "returns a video" do
18
+ response = {
19
+ "all_urls" => ["https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg"],
20
+ "created" => "2013-08-29T15:35:25.518514",
21
+ "description" => "",
22
+ "duration" => nil,
23
+ "id" => "s7TbkyDizi6k",
24
+ "languages" => [],
25
+ "metadata" => {},
26
+ "original_language" => "en",
27
+ "primary_audio_language_code" => "en",
28
+ "project" => nil,
29
+ "resource_uri" => "/api2/partners/videos/s7TbkyDizi6k/",
30
+ "site_url" => "http://staging.amara.org/videos/s7TbkyDizi6k/info/",
31
+ "video" => "prx-test-1",
32
+ "thumbnail" => "",
33
+ "title" => "cmdline-test-1",
34
+ "video_url" => "https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg"
35
+ }.to_json
36
+ stub_request(:get, "https://www.amara.org/api2/partners/videos/s7TbkyDizi6k/").
37
+ to_return(body: response)
38
+
39
+ videos = Amara::Videos.new(api_key: 'thisisakey', api_username: 'test_user')
40
+
41
+ response = videos.get("s7TbkyDizi6k")
42
+ response.object.wont_be_nil
43
+ video = response.object
44
+ video.id.must_equal 's7TbkyDizi6k'
45
+ end
46
+
47
+ it "creates a new video" do
48
+ response = {
49
+ "all_urls" => ["https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg"],
50
+ "created" => "2013-08-29T15:35:25.518514",
51
+ "description" => "",
52
+ "duration" => nil,
53
+ "id" => "s7TbkyDizi6k",
54
+ "languages" => [],
55
+ "metadata" => {},
56
+ "original_language" => "en",
57
+ "primary_audio_language_code" => "en",
58
+ "project" => nil,
59
+ "resource_uri" => "/api2/partners/videos/s7TbkyDizi6k/",
60
+ "site_url" => "http://staging.amara.org/videos/s7TbkyDizi6k/info/",
61
+ "video" => "test-team",
62
+ "thumbnail" => "",
63
+ "title" => "title",
64
+ "video_url" => "https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg"
65
+ }.to_json
66
+
67
+ stub_request(:post, "https://www.amara.org/api2/partners/videos/").
68
+ with(:body => "{\"team\":\"test-team\",\"title\":\"title\",\"video_url\":\"https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg\",\"primary_audio_language_code\":\"en\"}",
69
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Host'=>'www.amara.org:443', 'User-Agent'=>'Amara Ruby Gem 0.1.0', 'X-Api-Username'=>'test_user', 'X-Apikey'=>'thisisakey'}).
70
+ to_return(:status => 200, :body => response, :headers => {})
71
+
72
+ videos = Amara::Videos.new(api_key: 'thisisakey', api_username: 'test_user')
73
+ response = videos.create({
74
+ team: 'test-team',
75
+ title: 'title',
76
+ video_url: 'https://archive.org/download/1-test-mp3.JRiaC2.popuparchive.org/test.ogg',
77
+ primary_audio_language_code: 'en'
78
+ })
79
+
80
+ response.object.wont_be_nil
81
+ video = response.object
82
+ video.id.must_equal 's7TbkyDizi6k'
83
+ end
84
+
85
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kuklewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-30 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -151,17 +151,22 @@ files:
151
151
  - amara.gemspec
152
152
  - lib/.DS_Store
153
153
  - lib/amara.rb
154
+ - lib/amara/activity.rb
154
155
  - lib/amara/api.rb
155
156
  - lib/amara/api_factory.rb
156
157
  - lib/amara/client.rb
157
158
  - lib/amara/configuration.rb
158
159
  - lib/amara/connection.rb
159
160
  - lib/amara/languages.rb
161
+ - lib/amara/message.rb
160
162
  - lib/amara/response.rb
161
163
  - lib/amara/teams.rb
164
+ - lib/amara/teams/applications.rb
162
165
  - lib/amara/teams/members.rb
163
166
  - lib/amara/teams/projects.rb
164
167
  - lib/amara/teams/safe_members.rb
168
+ - lib/amara/teams/tasks.rb
169
+ - lib/amara/users.rb
165
170
  - lib/amara/version.rb
166
171
  - lib/amara/videos.rb
167
172
  - lib/amara/videos/languages.rb
@@ -172,6 +177,7 @@ files:
172
177
  - test/teams/projects_test.rb
173
178
  - test/teams_test.rb
174
179
  - test/test_helper.rb
180
+ - test/videos_test.rb
175
181
  homepage: https://github.com/PRX/amara
176
182
  licenses: []
177
183
  metadata: {}
@@ -201,3 +207,4 @@ test_files:
201
207
  - test/teams/projects_test.rb
202
208
  - test/teams_test.rb
203
209
  - test/test_helper.rb
210
+ - test/videos_test.rb