zencoder 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/lib/recipes.rb +6 -3
- data/lib/zencoder.rb +2 -2
- data/test/test_zencoder.rb +22 -8
- metadata +3 -3
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/recipes.rb
CHANGED
@@ -4,7 +4,7 @@ module ZencoderAPI #:nodoc:
|
|
4
4
|
|
5
5
|
# This class implements a couple of bogus recipes, mainly as an example of usage. Recipe isntances can be passed in to Zencoder#submit_job
|
6
6
|
class Recipe
|
7
|
-
@@keys = [:label, :base_url, :filename, :width, :height, :quality, :speed,
|
7
|
+
@@keys = [:label, :base_url, :filename, :width, :height, :size, :quality, :speed,
|
8
8
|
:upscale, :stretch, :frame_rate, :max_frame_rate, :keyframe_interval,
|
9
9
|
:video_bitrate, :bitrate_cap, :buffer_size, :h264_profile, :h264_level,
|
10
10
|
:skip_video, :audio_codec, :audio_bitrate, :audio_channels, :audio_sample_rate,
|
@@ -22,11 +22,14 @@ module ZencoderAPI #:nodoc:
|
|
22
22
|
raise RecipeError.new("no recipe parameters?") if params.empty?
|
23
23
|
raise RecipeError.new("unknown recipe parameter #{params.keys - @@keys}") unless (params.keys - @@keys).empty?
|
24
24
|
if params[:thumbnails]
|
25
|
-
raise RecipeError.new("unknown thumb keys #{params[:thumbnails].keys - @@thumb_keys}")
|
25
|
+
raise RecipeError.new("unknown thumb keys #{params[:thumbnails].keys - @@thumb_keys}") unless (params[:thumbnails].keys - @@thumb_keys).empty?
|
26
26
|
end
|
27
27
|
@o = params
|
28
28
|
end
|
29
29
|
|
30
|
+
def to_hash
|
31
|
+
@o
|
32
|
+
end
|
30
33
|
|
31
34
|
def to_json(*arg) #:nodoc:
|
32
35
|
@o.to_json(*arg)
|
@@ -43,7 +46,7 @@ module ZencoderAPI #:nodoc:
|
|
43
46
|
raise "Base_url unset." unless params['base_url']
|
44
47
|
defaults = {
|
45
48
|
"label"=> "iphone",
|
46
|
-
"
|
49
|
+
"size"=> "480x320",
|
47
50
|
"frame_rate"=> 24,
|
48
51
|
"max_frame_rate"=> 24,
|
49
52
|
"video_bitrate"=> 40,
|
data/lib/zencoder.rb
CHANGED
@@ -13,7 +13,7 @@ class Zencoder
|
|
13
13
|
# Currently https://app.zencoder.com/api This means you have to have ssl built into your ruby!
|
14
14
|
API_URL = 'https://app.zencoder.com/api'
|
15
15
|
|
16
|
-
VERSION = '1.0.
|
16
|
+
VERSION = '1.0.5' #:nodoc:
|
17
17
|
# Submits a job to zencoder.
|
18
18
|
# The recipe should be an instance or array of instances of ZencoderAPI::Recipe
|
19
19
|
# Exceptions are not handled, but rather propagated upwards.
|
@@ -21,7 +21,7 @@ class Zencoder
|
|
21
21
|
# If a block is provided, it is yielded the job configuration as a hash.
|
22
22
|
class <<self
|
23
23
|
def submit_job(apikey, src, *recipes)
|
24
|
-
jorb = {:api_key=>apikey, :input => src, :output=>[recipes].flatten}
|
24
|
+
jorb = {:api_key=>apikey, :input => src, :output=>[recipes].flatten.map(&:to_hash)}
|
25
25
|
yield jorb if block_given?
|
26
26
|
JSON.parse(RestClient.post(API_URL+'/jobs', jorb.to_json, {:content_type=>:json, :accept=>:json}))
|
27
27
|
end
|
data/test/test_zencoder.rb
CHANGED
@@ -14,16 +14,21 @@ class TestZencoder < Test::Unit::TestCase
|
|
14
14
|
@apikey = ENV['ZC_APIKEY']
|
15
15
|
@base_url = 's3://test_development/zencoder_asset'
|
16
16
|
@recipe = ZencoderAPI::Recipes.iphone('base_url' =>@base_url)
|
17
|
-
@recipe2 = ZencoderAPI::Recipes.web('base_url' =>@base_url
|
17
|
+
@recipe2 = ZencoderAPI::Recipes.web('base_url' =>@base_url,
|
18
|
+
:thumbnails => {
|
19
|
+
:number => 1,
|
20
|
+
:size => "75x75"})
|
18
21
|
assert_not_nil @apikey, "export ZC_APIKEY before you run the tests"
|
19
22
|
end
|
20
23
|
context "posting a new job" do
|
21
|
-
|
22
|
-
|
23
|
-
resp =<<-EOS
|
24
|
+
setup do
|
25
|
+
@resp =<<-EOS
|
24
26
|
{"id":36119,"outputs":[{"url":"s3://test_development/zencoder_asset/cf398a309f648f99c41a2c0573f40baf.mp4","label":"iphone","id":36174},{"url":"s3://test_development/zencoder_asset/253fae410b1262ef3a76296cbfdb8b44.mp4","label":"web","id":36175}]}
|
25
27
|
EOS
|
26
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
should "return jobid" do
|
31
|
+
RestClient.expects(:post).returns(@resp)
|
27
32
|
h = Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2])
|
28
33
|
assert_equal Hash, h.class
|
29
34
|
end
|
@@ -41,7 +46,7 @@ class TestZencoder < Test::Unit::TestCase
|
|
41
46
|
assert_equal z[:content_type], :json
|
42
47
|
assert_equal z[:accept], :json
|
43
48
|
true
|
44
|
-
}
|
49
|
+
}.returns(@resp)
|
45
50
|
Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2])
|
46
51
|
end
|
47
52
|
should "be able to muck the config " do
|
@@ -49,9 +54,10 @@ class TestZencoder < Test::Unit::TestCase
|
|
49
54
|
body = JSON.parse(y)
|
50
55
|
assert_equal body['foo'],'bar'
|
51
56
|
true
|
52
|
-
}
|
57
|
+
}.returns(@resp)
|
53
58
|
Zencoder.submit_job(@apikey, @src, @recipe) do |config|
|
54
59
|
config[:foo]='bar'
|
60
|
+
assert config[:output].first.is_a? Hash
|
55
61
|
end
|
56
62
|
end
|
57
63
|
should "be able to submit a job with 1 recipe" do
|
@@ -65,9 +71,17 @@ class TestZencoder < Test::Unit::TestCase
|
|
65
71
|
assert_equal z[:content_type], :json
|
66
72
|
assert_equal z[:accept], :json
|
67
73
|
true
|
68
|
-
}
|
74
|
+
}.returns(@resp)
|
69
75
|
Zencoder.submit_job(@apikey, @src, @recipe)
|
70
76
|
end
|
71
77
|
end
|
78
|
+
should "raise error when given bad data" do
|
79
|
+
assert_raise ZencoderAPI::RecipeError do
|
80
|
+
ZencoderAPI::Recipes.web('base_url' =>@base_url, :bad_key => 'wtf?')
|
81
|
+
end
|
82
|
+
assert_raise ZencoderAPI::RecipeError do
|
83
|
+
ZencoderAPI::Recipes.web('base_url' =>@base_url, :thumbnails => {:bad_key => 'wtf?'})
|
84
|
+
end
|
85
|
+
end
|
72
86
|
end
|
73
87
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 5
|
9
|
+
version: 1.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- McClain Looney
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-20 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|