zencoder 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Zencoder
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,184 @@
1
+ # Zencoder
2
+
3
+ The gem for interacting with the API on [Zencoder](http://zencoder.com).
4
+
5
+ See [http://zencoder.com/docs/api](http://zencoder.com/docs/api) for more details on the API.
6
+
7
+ Tested on the following versions of Ruby:
8
+
9
+ * Ruby 1.8.6-p399
10
+ * Ruby 1.8.7-p174
11
+ * Ruby 1.9.1-p378
12
+ * Ruby 1.9.2-preview3
13
+ * Ruby Enterprise Edition 1.8.7-2010.02
14
+ * Rubinius 1.0.1-20100603
15
+ * jRuby 1.5.1
16
+
17
+ ## Getting Started
18
+
19
+ The first thing you'll need to interact with the Zencoder API is your API key. You can use your API key in one of two ways. The first, and in our opinion the best, is to set it and forget it on the Zencoder module like so:
20
+
21
+ Zencoder.api_key = 'abcd1234'
22
+
23
+ Alternatively you can pass your API key in every request, but who wants to do that?
24
+
25
+ We'll include examples of both ways throughout this document.
26
+
27
+ ## Responses
28
+
29
+ All calls in the Zencoder library either raise Zencoder::HTTPError or return a Zencoder::Response.
30
+
31
+ A Zencoder::Response can be used as follows:
32
+
33
+ response = Zencoder::Job.list
34
+ response.success? # => true if the response code was 200 through 299
35
+ response.code # => 200
36
+ response.body # => the JSON-parsed body or raw body if unparseable
37
+ response.raw_body # => the body pre-JSON-parsing
38
+ response.raw_response # => the raw Net::HTTP or Typhoeus response (see below for how to use Typhoeus)
39
+
40
+ ## Jobs
41
+
42
+ There's more you can do on jobs than anything else in the API. The following methods are available: `list`, `create`, `details`, `progress`, `resubmit`, `cancel`, `delete`.
43
+
44
+ ### list
45
+
46
+ By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass two parameters to control the paging: `page` and `per_page`.
47
+
48
+ Zencoder::Job.list
49
+ Zencoder::Job.list(:per_page => 10)
50
+ Zencoder::Job.list(:per_page => 10, :page => 2)
51
+ Zencoder::Job.list(:per_page => 10, :page => 2, :api_key => 'abcd1234')
52
+
53
+ ### create
54
+
55
+ The hash you pass to the `create` method should be encodable to the [JSON you would pass to the Job creation API call on Zencoder](http://zencoder.com/docs/api/#encoding-job).
56
+
57
+ Zencoder::Job.create({:input => 's3://bucket/key.mp4'})
58
+ Zencoder::Job.create({:input => 's3://bucket/key.mp4',
59
+ :outputs => [{:label => 'vp8 for the web',
60
+ :url => 's3://bucket/key_output.webm'}]})
61
+ Zencoder::Job.create({:input => 's3://bucket/key.mp4', :api_key => 'abcd1234'})
62
+
63
+ ### details
64
+
65
+ The number passed to `details` is the ID of a Zencoder job.
66
+
67
+ Zencoder::Job.details(1)
68
+ Zencoder::Job.details(1, :api_key => 'abcd1234')
69
+
70
+ ### resubmit
71
+
72
+ The number passed to `resubmit` is the ID of a Zencoder job.
73
+
74
+ Zencoder::Job.resubmit(1)
75
+ Zencoder::Job.resubmit(1, :api_key => 'abcd1234')
76
+
77
+ ### cancel
78
+
79
+ The number passed to `cancel` is the ID of a Zencoder job.
80
+
81
+ Zencoder::Job.cancel(1)
82
+ Zencoder::Job.cancel(1, :api_key => 'abcd1234')
83
+
84
+ ### delete
85
+
86
+ The number passed to `delete` is the ID of a Zencoder job.
87
+
88
+ Zencoder::Job.delete(1)
89
+ Zencoder::Job.delete(1, :api_key => 'abcd1234')
90
+
91
+ ## Outputs
92
+
93
+ ### progress
94
+
95
+ Please note that the number passed to `progress` is the output file ID.
96
+
97
+ Zencoder::Output.progress(1)
98
+ Zencoder::Output.progress(1, :api_key => 'abcd1234')
99
+
100
+ ## Notifications
101
+
102
+ ### list
103
+
104
+ By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass three parameters to control the paging: `page`, `per_page`, and `since_id`. Passing `since_id` will return notifications for jobs created after the job with the given ID.
105
+
106
+ Zencoder::Notification.list
107
+ Zencoder::Notification.list(:per_page => 10)
108
+ Zencoder::Notification.list(:per_page => 10, :page => 2)
109
+ Zencoder::Notification.list(:per_page => 10, :page => 2, :since_id => 20)
110
+ Zencoder::Notification.list(:api_key => 'abcd1234')
111
+
112
+ ## Accounts
113
+
114
+ ### create
115
+
116
+ The hash you pass to the `create` method should be encodable to the [JSON you would pass to the Account creation API call on Zencoder](http://zencoder.com/docs/api/#accounts). No API key is required for this call, of course.
117
+
118
+ Zencoder::Account.create({:terms_of_service => 1,
119
+ :email => 'bob@example.com'})
120
+ Zencoder::Account.create({:terms_of_service => 1,
121
+ :email => 'bob@example.com',
122
+ :password => 'abcd1234',
123
+ :affiliate_code => 'abcd1234'})
124
+
125
+ ### details
126
+
127
+ Zencoder::Account.details
128
+ Zencoder::Account.details(:api_key => 'abcd1234')
129
+
130
+ ### integration
131
+
132
+ This will put your account into integration mode (site-wide).
133
+
134
+ Zencoder::Account.integration
135
+ Zencoder::Account.integration(:api_key => 'abcd1234')
136
+
137
+ ### live
138
+
139
+ This will put your account into live mode (site-wide).
140
+
141
+ Zencoder::Account.live
142
+ Zencoder::Account.live(:api_key => 'abcd1234')
143
+
144
+ ## Advanced HTTP
145
+
146
+ ### Alternate HTTP Libraries
147
+
148
+ By default this library will use Net::HTTP to make all API calls. You can change the backend or add your own:
149
+
150
+ require 'typhoeus'
151
+ Zencoder::HTTP.http_backend = Zencoder::HTTP::Typhoeus
152
+
153
+ require 'my_favorite_http_library'
154
+ Zencoder::HTTP.http_backend = MyFavoriteHTTPBackend
155
+
156
+ See the HTTP backends in this library to get started on your own.
157
+
158
+ ### Advanced Options
159
+
160
+ A secondary options hash can be passed to any method call which will then be passed on to the HTTP backend. You can pass `timeout` (in milliseconds), `headers`, and `params` (will be added to the query string) to any of the backends. If you are using Typhoeus, see their documentation for further options.
161
+
162
+ Zencoder::Job.list(:timeout => 1000) # Timeout is 1 second.
163
+
164
+ ### Default Options
165
+
166
+ Default options are passed to the HTTP backend. These can be retrieved and modified.
167
+
168
+ Zencoder::HTTP.default_options = {:timeout => 3000,
169
+ :headers => {'Accept' => 'application/json',
170
+ 'Content-Type' => 'application/json'}}
171
+
172
+ ### SSL
173
+
174
+ The Net::HTTP backend will do its best to locate your local SSL certs to allow SSL verification. For a list of paths that are checked, see `Zencoder::HTTP::NetHTTP.root_cert_paths`. Feel free to add your own at runtime.
175
+
176
+ Zencoder::HTTP::NetHTTP.root_cert_paths << '/my/custom/cert/path'
177
+
178
+ ## Advanced JSON
179
+
180
+ ### Alternate JSON Libraries
181
+
182
+ This library uses the `multi_json` gem to encode and decode JSON. It uses the `json_pure` gem by default for compatibility with different ruby implementations. You can change the JSON engine for MultiJson:
183
+
184
+ MultiJson.engine = :yajl
data/Rakefile CHANGED
@@ -1,24 +1,36 @@
1
- # -*- ruby -*-
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
2
4
 
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
3
10
 
4
- require 'rake/clean'
5
- require 'rubygems'
6
- require 'hoe'
7
- CLEAN.include %w(**/*.orig)
8
- Hoe.plugins.delete :rubyforge
9
- Hoe.plugin :hg
11
+ task :default => :test
12
+
13
+ require 'rake/rdoctask'
14
+
15
+ Rake::RDocTask.new do |rdoc|
16
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
10
17
 
11
- Hoe.spec 'zencoder' do
12
- developer('McClain Looney', 'm@loonsoft.com')
13
- extra_deps << %w(rest-client >=1.5.1)
14
- extra_deps << %w(json >=1.4.3)
15
- extra_dev_deps << %w(shoulda >=2.10.0)
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = "zencoder-rb #{version}"
20
+ rdoc.rdoc_files.include('README*')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
22
  end
17
23
 
18
- task :install =>:package do
19
- $:<< 'lib'
20
- require 'zencoder'
21
- puts `GEM_HOME=~/.gem/ruby/1.8 gem install pkg/zencoder-#{Zencoder::VERSION}.gem`
24
+ begin
25
+ require 'rcov/rcovtask'
26
+ Rcov::RcovTask.new do |test|
27
+ test.libs << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ test.rcov_opts << '--exclude "gems/*"'
31
+ end
32
+ rescue LoadError
33
+ task :rcov do
34
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
35
+ end
22
36
  end
23
- # vim: syntax=ruby
24
- #
@@ -1,32 +1,26 @@
1
- require 'rubygems'
2
- require 'json'
3
- require 'rest_client'
4
- require 'recipes'
5
- # A simple interface for dealing with the zencoder api. Currently just submits jobs. More features to come some day.
6
- #
7
- # Example:
8
- #
9
- # Zencoder.submit_job('somebigapikeynumberthing','s3://bucket/path/to/file.mov', ZencoderAPI::Recipes.iphone({:override=>value}))
10
- class Zencoder
11
- include ZencoderAPI
12
-
13
- # Currently https://app.zencoder.com/api This means you have to have ssl built into your ruby!
14
- API_URL = 'https://app.zencoder.com/api'
15
-
16
- VERSION = '1.0.7' #:nodoc:
17
- # Submits a job to zencoder.
18
- # The recipe should be an instance or array of instances of ZencoderAPI::Recipe
19
- # Exceptions are not handled, but rather propagated upwards.
20
- #
21
- # If a block is provided, it is yielded the job configuration as a hash.
22
- # Recipes is an array of Recipe objects.
23
- # opts can be used to override toplevel Zencoder api options
24
- class <<self
25
- def submit_job(apikey, src, recipes, opts={})
26
- jorb = {:api_key=>apikey, :input => src, :output=>[recipes].flatten.map(&:to_hash)}
27
- jorb.merge!(opts)
28
- yield jorb if block_given?
29
- JSON.parse(RestClient.post(API_URL+'/jobs', jorb.to_json, {:content_type=>:json, :accept=>:json}))
30
- end
31
- end
1
+ # Standard Library
2
+ require 'cgi'
3
+ require 'net/https'
4
+ require 'timeout'
5
+
6
+ # Gems
7
+ require 'multi_json'
8
+
9
+ begin
10
+ MultiJson.engine
11
+ rescue LoadError
12
+ require 'json'
32
13
  end
14
+
15
+ # Zencoder
16
+ require 'zencoder/zencoder'
17
+ require 'zencoder/http'
18
+ require 'zencoder/http/net_http'
19
+ require 'zencoder/http/typhoeus'
20
+ require 'zencoder/errors'
21
+ require 'zencoder/job'
22
+ require 'zencoder/output'
23
+ require 'zencoder/account'
24
+ require 'zencoder/notification'
25
+ require 'zencoder/response'
26
+ require 'zencoder/version'
@@ -0,0 +1,24 @@
1
+ module Zencoder::Account
2
+
3
+ extend Zencoder
4
+
5
+ def self.create(params={}, options={})
6
+ Zencoder::HTTP.post("#{Zencoder.base_url}/account", MultiJson.encode(params), options)
7
+ end
8
+
9
+ def self.details(options={})
10
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
11
+ Zencoder::HTTP.get("#{Zencoder.base_url}/account", merge_params(options, params))
12
+ end
13
+
14
+ def self.integration(options={})
15
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
16
+ Zencoder::HTTP.get("#{Zencoder.base_url}/account/integration", merge_params(options, params))
17
+ end
18
+
19
+ def self.live(options={})
20
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
21
+ Zencoder::HTTP.get("#{Zencoder.base_url}/account/live", merge_params(options, params))
22
+ end
23
+
24
+ end
@@ -0,0 +1,5 @@
1
+ class Zencoder::Error < StandardError
2
+ end
3
+
4
+ class Zencoder::HTTPError < Zencoder::Error
5
+ end
@@ -0,0 +1,56 @@
1
+ module Zencoder::HTTP
2
+
3
+ class << self
4
+ attr_accessor :default_options
5
+ attr_writer :http_backend
6
+ end
7
+
8
+ self.default_options = {:timeout => 10000,
9
+ :headers => {'Accept' => 'application/json',
10
+ 'Content-Type' => 'application/json'}}
11
+
12
+ def self.http_backend
13
+ @http_backend ||= Zencoder::HTTP::NetHTTP
14
+ end
15
+
16
+ def self.post(url, body, options={})
17
+ perform_method(:post, url, options.merge(:body => body))
18
+ end
19
+
20
+ def self.put(url, body, options={})
21
+ perform_method(:put, url, options.merge(:body => body))
22
+ end
23
+
24
+ def self.get(url, options={})
25
+ perform_method(:get, url, options)
26
+ end
27
+
28
+ def self.delete(url, options={})
29
+ perform_method(:delete, url, options)
30
+ end
31
+
32
+
33
+ protected
34
+
35
+ def self.perform_method(method, url, options)
36
+ process_response http_backend.send(method, url, self.default_options.merge(options))
37
+ rescue StandardError => e
38
+ raise Zencoder::HTTPError, "#{e.class} - #{e.message}"
39
+ end
40
+
41
+ def self.process_response(http_backend_response)
42
+ response = Zencoder::Response.new
43
+ response.code = http_backend_response.code
44
+
45
+ begin
46
+ response.body = MultiJson.decode(http_backend_response.body.to_s)
47
+ rescue StandardError # Hack! Returns different exceptions depending on the JSON engine
48
+ response.body = http_backend_response.body
49
+ end
50
+
51
+ response.raw_body = http_backend_response.body
52
+ response.raw_response = http_backend_response
53
+ response
54
+ end
55
+
56
+ end
@@ -0,0 +1,142 @@
1
+ # Ruby's Net/HTTP Sucks
2
+ # Borrowed root cert checking from http://redcorundum.blogspot.com/2008/03/ssl-certificates-and-nethttps.html
3
+
4
+ module Zencoder::HTTP::NetHTTP
5
+
6
+ class << self
7
+ attr_accessor :root_cert_paths
8
+ end
9
+
10
+ self.root_cert_paths = ['/etc/ssl/certs',
11
+ '/var/ssl',
12
+ '/usr/share/ssl',
13
+ '/usr/ssl',
14
+ '/etc/ssl',
15
+ '/usr/local/openssl',
16
+ '/usr/lib/ssl',
17
+ '/System/Library/OpenSSL',
18
+ '/etc/openssl',
19
+ '/usr/local/ssl',
20
+ '/etc/pki/tls']
21
+
22
+ def self.post(url, options={})
23
+ uri = URI.parse(url)
24
+ add_params_to_query_string(uri, options[:params])
25
+
26
+ request = Net::HTTP::Post.new(path_with_query_string(uri))
27
+
28
+ add_headers(request, options[:headers])
29
+ add_body(request, options[:body])
30
+
31
+ request_with_timeout(http_with_ssl(uri), request, options[:timeout])
32
+ end
33
+
34
+ def self.put(url, options={})
35
+ uri = URI.parse(url)
36
+ add_params_to_query_string(uri, options[:params])
37
+
38
+ request = Net::HTTP::Put.new(path_with_query_string(uri))
39
+
40
+ add_headers(request, options[:headers])
41
+ add_body(request, options[:body])
42
+
43
+ request_with_timeout(http_with_ssl(uri), request, options[:timeout])
44
+ end
45
+
46
+ def self.get(url, options={})
47
+ uri = URI.parse(url)
48
+ add_params_to_query_string(uri, options[:params])
49
+
50
+ request = Net::HTTP::Get.new(path_with_query_string(uri))
51
+
52
+ add_headers(request, options[:headers])
53
+
54
+ request_with_timeout(http_with_ssl(uri), request, options[:timeout])
55
+ end
56
+
57
+ def self.delete(url, options={})
58
+ uri = URI.parse(url)
59
+ add_params_to_query_string(uri, options[:params])
60
+
61
+ request = Net::HTTP::Delete.new(path_with_query_string(uri))
62
+
63
+ add_headers(request, options[:headers])
64
+
65
+ request_with_timeout(http_with_ssl(uri), request, options[:timeout])
66
+ end
67
+
68
+
69
+ protected
70
+
71
+ def self.http_with_ssl(uri)
72
+ http = Net::HTTP.new(uri.host, uri.port)
73
+
74
+ if uri.scheme == 'https'
75
+ http.use_ssl = true
76
+
77
+ if root_cert_path = locate_root_cert_path
78
+ http.ca_path = root_cert_path
79
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
80
+ http.verify_depth = 5
81
+ else
82
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
83
+ end
84
+ end
85
+
86
+ http
87
+ end
88
+
89
+ def self.path_with_query_string(uri)
90
+ if uri.path.empty?
91
+ uri.path = '/'
92
+ end
93
+
94
+ if uri.query.to_s.empty?
95
+ uri.path
96
+ else
97
+ uri.path + '?' + uri.query.to_s
98
+ end
99
+ end
100
+
101
+ def self.locate_root_cert_path
102
+ root_cert_paths.detect do |root_cert_path|
103
+ File.directory?(root_cert_path)
104
+ end
105
+ end
106
+
107
+ def self.add_headers(request, headers)
108
+ if headers
109
+ headers.each do |header, value|
110
+ request.add_field(header.to_s, value.to_s)
111
+ end
112
+ end
113
+ end
114
+
115
+ def self.add_body(request, body)
116
+ if body
117
+ request.body = body
118
+ end
119
+ end
120
+
121
+ def self.add_params_to_query_string(uri, params)
122
+ if params
123
+ params_as_query = params.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
124
+ if uri.query.to_s.empty?
125
+ uri.query = params_as_query
126
+ else
127
+ uri.query = [uri.query.to_s, params_as_query].join('&')
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.request_with_timeout(http, request, timeout)
133
+ if timeout
134
+ Timeout.timeout(timeout / 1000.0) do
135
+ http.request(request)
136
+ end
137
+ else
138
+ http.request(request)
139
+ end
140
+ end
141
+
142
+ end
@@ -0,0 +1,19 @@
1
+ module Zencoder::HTTP::Typhoeus
2
+
3
+ def self.post(url, options={})
4
+ Typhoeus::Request.post(url, options)
5
+ end
6
+
7
+ def self.put(url, options={})
8
+ Typhoeus::Request.put(url, options)
9
+ end
10
+
11
+ def self.get(url, options={})
12
+ Typhoeus::Request.get(url, options)
13
+ end
14
+
15
+ def self.delete(url, options={})
16
+ Typhoeus::Request.delete(url, options)
17
+ end
18
+
19
+ end
@@ -0,0 +1,40 @@
1
+ module Zencoder::Job
2
+
3
+ extend Zencoder
4
+
5
+ def self.create(params={}, options={})
6
+ params_with_api_key = {:api_key => Zencoder.api_key}.merge(params)
7
+ Zencoder::HTTP.post("#{Zencoder.base_url}/jobs",
8
+ MultiJson.encode(params_with_api_key),
9
+ options)
10
+ end
11
+
12
+ def self.list(options={})
13
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key,
14
+ :page => options.delete(:page) || 1,
15
+ :per_page => options.delete(:per_page) || 50 }
16
+
17
+ Zencoder::HTTP.get("#{Zencoder.base_url}/jobs", merge_params(options, params))
18
+ end
19
+
20
+ def self.details(job_id, options={})
21
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
22
+ Zencoder::HTTP.get("#{Zencoder.base_url}/jobs/#{job_id}", merge_params(options, params))
23
+ end
24
+
25
+ def self.resubmit(job_id, options={})
26
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
27
+ Zencoder::HTTP.get("#{Zencoder.base_url}/jobs/#{job_id}/resubmit", merge_params(options, params))
28
+ end
29
+
30
+ def self.cancel(job_id, options={})
31
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
32
+ Zencoder::HTTP.get("#{Zencoder.base_url}/jobs/#{job_id}/cancel", merge_params(options, params))
33
+ end
34
+
35
+ def self.delete(job_id, options={})
36
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
37
+ Zencoder::HTTP.delete("#{Zencoder.base_url}/jobs/#{job_id}", merge_params(options, params))
38
+ end
39
+
40
+ end
@@ -0,0 +1,13 @@
1
+ module Zencoder::Notification
2
+
3
+ extend Zencoder
4
+
5
+ def self.list(options={})
6
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key,
7
+ :page => options.delete(:page) || 1,
8
+ :per_page => options.delete(:per_page) || 50 }
9
+
10
+ Zencoder::HTTP.get("#{Zencoder.base_url}/notifications", merge_params(options, params))
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ module Zencoder::Output
2
+
3
+ extend Zencoder
4
+
5
+ def self.progress(output_id, options={})
6
+ params = {:api_key => options.delete(:api_key) || Zencoder.api_key}
7
+ Zencoder::HTTP.get("#{Zencoder.base_url}/outputs/#{output_id}/progress", merge_params(options, params))
8
+ end
9
+
10
+ end
@@ -0,0 +1,23 @@
1
+ class Zencoder::Response
2
+
3
+ attr_accessor :code, :body, :raw_body, :raw_response
4
+
5
+ def initialize(options={})
6
+ options.each do |k, v|
7
+ send("#{k}=", v) if respond_to?("#{k}=")
8
+ end
9
+ end
10
+
11
+ def success?
12
+ code.to_i > 199 && code.to_i < 300
13
+ end
14
+
15
+ def errors
16
+ if body.is_a?(Hash)
17
+ Array(body['errors']).compact
18
+ else
19
+ []
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module Zencoder
2
+ VERSION = '2.0.0'
3
+ end
@@ -0,0 +1,22 @@
1
+ module Zencoder
2
+
3
+ class << self
4
+ attr_accessor :base_url
5
+ attr_accessor :api_key
6
+ end
7
+
8
+ self.base_url = 'https://app.zencoder.com/api'
9
+
10
+
11
+ protected
12
+
13
+ def merge_params(options, params)
14
+ if options[:params]
15
+ options[:params] = options[:params].merge(params)
16
+ options
17
+ else
18
+ options.merge(:params => params)
19
+ end
20
+ end
21
+
22
+ end
metadata CHANGED
@@ -3,50 +3,46 @@ name: zencoder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
6
+ - 2
7
7
  - 0
8
- - 7
9
- version: 1.0.7
8
+ - 0
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
- - McClain Looney
12
+ - Nathan Sutton
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-10 00:00:00 -05:00
17
+ date: 2010-06-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rest-client
21
+ name: multi_json
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 1
29
- - 5
30
- - 1
31
- version: 1.5.1
28
+ - 0
29
+ version: "0"
32
30
  type: :runtime
33
31
  version_requirements: *id001
34
32
  - !ruby/object:Gem::Dependency
35
- name: json
33
+ name: json_pure
36
34
  prerelease: false
37
35
  requirement: &id002 !ruby/object:Gem::Requirement
38
36
  requirements:
39
37
  - - ">="
40
38
  - !ruby/object:Gem::Version
41
39
  segments:
42
- - 1
43
- - 4
44
- - 3
45
- version: 1.4.3
40
+ - 0
41
+ version: "0"
46
42
  type: :runtime
47
43
  version_requirements: *id002
48
44
  - !ruby/object:Gem::Dependency
49
- name: gemcutter
45
+ name: shoulda
50
46
  prerelease: false
51
47
  requirement: &id003 !ruby/object:Gem::Requirement
52
48
  requirements:
@@ -54,69 +50,64 @@ dependencies:
54
50
  - !ruby/object:Gem::Version
55
51
  segments:
56
52
  - 0
57
- - 5
58
- - 0
59
- version: 0.5.0
53
+ version: "0"
60
54
  type: :development
61
55
  version_requirements: *id003
62
56
  - !ruby/object:Gem::Dependency
63
- name: shoulda
57
+ name: mocha
64
58
  prerelease: false
65
59
  requirement: &id004 !ruby/object:Gem::Requirement
66
60
  requirements:
67
61
  - - ">="
68
62
  - !ruby/object:Gem::Version
69
63
  segments:
70
- - 2
71
- - 10
72
64
  - 0
73
- version: 2.10.0
65
+ version: "0"
74
66
  type: :development
75
67
  version_requirements: *id004
76
68
  - !ruby/object:Gem::Dependency
77
- name: hoe
69
+ name: webmock
78
70
  prerelease: false
79
71
  requirement: &id005 !ruby/object:Gem::Requirement
80
72
  requirements:
81
73
  - - ">="
82
74
  - !ruby/object:Gem::Version
83
75
  segments:
84
- - 2
85
- - 5
86
76
  - 0
87
- version: 2.5.0
77
+ version: "0"
88
78
  type: :development
89
79
  version_requirements: *id005
90
- description: |-
91
- A small library for interacting with Zencoder.com services.
92
-
93
- See http://www.Zencoder.com for more details.
94
- email:
95
- - m@loonsoft.com
80
+ description: Zencoder <http://zencoder.com> integration library.
81
+ email: nate@zencoder.com
96
82
  executables: []
97
83
 
98
84
  extensions: []
99
85
 
100
- extra_rdoc_files:
101
- - History.txt
102
- - Manifest.txt
103
- - README.txt
86
+ extra_rdoc_files: []
87
+
104
88
  files:
105
- - History.txt
106
- - Manifest.txt
107
- - README.txt
108
- - Rakefile
109
- - lib/recipes.rb
89
+ - lib/zencoder/account.rb
90
+ - lib/zencoder/errors.rb
91
+ - lib/zencoder/http/net_http.rb
92
+ - lib/zencoder/http/typhoeus.rb
93
+ - lib/zencoder/http.rb
94
+ - lib/zencoder/job.rb
95
+ - lib/zencoder/notification.rb
96
+ - lib/zencoder/output.rb
97
+ - lib/zencoder/response.rb
98
+ - lib/zencoder/version.rb
99
+ - lib/zencoder/zencoder.rb
110
100
  - lib/zencoder.rb
111
- - test/test_zencoder.rb
101
+ - LICENSE
102
+ - README.markdown
103
+ - Rakefile
112
104
  has_rdoc: true
113
- homepage: http://www.bitbucket.org/mml/zencoder
105
+ homepage: http://github.com/zencoder/zencoder-rb
114
106
  licenses: []
115
107
 
116
108
  post_install_message:
117
- rdoc_options:
118
- - --main
119
- - README.txt
109
+ rdoc_options: []
110
+
120
111
  require_paths:
121
112
  - lib
122
113
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -139,6 +130,6 @@ rubyforge_project: zencoder
139
130
  rubygems_version: 1.3.6
140
131
  signing_key:
141
132
  specification_version: 3
142
- summary: A small library for interacting with Zencoder.com services
143
- test_files:
144
- - test/test_zencoder.rb
133
+ summary: Zencoder <http://zencoder.com> integration library.
134
+ test_files: []
135
+
@@ -1,33 +0,0 @@
1
- === 1.0.0 / 2010-04-29
2
-
3
- * 1 major enhancement
4
-
5
- * Birthday!
6
-
7
- === 1.0.1 / 2010-04-29
8
-
9
- * Updated readme
10
-
11
- === 1.0.2 / 2010-04-29
12
-
13
- * Fixed manifest
14
-
15
- === 1.0.3 / 2010-04-29
16
-
17
- * First actual working version. probably should have held off on pushing the others to gemcutter. c'est la vie.
18
-
19
- === 1.0.4 / 2010-05-03
20
-
21
- * Jobid hash now returned from the rest request to the api. Useful for receiving callbacks & such
22
-
23
- === 1.0.5 / 2010-05-20
24
-
25
- * Pulled some recipes contributed by Brian Maddy
26
-
27
- === 1.0.6 / 2010-05-28
28
-
29
- * Added support for toplevel options. {:test=>1} for example. This breaks the old api. The recipes argument to submit_job() must be present, and an optional :opts hash will be merged into the toplevel Zencoder request hash.
30
-
31
- === 1.0.7 / 2010-06-10
32
-
33
- * Merged in changes from Cory Preus for compatibility with upstream API changes.
@@ -1,7 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- lib/recipes.rb
6
- lib/zencoder.rb
7
- test/test_zencoder.rb
data/README.txt DELETED
@@ -1,101 +0,0 @@
1
- = Zencoder
2
-
3
- * http://www.bitbucket.org/mml/zencoder
4
-
5
- == DESCRIPTION:
6
-
7
- A small library for interacting with Zencoder.com services.
8
-
9
- See http://www.Zencoder.com for more details.
10
-
11
- == FEATURES/PROBLEMS:
12
-
13
- * None yet
14
-
15
- == SYNOPSIS:
16
-
17
- Zencoder.submit_job('somebigapikeynumberthing','s3://bucket/path/to/file.mov', ZencoderAPI::Recipes.iphone({:override=>value}))
18
-
19
- == REQUIREMENTS:
20
-
21
- * rest-client
22
-
23
- == INSTALL:
24
-
25
- * Get your api key from Zencoder.com, and install the gem.
26
-
27
- == DEVELOPERS:
28
-
29
- Here's the biggest input i could generate using the awesome Zencoder api builder. Note that it's nonsensical, as
30
- it turns on both skip audio and skip video flags.
31
- {
32
- "test": 1,
33
- "input": "s3://mybucket/foo",
34
- "output": [
35
- {
36
- "label": "iphone",
37
- "base_url": "s3://mybucket/",
38
- "filename": "packet/7/movie.flv",
39
- "width": 600,
40
- "height": 300,
41
- "quality": 3,
42
- "speed": 3,
43
- "upscale": 1,
44
- "stretch": 1,
45
- "frame_rate": 29.997,
46
- "max_frame_rate": 30,
47
- "keyframe_interval": 30,
48
- "video_bitrate": 500,
49
- "bitrate_cap": 600,
50
- "buffer_size": 500,
51
- "h264_profile": "high",
52
- "h264_level": 2.2,
53
- "skip_video": 1,
54
- "audio_codec": "aac",
55
- "audio_bitrate": 200,
56
- "audio_channels": 2,
57
- "audio_sample_rate": 128,
58
- "skip_audio": 1,
59
- "thumbnails": {
60
- "number": 30,
61
- "size": "100x100",
62
- "base_url": "s3://thumbnails",
63
- "prefix": "fname_prefix"
64
- },
65
- "notifications": [
66
- "http://callback",
67
- "m@loonsoft.com"
68
- ],
69
- "start_clip": 20,
70
- "clip_length": 30
71
- }
72
- ],
73
- "api_key": "your apikey"
74
- }
75
-
76
-
77
-
78
- == LICENSE:
79
-
80
- (The MIT License)
81
-
82
- Copyright (c) 2010 McClain Looney
83
-
84
- Permission is hereby granted, free of charge, to any person obtaining
85
- a copy of this software and associated documentation files (the
86
- 'Software'), to deal in the Software without restriction, including
87
- without limitation the rights to use, copy, modify, merge, publish,
88
- distribute, sublicense, and/or sell copies of the Software, and to
89
- permit persons to whom the Software is furnished to do so, subject to
90
- the following conditions:
91
-
92
- The above copyright notice and this permission notice shall be
93
- included in all copies or substantial portions of the Software.
94
-
95
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
96
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
97
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
98
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
99
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
100
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
101
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,78 +0,0 @@
1
-
2
- module ZencoderAPI #:nodoc:
3
-
4
-
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
- class Recipe
7
- @@keys = [:label, :base_url, :filename, :width, :height, :size, :quality, :speed,
8
- :upscale, :stretch, :frame_rate, :max_frame_rate, :keyframe_interval,
9
- :video_bitrate, :bitrate_cap, :buffer_size, :h264_profile, :h264_level,
10
- :skip_video, :audio_codec, :audio_bitrate, :audio_channels, :audio_sample_rate,
11
- :skip_audio, :start_clip, :clip_length, :thumbnails, :notifications, :tuning,
12
- :autolevel, :audio_quality, :deblock, :public, :denoise, :video_codec]
13
-
14
- @@thumb_keys = [:number, :size, :base_url, :prefix]
15
-
16
- # constructor. accepts a name for the recipe, and a hash of params. The constructor will try to verify that you aren't doing
17
- # something it doesn't know about, though does no further validation.
18
- def initialize(name, params )
19
- params = params.inject(Hash.new) do |m,v|
20
- m[v.first.to_s.to_sym]=v.last
21
- m
22
- end
23
- raise RecipeError.new("no recipe parameters?") if params.empty?
24
- raise RecipeError.new("unknown recipe parameter '#{params.keys - @@keys}' ") unless (params.keys - @@keys).empty?
25
- if params[:thumbnails]
26
- raise RecipeError.new("unknown thumb keys #{params[:thumbnails].keys - @@thumb_keys}") unless (params[:thumbnails].keys - @@thumb_keys).empty?
27
- end
28
- @o = params
29
- end
30
-
31
- def to_hash
32
- @o
33
- end
34
-
35
- def to_json(*arg) #:nodoc:
36
- @o.to_json(*arg)
37
- end
38
- end
39
-
40
- # Raised if something goes wrong with a recipe configuration
41
- class RecipeError < Exception; end
42
-
43
- # Some example recipes.
44
- module Recipes
45
- #A sample iphone recipe. if you have a better one, send me a patch.
46
- def self.iphone(params={})
47
- raise "Base_url unset." unless params['base_url']
48
- defaults = {
49
- "label"=> "iphone",
50
- "size"=> "480x320",
51
- "frame_rate"=> 24,
52
- "max_frame_rate"=> 24,
53
- "video_bitrate"=> 40,
54
- "bitrate_cap"=> 100
55
- }
56
-
57
- params = defaults.merge(params)
58
-
59
- Recipe.new(:iphone, params)
60
- end
61
-
62
- # A sample web recipe. if you have a better one, send me a patch.
63
- def self.web(params={})
64
- raise "Base_url unset." unless params['base_url']
65
- defaults = {
66
- "label"=> "web",
67
- "width"=> 240,
68
- "frame_rate"=> 24,
69
- "max_frame_rate"=> 24,
70
- "video_bitrate"=> 40,
71
- "bitrate_cap"=> 100
72
- }
73
- params = defaults.merge(params)
74
-
75
- Recipe.new(:web, params)
76
- end
77
- end
78
- end
@@ -1,122 +0,0 @@
1
- require 'rubygems'
2
- require "test/unit"
3
- require "zencoder"
4
- require 'shoulda'
5
- require 'mocha'
6
- require 'ruby-debug'
7
-
8
- class TestZencoder < Test::Unit::TestCase
9
-
10
- context "the zn lib" do
11
- setup do
12
- @src='s3://test_development/spark.avi'
13
- @api = 'https://app.zencoder.com'
14
- @apikey = ENV['ZC_APIKEY']
15
- @base_url = 's3://test_development/zencoder_asset'
16
- @recipe = ZencoderAPI::Recipes.iphone('base_url' =>@base_url)
17
- @recipe2 = ZencoderAPI::Recipes.web('base_url' =>@base_url,
18
- :thumbnails => {
19
- :number => 1,
20
- :size => "75x75"})
21
- assert_not_nil @apikey, "export ZC_APIKEY before you run the tests"
22
- end
23
- context "posting a new job" do
24
- setup do
25
- @resp =<<-EOS
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}]}
27
- EOS
28
- end
29
-
30
- should "return jobid" do
31
- RestClient.expects(:post).returns(@resp)
32
- h = Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2])
33
- assert_equal Hash, h.class
34
- end
35
-
36
- should "be able to submit a job with opts" do
37
- RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z|
38
- assert_equal x, 'https://app.zencoder.com/api/jobs'
39
- body = JSON.parse(y)
40
- assert_equal body['input'], @src
41
- assert_equal @base_url, body['output'][0]['base_url']
42
- assert_equal @base_url, body['output'][1]['base_url']
43
- assert_equal 'web', body['output'][1]['label']
44
- assert_equal 'iphone', body['output'][0]['label']
45
- assert_equal @apikey, body['api_key']
46
- assert_equal 1, body['test']
47
- assert_equal :json, z[:content_type]
48
- assert_equal :json, z[:accept]
49
- true
50
- }.returns(@resp)
51
- Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2], :test => 1)
52
- end
53
-
54
- should "be able to submit a job" do
55
- RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z|
56
- assert_equal x, 'https://app.zencoder.com/api/jobs'
57
- body = JSON.parse(y)
58
- assert_equal body['input'], @src
59
- assert_equal body['output'][0]['base_url'], @base_url
60
- assert_equal body['output'][1]['base_url'], @base_url
61
- assert_equal body['output'][1]['label'], 'web'
62
- assert_equal body['output'][0]['label'], 'iphone'
63
- assert_equal body['api_key'], @apikey
64
- assert_nil body['test']
65
- assert_equal z[:content_type], :json
66
- assert_equal z[:accept], :json
67
- true
68
- }.returns(@resp)
69
- Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2])
70
- end
71
- should "be able to muck the config " do
72
- RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z|
73
- body = JSON.parse(y)
74
- assert_equal body['foo'],'bar'
75
- true
76
- }.returns(@resp)
77
- Zencoder.submit_job(@apikey, @src, @recipe) do |config|
78
- config[:foo]='bar'
79
- assert config[:output].first.is_a? Hash
80
- end
81
- end
82
- should "be able to submit a job with 1 recipe" do
83
- RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z|
84
- assert_equal x, 'https://app.zencoder.com/api/jobs'
85
- body = JSON.parse(y)
86
- assert_equal body['input'], @src
87
- assert_equal body['output'][0]['base_url'], @base_url
88
- assert_equal body['output'][0]['label'], 'iphone'
89
- assert_equal body['api_key'], @apikey
90
- assert_equal z[:content_type], :json
91
- assert_equal z[:accept], :json
92
- true
93
- }.returns(@resp)
94
- Zencoder.submit_job(@apikey, @src, @recipe)
95
- end
96
- end
97
- should "raise error when given bad data" do
98
- assert_raise ZencoderAPI::RecipeError do
99
- ZencoderAPI::Recipes.web('base_url' =>@base_url, :bad_key => 'wtf?')
100
- end
101
- assert_raise ZencoderAPI::RecipeError do
102
- ZencoderAPI::Recipes.web('base_url' =>@base_url, :thumbnails => {:bad_key => 'wtf?'})
103
- end
104
- end
105
- context "with the following request" do
106
- setup do
107
- @params = JSON.parse(IO.readlines('test/fixtures/sample_request.json').to_s)
108
- @params['output'] = @params['output'][0]
109
- # Change string keys to symbols, no HashWithIndifferentAccess
110
- @params['output']['thumbnails'].each_pair do |key, value|
111
- @params['output']['thumbnails'][key.to_sym] = value
112
- @params['output']['thumbnails'].delete(key)
113
- end
114
- end
115
- should "have the output keys" do
116
- assert_nothing_raised do
117
- ZencoderAPI::Recipes.web({'base_url' => @base_url}.merge(@params['output']))
118
- end
119
- end
120
- end
121
- end
122
- end