media_monster_client 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/media_monster/job.rb +6 -0
- data/lib/media_monster_client/version.rb +1 -1
- data/lib/media_monster_client.rb +19 -1
- data/media_monster_client.gemspec +8 -5
- data/test/test_media_monster_client.rb +52 -30
- metadata +47 -5
data/.gitignore
CHANGED
data/lib/media_monster/job.rb
CHANGED
@@ -3,9 +3,11 @@ module MediaMonster
|
|
3
3
|
class Job < Model
|
4
4
|
|
5
5
|
attr_accessor :job_type # which type of job is this? audio to start, video, document, etc.
|
6
|
+
attr_accessor :priority # curently supports blank and 'high'
|
6
7
|
attr_accessor :original # file location
|
7
8
|
attr_accessor :call_back # url for webhook
|
8
9
|
attr_accessor :tasks # array of tasks
|
10
|
+
attr_accessor :id
|
9
11
|
|
10
12
|
def initialize(*args)
|
11
13
|
super
|
@@ -36,6 +38,10 @@ module MediaMonster
|
|
36
38
|
end
|
37
39
|
@tasks << new_task
|
38
40
|
end
|
41
|
+
|
42
|
+
def retry!
|
43
|
+
MediaMonsterClient.retry_job self
|
44
|
+
end
|
39
45
|
|
40
46
|
end
|
41
47
|
|
data/lib/media_monster_client.rb
CHANGED
@@ -25,19 +25,37 @@ module MediaMonsterClient
|
|
25
25
|
def create_job(job=nil)
|
26
26
|
job ||= MediaMonster::Job.new
|
27
27
|
yield job
|
28
|
-
|
28
|
+
job.tap do |j|
|
29
|
+
j_str = post(create_url('jobs'), j.to_json, {'Accept'=>'application/json','Content-Type'=>'application/json'}).body
|
30
|
+
json = JSON.parse(j_str)
|
31
|
+
j.id = json['job']['id']
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def update_task(task_id, task_status)
|
32
36
|
json = {'task'=>{'status'=>task_status}}.to_json
|
33
37
|
put(create_url("tasks/#{task_id.to_i}"), json, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
|
34
38
|
end
|
39
|
+
|
40
|
+
def retry_job(job)
|
41
|
+
case job
|
42
|
+
when MediaMonster::Job then job
|
43
|
+
when Fixnum then MediaMonster::Job.new(:id => job)
|
44
|
+
when String then MediaMonster::Job.new(:id => job.to_i)
|
45
|
+
end.tap do |j|
|
46
|
+
post(retry_url(j), {}, {'Accept'=>'application/json'})
|
47
|
+
end
|
48
|
+
end
|
35
49
|
|
36
50
|
protected
|
37
51
|
|
38
52
|
def create_url(path)
|
39
53
|
"/api/#{version}/#{path}"
|
40
54
|
end
|
55
|
+
|
56
|
+
def retry_url(model)
|
57
|
+
"/api/#{version}/#{model.class.to_s.downcase.pluralize}/#{model.id}/retry"
|
58
|
+
end
|
41
59
|
|
42
60
|
[:delete, :get, :head, :post, :put, :request].each do |method|
|
43
61
|
define_method method do |*args|
|
@@ -12,13 +12,16 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{client gem for media monster app}
|
13
13
|
s.description = %q{client gem for media monster app}
|
14
14
|
|
15
|
-
s.rubyforge_project = "media_monster_client"
|
16
|
-
|
17
|
-
s.add_dependency("activesupport")
|
18
|
-
s.add_dependency("oauth")
|
19
|
-
|
20
15
|
s.files = `git ls-files`.split("\n")
|
21
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
18
|
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency("activesupport")
|
21
|
+
s.add_runtime_dependency("oauth")
|
22
|
+
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "test-unit"
|
25
|
+
s.add_development_dependency 'fakeweb'
|
26
|
+
|
24
27
|
end
|
@@ -4,6 +4,7 @@
|
|
4
4
|
# gem 'activesupport', '=3.0.9'
|
5
5
|
|
6
6
|
require 'helper'
|
7
|
+
require 'fakeweb'
|
7
8
|
|
8
9
|
class TestMediaMonsterClient < Test::Unit::TestCase
|
9
10
|
|
@@ -13,49 +14,70 @@ class TestMediaMonsterClient < Test::Unit::TestCase
|
|
13
14
|
MediaMonsterClient.host = "development.prx.org"
|
14
15
|
MediaMonsterClient.port = 3000
|
15
16
|
MediaMonsterClient.version = 'v1'
|
17
|
+
|
18
|
+
# FakeWeb.register_uri(:post, "http://development.prx.org:3000/api/v1/jobs", :body => MediaMonster::Job.new(:id=>123).to_json)
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
21
|
+
def test_create_job_with_hash_original
|
19
22
|
response = MediaMonsterClient.create_job do |job|
|
20
23
|
job.job_type = 'audio'
|
21
|
-
job.
|
24
|
+
job.priority = 'high'
|
25
|
+
job.original = {:url=>'s3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2', :format=>'mp2'}
|
22
26
|
job.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
|
23
|
-
|
24
27
|
job.add_task( 'transcode',
|
25
28
|
{:format=>'mp3', :sample_rate=>'44100', :bit_rate=>'128'},
|
26
|
-
's3://development.tcf.prx.org/public/audio_files/21/
|
29
|
+
's3://development.tcf.prx.org/public/audio_files/21/test_AK.mp3',
|
27
30
|
nil,
|
28
31
|
'download')
|
29
32
|
|
30
33
|
end
|
31
|
-
|
32
34
|
puts response.inspect
|
33
|
-
|
35
|
+
|
36
|
+
assert !response.id.blank?
|
34
37
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
38
|
+
|
39
|
+
#
|
40
|
+
# def test_create_job
|
41
|
+
# response = MediaMonsterClient.create_job do |job|
|
42
|
+
# job.job_type = 'audio'
|
43
|
+
# job.original = 's3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2'
|
44
|
+
# job.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
|
45
|
+
#
|
46
|
+
# job.add_task( 'transcode',
|
47
|
+
# {:format=>'mp3', :sample_rate=>'44100', :bit_rate=>'128'},
|
48
|
+
# 's3://development.tcf.prx.org/public/audio_files/21/test.mp3',
|
49
|
+
# nil,
|
50
|
+
# 'download')
|
51
|
+
#
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# puts response.inspect
|
55
|
+
#
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# def test_create_job_with_sequence
|
59
|
+
# response = MediaMonsterClient.create_job do |job|
|
60
|
+
# job.job_type = 'audio'
|
61
|
+
# job.original = 's3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test.mp2'
|
62
|
+
# job.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
|
63
|
+
#
|
64
|
+
# job.add_sequence do |s|
|
65
|
+
# s.call_back = "http://development.prx.org:3001/audio_files/21/transcoded"
|
66
|
+
# s.label = 'preview'
|
67
|
+
#
|
68
|
+
# s.add_task( :task_type=>'cut',
|
69
|
+
# :options=>{:length=>4, :fade=>1},
|
70
|
+
# :label=>'cut it')
|
71
|
+
#
|
72
|
+
# s.add_task( :task_type=>'transcode',
|
73
|
+
# :options=>{:format=>'mp3', :sample_rate=>'44100', :bit_rate=>'64'},
|
74
|
+
# :label=>'mp3',
|
75
|
+
# :result=>'s3://development.tcf.prx.org/public/uploads/entry_audio_files/2/test_preview.mp3')
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# end
|
79
|
+
# puts response.inspect
|
80
|
+
# end
|
59
81
|
|
60
82
|
# MediaMonsterClient.create_job do |job|
|
61
83
|
# job.job_type = 'audio'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_monster_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Kuklewicz (kookster)
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-17 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,48 @@ dependencies:
|
|
46
46
|
version: "0"
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: test-unit
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: fakeweb
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
49
91
|
description: client gem for media monster app
|
50
92
|
email:
|
51
93
|
- andrew@prx.org
|
@@ -98,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
140
|
version: "0"
|
99
141
|
requirements: []
|
100
142
|
|
101
|
-
rubyforge_project:
|
143
|
+
rubyforge_project:
|
102
144
|
rubygems_version: 1.4.2
|
103
145
|
signing_key:
|
104
146
|
specification_version: 3
|