active-encode 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +16 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE +202 -0
  7. data/README.md +106 -0
  8. data/Rakefile +34 -0
  9. data/active-encode.gemspec +29 -0
  10. data/lib/active-encode.rb +1 -0
  11. data/lib/active_encode.rb +2 -0
  12. data/lib/active_encode/base.rb +16 -0
  13. data/lib/active_encode/callbacks.rb +69 -0
  14. data/lib/active_encode/core.rb +81 -0
  15. data/lib/active_encode/engine_adapter.rb +52 -0
  16. data/lib/active_encode/engine_adapters.rb +26 -0
  17. data/lib/active_encode/engine_adapters/active_job_adapter.rb +23 -0
  18. data/lib/active_encode/engine_adapters/inline_adapter.rb +42 -0
  19. data/lib/active_encode/engine_adapters/matterhorn_adapter.rb +290 -0
  20. data/lib/active_encode/engine_adapters/test_adapter.rb +38 -0
  21. data/lib/active_encode/engine_adapters/zencoder_adapter.rb +147 -0
  22. data/lib/active_encode/status.rb +38 -0
  23. data/lib/active_encode/technical_metadata.rb +11 -0
  24. data/lib/active_encode/version.rb +3 -0
  25. data/spec/fixtures/Bars_512kb.mp4 +0 -0
  26. data/spec/fixtures/matterhorn/cancelled_response.xml +323 -0
  27. data/spec/fixtures/matterhorn/completed_response.xml +4 -0
  28. data/spec/fixtures/matterhorn/create_response.xml +300 -0
  29. data/spec/fixtures/matterhorn/delete_track_response.xml +2 -0
  30. data/spec/fixtures/matterhorn/failed_response.xml +4 -0
  31. data/spec/fixtures/matterhorn/purged_response.xml +342 -0
  32. data/spec/fixtures/matterhorn/running_response.xml +1 -0
  33. data/spec/fixtures/matterhorn/stop_completed_response.xml +228 -0
  34. data/spec/fixtures/matterhorn/stop_running_response.xml +339 -0
  35. data/spec/fixtures/zencoder/job_create.json +1 -0
  36. data/spec/fixtures/zencoder/job_details_cancelled.json +1 -0
  37. data/spec/fixtures/zencoder/job_details_completed.json +1 -0
  38. data/spec/fixtures/zencoder/job_details_create.json +1 -0
  39. data/spec/fixtures/zencoder/job_details_failed.json +73 -0
  40. data/spec/fixtures/zencoder/job_details_running.json +1 -0
  41. data/spec/fixtures/zencoder/job_progress_cancelled.json +13 -0
  42. data/spec/fixtures/zencoder/job_progress_completed.json +13 -0
  43. data/spec/fixtures/zencoder/job_progress_create.json +1 -0
  44. data/spec/fixtures/zencoder/job_progress_failed.json +13 -0
  45. data/spec/fixtures/zencoder/job_progress_running.json +1 -0
  46. data/spec/integration/matterhorn_adapter_spec.rb +186 -0
  47. data/spec/integration/zencoder_adapter_spec.rb +153 -0
  48. data/spec/spec_helper.rb +12 -0
  49. data/spec/units/callbacks_spec.rb +67 -0
  50. data/spec/units/engine_adapter_spec.rb +68 -0
  51. data/spec/units/status_spec.rb +64 -0
  52. metadata +221 -0
@@ -0,0 +1,12 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bundler/setup'
5
+ Bundler.setup
6
+
7
+ require 'rspec/its'
8
+ require 'active-encode'
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ActiveEncode::Callbacks" do
4
+
5
+ before do
6
+ class CallbackEncode < ActiveEncode::Base
7
+ before_create ->(encode) { encode.history << "CallbackEncode ran before_create" }
8
+ after_create ->(encode) { encode.history << "CallbackEncode ran after_create" }
9
+
10
+ before_cancel ->(encode) { encode.history << "CallbackEncode ran before_cancel" }
11
+ after_cancel ->(encode) { encode.history << "CallbackEncode ran after_cancel" }
12
+
13
+ before_purge ->(encode) { encode.history << "CallbackEncode ran before_purge" }
14
+ after_purge ->(encode) { encode.history << "CallbackEncode ran after_purge" }
15
+
16
+ around_create do |encode, block|
17
+ encode.history << "CallbackEncode ran around_create_start"
18
+ block.call
19
+ encode.history << "CallbackEncode ran around_create_stop"
20
+ end
21
+
22
+ around_cancel do |encode, block|
23
+ encode.history << "CallbackEncode ran around_cancel_start"
24
+ block.call
25
+ encode.history << "CallbackEncode ran around_cancel_stop"
26
+ end
27
+
28
+ around_purge do |encode, block|
29
+ encode.history << "CallbackEncode ran around_purge_start"
30
+ block.call
31
+ encode.history << "CallbackEncode ran around_purge_stop"
32
+ end
33
+
34
+ def history
35
+ @history ||= []
36
+ end
37
+ end
38
+ end
39
+
40
+ after do
41
+ Object.send(:remove_const, :CallbackEncode)
42
+ end
43
+
44
+ describe 'create callbacks' do
45
+ subject { CallbackEncode.create("sample.mp4").history }
46
+ it { is_expected.to include("CallbackEncode ran before_create") }
47
+ it { is_expected.to include("CallbackEncode ran after_create") }
48
+ it { is_expected.to include("CallbackEncode ran around_create_start") }
49
+ it { is_expected.to include("CallbackEncode ran around_create_stop") }
50
+ end
51
+
52
+ describe 'cancel callbacks' do
53
+ subject { CallbackEncode.create("sample.mp4").cancel!.history }
54
+ it { is_expected.to include("CallbackEncode ran before_cancel") }
55
+ it { is_expected.to include("CallbackEncode ran after_cancel") }
56
+ it { is_expected.to include("CallbackEncode ran around_cancel_start") }
57
+ it { is_expected.to include("CallbackEncode ran around_cancel_stop") }
58
+ end
59
+
60
+ describe 'purge callbacks' do
61
+ subject { CallbackEncode.create("sample.mp4").purge!.history }
62
+ it { is_expected.to include("CallbackEncode ran before_purge") }
63
+ it { is_expected.to include("CallbackEncode ran after_purge") }
64
+ it { is_expected.to include("CallbackEncode ran around_purge_start") }
65
+ it { is_expected.to include("CallbackEncode ran around_purge_stop") }
66
+ end
67
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ActiveEncode::EngineAdapter" do
4
+ before do
5
+ module ActiveEncode
6
+ module EngineAdapters
7
+ class StubOneAdapter
8
+ def create(encode); end
9
+ def find(id, opts = {}); end
10
+ def list(*filters); end
11
+ def cancel(encode); end
12
+ def purge(encode); end
13
+ def remove_output(encode, output_id); end
14
+ end
15
+
16
+ class StubTwoAdapter
17
+ def create(encode); end
18
+ def find(id, opts = {}); end
19
+ def list(*filters); end
20
+ def cancel(encode); end
21
+ def purge(encode); end
22
+ def remove_output(encode, output_id); end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ after do
29
+ ActiveEncode::EngineAdapters.send(:remove_const, :StubOneAdapter)
30
+ ActiveEncode::EngineAdapters.send(:remove_const, :StubTwoAdapter)
31
+ end
32
+
33
+ it 'should not allow classes as arguments' do
34
+ expect { ActiveEncode::Base.engine_adapter = ActiveEncode::EngineAdapters::StubOneAdapter }.to raise_error(ArgumentError)
35
+ end
36
+
37
+ it 'should not allow arguments that are not engine adapters' do
38
+ expect { ActiveEncode::Base.engine_adapter = Mutex.new }.to raise_error(ArgumentError)
39
+ end
40
+
41
+ context 'overriding' do
42
+ let(:base_engine_adapter) { ActiveEncode::Base.engine_adapter }
43
+
44
+ it 'should not affect the parent' do
45
+ child_encode_one = Class.new(ActiveEncode::Base)
46
+ child_encode_one.engine_adapter = :stub_one
47
+
48
+ expect(child_encode_one.engine_adapter).not_to eq base_engine_adapter
49
+ expect(child_encode_one.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubOneAdapter
50
+ expect(ActiveEncode::Base.engine_adapter).to eq base_engine_adapter
51
+ end
52
+
53
+ it 'should not affect its sibling' do
54
+ child_encode_one = Class.new(ActiveEncode::Base)
55
+ child_encode_one.engine_adapter = :stub_one
56
+ child_encode_two = Class.new(ActiveEncode::Base)
57
+ child_encode_two.engine_adapter = :stub_two
58
+
59
+ expect(child_encode_two.engine_adapter).not_to eq base_engine_adapter
60
+ expect(child_encode_two.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubTwoAdapter
61
+ #child_encode_one's engine adapter should remain unchanged
62
+ expect(child_encode_one.engine_adapter).to be_kind_of ActiveEncode::EngineAdapters::StubOneAdapter
63
+ expect(ActiveEncode::Base.engine_adapter).to eq base_engine_adapter
64
+ #new encodes should not be affected
65
+ expect(Class.new(ActiveEncode::Base).engine_adapter).to eq base_engine_adapter
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ActiveEncode::Status' do
4
+
5
+ subject { ActiveEncode::Base.new(nil) }
6
+
7
+ context 'new object' do
8
+ subject {ActiveEncode::Base.new(nil)}
9
+ it { is_expected.not_to be_created }
10
+ it { is_expected.not_to be_running }
11
+ it { is_expected.not_to be_cancelled }
12
+ it { is_expected.not_to be_completed }
13
+ it { is_expected.not_to be_failed }
14
+ end
15
+
16
+ context 'running job' do
17
+ before do
18
+ subject.id = 1
19
+ subject.state = :running
20
+ end
21
+ it { is_expected.to be_created }
22
+ it { is_expected.to be_running }
23
+ it { is_expected.not_to be_cancelled }
24
+ it { is_expected.not_to be_completed }
25
+ it { is_expected.not_to be_failed }
26
+ end
27
+
28
+ context 'cancelled job' do
29
+ before do
30
+ subject.id = 1
31
+ subject.state = :cancelled
32
+ end
33
+ it { is_expected.to be_created }
34
+ it { is_expected.not_to be_running }
35
+ it { is_expected.to be_cancelled }
36
+ it { is_expected.not_to be_completed }
37
+ it { is_expected.not_to be_failed }
38
+ end
39
+
40
+ context 'completed job' do
41
+ before do
42
+ subject.id = 1
43
+ subject.state = :completed
44
+ end
45
+ it { is_expected.to be_created }
46
+ it { is_expected.not_to be_running }
47
+ it { is_expected.not_to be_cancelled }
48
+ it { is_expected.to be_completed }
49
+ it { is_expected.not_to be_failed }
50
+ end
51
+
52
+ context 'failed job' do
53
+ before do
54
+ subject.id = 1
55
+ subject.state = :failed
56
+ end
57
+ it { is_expected.to be_created }
58
+ it { is_expected.not_to be_running }
59
+ it { is_expected.not_to be_cancelled }
60
+ it { is_expected.not_to be_completed }
61
+ it { is_expected.to be_failed }
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-encode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Klein, Chris Colvard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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: activemodel
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.2'
111
+ description: This gem serves as the basis for the interface between a Ruby (Rails)
112
+ application and a provider of transcoding services such as Opencast Matterhorn,
113
+ Zencoder, and Amazon Elastic Transcoder.
114
+ email:
115
+ - mbklein@gmail.com, chris.colvard@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".coveralls.yml"
121
+ - ".gitignore"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - active-encode.gemspec
128
+ - lib/active-encode.rb
129
+ - lib/active_encode.rb
130
+ - lib/active_encode/base.rb
131
+ - lib/active_encode/callbacks.rb
132
+ - lib/active_encode/core.rb
133
+ - lib/active_encode/engine_adapter.rb
134
+ - lib/active_encode/engine_adapters.rb
135
+ - lib/active_encode/engine_adapters/active_job_adapter.rb
136
+ - lib/active_encode/engine_adapters/inline_adapter.rb
137
+ - lib/active_encode/engine_adapters/matterhorn_adapter.rb
138
+ - lib/active_encode/engine_adapters/test_adapter.rb
139
+ - lib/active_encode/engine_adapters/zencoder_adapter.rb
140
+ - lib/active_encode/status.rb
141
+ - lib/active_encode/technical_metadata.rb
142
+ - lib/active_encode/version.rb
143
+ - spec/fixtures/Bars_512kb.mp4
144
+ - spec/fixtures/matterhorn/cancelled_response.xml
145
+ - spec/fixtures/matterhorn/completed_response.xml
146
+ - spec/fixtures/matterhorn/create_response.xml
147
+ - spec/fixtures/matterhorn/delete_track_response.xml
148
+ - spec/fixtures/matterhorn/failed_response.xml
149
+ - spec/fixtures/matterhorn/purged_response.xml
150
+ - spec/fixtures/matterhorn/running_response.xml
151
+ - spec/fixtures/matterhorn/stop_completed_response.xml
152
+ - spec/fixtures/matterhorn/stop_running_response.xml
153
+ - spec/fixtures/zencoder/job_create.json
154
+ - spec/fixtures/zencoder/job_details_cancelled.json
155
+ - spec/fixtures/zencoder/job_details_completed.json
156
+ - spec/fixtures/zencoder/job_details_create.json
157
+ - spec/fixtures/zencoder/job_details_failed.json
158
+ - spec/fixtures/zencoder/job_details_running.json
159
+ - spec/fixtures/zencoder/job_progress_cancelled.json
160
+ - spec/fixtures/zencoder/job_progress_completed.json
161
+ - spec/fixtures/zencoder/job_progress_create.json
162
+ - spec/fixtures/zencoder/job_progress_failed.json
163
+ - spec/fixtures/zencoder/job_progress_running.json
164
+ - spec/integration/matterhorn_adapter_spec.rb
165
+ - spec/integration/zencoder_adapter_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/units/callbacks_spec.rb
168
+ - spec/units/engine_adapter_spec.rb
169
+ - spec/units/status_spec.rb
170
+ homepage: ''
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.4.7
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Declare encode job classes that can be run by a variety of encoding services
194
+ test_files:
195
+ - spec/fixtures/Bars_512kb.mp4
196
+ - spec/fixtures/matterhorn/cancelled_response.xml
197
+ - spec/fixtures/matterhorn/completed_response.xml
198
+ - spec/fixtures/matterhorn/create_response.xml
199
+ - spec/fixtures/matterhorn/delete_track_response.xml
200
+ - spec/fixtures/matterhorn/failed_response.xml
201
+ - spec/fixtures/matterhorn/purged_response.xml
202
+ - spec/fixtures/matterhorn/running_response.xml
203
+ - spec/fixtures/matterhorn/stop_completed_response.xml
204
+ - spec/fixtures/matterhorn/stop_running_response.xml
205
+ - spec/fixtures/zencoder/job_create.json
206
+ - spec/fixtures/zencoder/job_details_cancelled.json
207
+ - spec/fixtures/zencoder/job_details_completed.json
208
+ - spec/fixtures/zencoder/job_details_create.json
209
+ - spec/fixtures/zencoder/job_details_failed.json
210
+ - spec/fixtures/zencoder/job_details_running.json
211
+ - spec/fixtures/zencoder/job_progress_cancelled.json
212
+ - spec/fixtures/zencoder/job_progress_completed.json
213
+ - spec/fixtures/zencoder/job_progress_create.json
214
+ - spec/fixtures/zencoder/job_progress_failed.json
215
+ - spec/fixtures/zencoder/job_progress_running.json
216
+ - spec/integration/matterhorn_adapter_spec.rb
217
+ - spec/integration/zencoder_adapter_spec.rb
218
+ - spec/spec_helper.rb
219
+ - spec/units/callbacks_spec.rb
220
+ - spec/units/engine_adapter_spec.rb
221
+ - spec/units/status_spec.rb