zencoder 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/zencoder.rb +2 -8
- data/lib/zencoder/account.rb +17 -17
- data/lib/zencoder/errors.rb +3 -4
- data/lib/zencoder/http.rb +74 -40
- data/lib/zencoder/http/net_http.rb +107 -110
- data/lib/zencoder/http/typhoeus.rb +17 -13
- data/lib/zencoder/job.rb +37 -37
- data/lib/zencoder/notification.rb +8 -8
- data/lib/zencoder/output.rb +6 -6
- data/lib/zencoder/response.rb +17 -15
- data/lib/zencoder/version.rb +2 -2
- data/lib/zencoder/zencoder.rb +34 -6
- metadata +8 -20
data/lib/zencoder.rb
CHANGED
@@ -4,19 +4,13 @@ require 'net/https'
|
|
4
4
|
require 'timeout'
|
5
5
|
|
6
6
|
# Gems
|
7
|
-
require '
|
8
|
-
|
9
|
-
begin
|
10
|
-
MultiJson.engine
|
11
|
-
rescue LoadError
|
12
|
-
require 'json'
|
13
|
-
end
|
7
|
+
require 'active_support' # JSON and XML parsing/encoding
|
14
8
|
|
15
9
|
# Zencoder
|
16
10
|
require 'zencoder/zencoder'
|
17
|
-
require 'zencoder/http'
|
18
11
|
require 'zencoder/http/net_http'
|
19
12
|
require 'zencoder/http/typhoeus'
|
13
|
+
require 'zencoder/http'
|
20
14
|
require 'zencoder/errors'
|
21
15
|
require 'zencoder/job'
|
22
16
|
require 'zencoder/output'
|
data/lib/zencoder/account.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class Account < Zencoder
|
2
3
|
|
3
|
-
|
4
|
+
def self.create(params={}, options={})
|
5
|
+
HTTP.post("#{base_url}/account", encode(params, options[:format]), options)
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
def self.details(options={})
|
9
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
10
|
+
HTTP.get("#{base_url}/account", merge_params(options, params))
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
def self.integration(options={})
|
14
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
15
|
+
HTTP.get("#{base_url}/account/integration", merge_params(options, params))
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def self.live(options={})
|
19
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
20
|
+
HTTP.get("#{base_url}/account/live", merge_params(options, params))
|
21
|
+
end
|
18
22
|
|
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
23
|
end
|
23
|
-
|
24
24
|
end
|
data/lib/zencoder/errors.rb
CHANGED
data/lib/zencoder/http.rb
CHANGED
@@ -1,56 +1,90 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class HTTP < Zencoder
|
2
3
|
|
3
|
-
|
4
|
-
attr_accessor :default_options
|
5
|
-
attr_writer :http_backend
|
6
|
-
end
|
4
|
+
attr_accessor :body, :url, :options, :method, :format
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
'Content-Type' => 'application/json'}}
|
6
|
+
cattr_accessor :default_options
|
7
|
+
cattr_accessor :http_backend
|
11
8
|
|
12
|
-
|
13
|
-
@http_backend ||= Zencoder::HTTP::NetHTTP
|
14
|
-
end
|
9
|
+
self.http_backend = NetHTTP
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
self.default_options = {:timeout => 10000,
|
12
|
+
:headers => {'Accept' => 'application/json',
|
13
|
+
'Content-Type' => 'application/json'}}
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def initialize(method, url, options={})
|
16
|
+
self.method = method
|
17
|
+
self.url = url
|
18
|
+
self.options = options
|
19
|
+
self.format = options.delete(:format)
|
20
|
+
self.body = options.delete(:body)
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def self.post(url, body, options={})
|
24
|
+
new(:post, url, options.merge(:body => body)).perform_method
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def self.put(url, body, options={})
|
28
|
+
new(:put, url, options.merge(:body => body)).perform_method
|
29
|
+
end
|
31
30
|
|
31
|
+
def self.get(url, options={})
|
32
|
+
new(:get, url, options).perform_method
|
33
|
+
end
|
32
34
|
|
33
|
-
|
35
|
+
def self.delete(url, options={})
|
36
|
+
new(:delete, url, options).perform_method
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
def perform_method
|
40
|
+
process(http_backend.send(method, url, options))
|
41
|
+
rescue StandardError => e
|
42
|
+
raise HTTPError, "#{e.class} - #{e.message}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def options=(value)
|
46
|
+
@options = default_options.merge(value || {})
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
options[:headers] ||= {}
|
49
|
+
options[:headers]['Accept'] ||= "application/#{format}"
|
50
|
+
options[:headers]['Content-Type'] ||= "application/#{format}"
|
44
51
|
|
45
|
-
|
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
|
52
|
+
options
|
49
53
|
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def options
|
56
|
+
@options || self.options = default_options
|
57
|
+
end
|
58
|
+
|
59
|
+
def format
|
60
|
+
@format ||= :json
|
61
|
+
end
|
62
|
+
|
63
|
+
def http_backend
|
64
|
+
self.class.http_backend
|
65
|
+
end
|
66
|
+
|
67
|
+
def default_options
|
68
|
+
self.class.default_options
|
69
|
+
end
|
55
70
|
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
def process(http_response)
|
75
|
+
response = Response.new
|
76
|
+
response.code = http_response.code
|
77
|
+
|
78
|
+
begin
|
79
|
+
response.body = decode(http_response.body.to_s, format)
|
80
|
+
rescue StandardError # Hack! Returns different exceptions depending on the decoding engine
|
81
|
+
response.body = http_response.body
|
82
|
+
end
|
83
|
+
|
84
|
+
response.raw_body = http_response.body
|
85
|
+
response.raw_response = http_response
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
56
90
|
end
|
@@ -1,142 +1,139 @@
|
|
1
1
|
# Ruby's Net/HTTP Sucks
|
2
2
|
# Borrowed root cert checking from http://redcorundum.blogspot.com/2008/03/ssl-certificates-and-nethttps.html
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
4
|
+
class Zencoder
|
5
|
+
class HTTP < Zencoder
|
6
|
+
class NetHTTP
|
7
|
+
|
8
|
+
attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :options
|
9
|
+
|
10
|
+
cattr_accessor :root_cert_paths
|
11
|
+
|
12
|
+
self.root_cert_paths = ['/etc/ssl/certs',
|
13
|
+
'/var/ssl',
|
14
|
+
'/usr/share/ssl',
|
15
|
+
'/usr/ssl',
|
16
|
+
'/etc/ssl',
|
17
|
+
'/usr/local/openssl',
|
18
|
+
'/usr/lib/ssl',
|
19
|
+
'/System/Library/OpenSSL',
|
20
|
+
'/etc/openssl',
|
21
|
+
'/usr/local/ssl',
|
22
|
+
'/etc/pki/tls']
|
23
|
+
|
24
|
+
def initialize(method, url, options)
|
25
|
+
@method = method
|
26
|
+
@url = url
|
27
|
+
@body = options.delete(:body)
|
28
|
+
@params = options.delete(:params)
|
29
|
+
@headers = options.delete(:headers)
|
30
|
+
@timeout = options.delete(:timeout)
|
31
|
+
@options = options
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def self.post(url, options={})
|
35
|
+
new(:post, url, options).perform
|
36
|
+
end
|
37
37
|
|
38
|
-
|
38
|
+
def self.put(url, options={})
|
39
|
+
new(:get, url, options).perform
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
def self.get(url, options={})
|
43
|
+
new(:get, url, options).perform
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
46
|
+
def self.delete(url, options={})
|
47
|
+
new(:delete, url, options).perform
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
def perform
|
51
|
+
deliver(http, request)
|
52
|
+
end
|
49
53
|
|
50
|
-
request = Net::HTTP::Get.new(path_with_query_string(uri))
|
51
54
|
|
52
|
-
|
55
|
+
protected
|
53
56
|
|
54
|
-
|
55
|
-
|
57
|
+
def deliver(http, request)
|
58
|
+
if timeout
|
59
|
+
Timeout.timeout(timeout / 1000.0) do
|
60
|
+
http.request(request)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
http.request(request)
|
64
|
+
end
|
65
|
+
end
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
add_params_to_query_string(uri, options[:params])
|
67
|
+
def http
|
68
|
+
u = uri
|
60
69
|
|
61
|
-
|
70
|
+
http = Net::HTTP.new(u.host, u.port)
|
62
71
|
|
63
|
-
|
72
|
+
if u.scheme == 'https'
|
73
|
+
http.use_ssl = true
|
64
74
|
|
65
|
-
|
66
|
-
|
75
|
+
if root_cert_path = locate_root_cert_path
|
76
|
+
http.ca_path = root_cert_path
|
77
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
78
|
+
http.verify_depth = 5
|
79
|
+
else
|
80
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
81
|
+
end
|
82
|
+
end
|
67
83
|
|
84
|
+
http
|
85
|
+
end
|
68
86
|
|
69
|
-
|
87
|
+
def request
|
88
|
+
r = request_class.new(path)
|
89
|
+
r.body = body if body
|
90
|
+
if headers
|
91
|
+
headers.each do |header, value|
|
92
|
+
r.add_field(header.to_s, value.to_s)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
r
|
96
|
+
end
|
70
97
|
|
71
|
-
|
72
|
-
|
98
|
+
def uri
|
99
|
+
u = URI.parse(url)
|
73
100
|
|
74
|
-
|
75
|
-
|
101
|
+
if params
|
102
|
+
params_as_query = params.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
|
103
|
+
if u.query.to_s.empty?
|
104
|
+
u.query = params_as_query
|
105
|
+
else
|
106
|
+
u.query = [u.query.to_s, params_as_query].join('&')
|
107
|
+
end
|
108
|
+
end
|
76
109
|
|
77
|
-
|
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
|
110
|
+
u
|
83
111
|
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
112
|
|
94
|
-
|
95
|
-
|
96
|
-
else
|
97
|
-
uri.path + '?' + uri.query.to_s
|
98
|
-
end
|
99
|
-
end
|
113
|
+
def path
|
114
|
+
u = uri
|
100
115
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
116
|
+
if u.path.empty?
|
117
|
+
u.path = '/'
|
118
|
+
end
|
106
119
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
120
|
+
if u.query.to_s.empty?
|
121
|
+
u.path
|
122
|
+
else
|
123
|
+
u.path + '?' + u.query.to_s
|
124
|
+
end
|
111
125
|
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
126
|
|
121
|
-
|
122
|
-
|
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('&')
|
127
|
+
def request_class
|
128
|
+
Net::HTTP.const_get(method.to_s.capitalize)
|
128
129
|
end
|
129
|
-
end
|
130
|
-
end
|
131
130
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
131
|
+
def locate_root_cert_path
|
132
|
+
self.class.root_cert_paths.detect do |root_cert_path|
|
133
|
+
File.directory?(root_cert_path)
|
134
|
+
end
|
136
135
|
end
|
137
|
-
|
138
|
-
http.request(request)
|
136
|
+
|
139
137
|
end
|
140
138
|
end
|
141
|
-
|
142
139
|
end
|
@@ -1,19 +1,23 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class HTTP < Zencoder
|
3
|
+
class Typhoeus
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def self.post(url, options={})
|
6
|
+
::Typhoeus::Request.post(url, options)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
def self.put(url, options={})
|
10
|
+
::Typhoeus::Request.put(url, options)
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
def self.get(url, options={})
|
14
|
+
::Typhoeus::Request.get(url, options)
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
def self.delete(url, options={})
|
18
|
+
::Typhoeus::Request.delete(url, options)
|
19
|
+
end
|
18
20
|
|
21
|
+
end
|
22
|
+
end
|
19
23
|
end
|
data/lib/zencoder/job.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class Job < Zencoder
|
3
|
+
|
4
|
+
def self.create(params={}, options={})
|
5
|
+
params_with_api_key = {:api_key => api_key}.merge(params)
|
6
|
+
HTTP.post("#{base_url}/jobs",
|
7
|
+
encode(params_with_api_key, options[:format]),
|
8
|
+
options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.list(options={})
|
12
|
+
params = {:api_key => options.delete(:api_key) || api_key,
|
13
|
+
:page => options.delete(:page) || 1,
|
14
|
+
:per_page => options.delete(:per_page) || 50 }
|
15
|
+
|
16
|
+
HTTP.get("#{base_url}/jobs", merge_params(options, params))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.details(job_id, options={})
|
20
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
21
|
+
HTTP.get("#{base_url}/jobs/#{job_id}", merge_params(options, params))
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.resubmit(job_id, options={})
|
25
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
26
|
+
HTTP.get("#{base_url}/jobs/#{job_id}/resubmit", merge_params(options, params))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cancel(job_id, options={})
|
30
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
31
|
+
HTTP.get("#{base_url}/jobs/#{job_id}/cancel", merge_params(options, params))
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.delete(job_id, options={})
|
35
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
36
|
+
HTTP.delete("#{base_url}/jobs/#{job_id}", merge_params(options, params))
|
37
|
+
end
|
2
38
|
|
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
39
|
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
40
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class Notification < Zencoder
|
2
3
|
|
3
|
-
|
4
|
+
def self.list(options={})
|
5
|
+
params = {:api_key => options.delete(:api_key) || api_key,
|
6
|
+
:page => options.delete(:page) || 1,
|
7
|
+
:per_page => options.delete(:per_page) || 50 }
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
:page => options.delete(:page) || 1,
|
8
|
-
:per_page => options.delete(:per_page) || 50 }
|
9
|
+
HTTP.get("#{base_url}/notifications", merge_params(options, params))
|
10
|
+
end
|
9
11
|
|
10
|
-
Zencoder::HTTP.get("#{Zencoder.base_url}/notifications", merge_params(options, params))
|
11
12
|
end
|
12
|
-
|
13
13
|
end
|
data/lib/zencoder/output.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
|
+
class Output < Zencoder
|
2
3
|
|
3
|
-
|
4
|
+
def self.progress(output_id, options={})
|
5
|
+
params = {:api_key => options.delete(:api_key) || api_key}
|
6
|
+
HTTP.get("#{base_url}/outputs/#{output_id}/progress", merge_params(options, params))
|
7
|
+
end
|
4
8
|
|
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
9
|
end
|
9
|
-
|
10
10
|
end
|
data/lib/zencoder/response.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
class Zencoder
|
1
|
+
class Zencoder
|
2
|
+
class Response < Zencoder
|
2
3
|
|
3
|
-
|
4
|
+
attr_accessor :code, :body, :raw_body, :raw_response
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def initialize(options={})
|
7
|
+
options.each do |k, v|
|
8
|
+
send("#{k}=", v) if respond_to?("#{k}=")
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def success?
|
13
|
+
code.to_i > 199 && code.to_i < 300
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def errors
|
17
|
+
if body.is_a?(Hash)
|
18
|
+
Array(body['errors']).compact
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
24
|
+
end
|
23
25
|
end
|
data/lib/zencoder/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '2.
|
1
|
+
class Zencoder
|
2
|
+
VERSION = '2.1.0'
|
3
3
|
end
|
data/lib/zencoder/zencoder.rb
CHANGED
@@ -1,16 +1,44 @@
|
|
1
|
-
|
1
|
+
class Zencoder
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
attr_accessor :api_key
|
6
|
-
end
|
3
|
+
cattr_accessor :base_url
|
4
|
+
cattr_accessor :api_key
|
7
5
|
|
8
6
|
self.base_url = 'https://app.zencoder.com/api'
|
9
7
|
|
8
|
+
def self.encode(content, format)
|
9
|
+
if content.is_a?(String)
|
10
|
+
content
|
11
|
+
elsif format.to_s == 'xml'
|
12
|
+
content.to_xml
|
13
|
+
elsif
|
14
|
+
content.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def encode(content, format)
|
19
|
+
self.class.encode(content, format)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.decode(content, format)
|
23
|
+
if content.is_a?(String)
|
24
|
+
if format.to_s == 'xml'
|
25
|
+
ActiveSupport::XmlMini.parse(content)
|
26
|
+
else
|
27
|
+
ActiveSupport::JSON.decode(content)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
content
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def decode(content, format)
|
35
|
+
self.class.decode(content, format)
|
36
|
+
end
|
37
|
+
|
10
38
|
|
11
39
|
protected
|
12
40
|
|
13
|
-
def merge_params(options, params)
|
41
|
+
def self.merge_params(options, params)
|
14
42
|
if options[:params]
|
15
43
|
options[:params] = options[:params].merge(params)
|
16
44
|
options
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 2.0.0
|
9
|
+
version: 2.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nathan Sutton
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-30 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: active_support
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
type: :runtime
|
31
31
|
version_requirements: *id001
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
33
|
+
name: shoulda
|
34
34
|
prerelease: false
|
35
35
|
requirement: &id002 !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
@@ -39,10 +39,10 @@ dependencies:
|
|
39
39
|
segments:
|
40
40
|
- 0
|
41
41
|
version: "0"
|
42
|
-
type: :
|
42
|
+
type: :development
|
43
43
|
version_requirements: *id002
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
45
|
+
name: mocha
|
46
46
|
prerelease: false
|
47
47
|
requirement: &id003 !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
type: :development
|
55
55
|
version_requirements: *id003
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: webmock
|
58
58
|
prerelease: false
|
59
59
|
requirement: &id004 !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
@@ -65,18 +65,6 @@ dependencies:
|
|
65
65
|
version: "0"
|
66
66
|
type: :development
|
67
67
|
version_requirements: *id004
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: webmock
|
70
|
-
prerelease: false
|
71
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
type: :development
|
79
|
-
version_requirements: *id005
|
80
68
|
description: Zencoder <http://zencoder.com> integration library.
|
81
69
|
email: nate@zencoder.com
|
82
70
|
executables: []
|