transloadit 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +23 -0
- data/.standard.yml +0 -0
- data/CHANGELOG.md +68 -57
- data/Gemfile +1 -1
- data/README.md +162 -86
- data/Rakefile +12 -17
- data/examples/README.md +94 -55
- data/examples/basic/audio-concat-transcoder.rb +29 -19
- data/examples/basic/audio-transcoder.rb +32 -22
- data/examples/basic/image-transcoder.rb +22 -17
- data/examples/basic/main.rb +31 -37
- data/examples/basic/media-transcoder.rb +2 -7
- data/lib/transloadit/api_model.rb +13 -13
- data/lib/transloadit/assembly.rb +27 -24
- data/lib/transloadit/exception.rb +2 -4
- data/lib/transloadit/request.rb +58 -52
- data/lib/transloadit/response/assembly.rb +14 -13
- data/lib/transloadit/response.rb +10 -10
- data/lib/transloadit/step.rb +13 -13
- data/lib/transloadit/template.rb +5 -5
- data/lib/transloadit/version.rb +1 -1
- data/lib/transloadit.rb +24 -24
- data/test/fixtures/cassettes/cancel_assembly.yml +3 -3
- data/test/fixtures/cassettes/create_template.yml +1 -1
- data/test/fixtures/cassettes/delete_template.yml +1 -1
- data/test/fixtures/cassettes/fetch_assemblies.yml +1 -1
- data/test/fixtures/cassettes/fetch_assembly_aborted.yml +3 -3
- data/test/fixtures/cassettes/fetch_assembly_errors.yml +3 -3
- data/test/fixtures/cassettes/fetch_assembly_executing.yml +3 -3
- data/test/fixtures/cassettes/fetch_assembly_notifications.yml +1 -1
- data/test/fixtures/cassettes/fetch_assembly_ok.yml +6 -6
- data/test/fixtures/cassettes/fetch_assembly_uploading.yml +3 -3
- data/test/fixtures/cassettes/fetch_billing.yml +1 -1
- data/test/fixtures/cassettes/fetch_root.yml +3 -3
- data/test/fixtures/cassettes/fetch_template.yml +1 -1
- data/test/fixtures/cassettes/fetch_templates.yml +1 -1
- data/test/fixtures/cassettes/post_assembly.yml +2 -2
- data/test/fixtures/cassettes/rate_limit_fail.yml +3 -3
- data/test/fixtures/cassettes/rate_limit_succeed.yml +4 -4
- data/test/fixtures/cassettes/replay_assembly.yml +2 -2
- data/test/fixtures/cassettes/replay_assembly_notification.yml +1 -1
- data/test/fixtures/cassettes/submit_assembly.yml +3 -3
- data/test/fixtures/cassettes/update_template.yml +1 -1
- data/test/test_helper.rb +10 -10
- data/test/unit/test_transloadit.rb +66 -66
- data/test/unit/transloadit/test_api.rb +35 -33
- data/test/unit/transloadit/test_assembly.rb +148 -112
- data/test/unit/transloadit/test_request.rb +41 -42
- data/test/unit/transloadit/test_response.rb +76 -76
- data/test/unit/transloadit/test_step.rb +52 -52
- data/test/unit/transloadit/test_template.rb +49 -54
- data/transloadit.gemspec +25 -26
- metadata +25 -41
- data/.travis.yml +0 -13
data/lib/transloadit/assembly.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
3
|
#
|
4
4
|
# Represents an Assembly API ready to make calls to the REST API endpoints.
|
@@ -22,7 +22,7 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
22
22
|
# server-side template. It's submitted along with a list of files to process,
|
23
23
|
# at which point Transloadit will process and store the files according to the
|
24
24
|
# rules in the Assembly.
|
25
|
-
# See the Transloadit {documentation}[
|
25
|
+
# See the Transloadit {documentation}[https://transloadit.com/docs/building-assembly-instructions]
|
26
26
|
# for futher information on Assemblies and their parameters.
|
27
27
|
#
|
28
28
|
# Accepts as many IO objects as you wish to process in the assembly.
|
@@ -36,7 +36,7 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
36
36
|
# @param [Array<IO>] *ios the files for the assembly to process
|
37
37
|
# @param [Hash] params additional POST data to submit with the request;
|
38
38
|
# for a full list of parameters, see the official documentation
|
39
|
-
# on {templates}[
|
39
|
+
# on {templates}[https://transloadit.com/docs/templates].
|
40
40
|
# @option params [Step, Array<Step>] :steps the steps to perform in this
|
41
41
|
# assembly
|
42
42
|
# @option params [String] :notify_url A URL to be POSTed when the assembly
|
@@ -46,18 +46,18 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
46
46
|
# specifying params here directly
|
47
47
|
#
|
48
48
|
def create!(*ios, **params)
|
49
|
-
params[:steps] = _wrap_steps_in_hash(params[:steps])
|
49
|
+
params[:steps] = _wrap_steps_in_hash(params[:steps]) unless params[:steps].nil?
|
50
50
|
|
51
51
|
extra_params = {}
|
52
|
-
extra_params.merge!(
|
52
|
+
extra_params.merge!(options[:fields]) if options[:fields]
|
53
53
|
|
54
|
-
trials =
|
54
|
+
trials = options[:tries] || DEFAULT_TRIES
|
55
55
|
(1..trials).each do |trial|
|
56
56
|
# update the payload with file entries
|
57
|
-
ios.each_with_index {|f, i| extra_params.update
|
57
|
+
ios.each_with_index { |f, i| extra_params.update "file_#{i}": f }
|
58
58
|
|
59
59
|
response = _do_request(
|
60
|
-
|
60
|
+
"/assemblies", params, "post", extra_params
|
61
61
|
).extend!(Transloadit::Response::Assembly)
|
62
62
|
|
63
63
|
return response unless response.rate_limit?
|
@@ -71,9 +71,9 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
71
71
|
# keeping this method for backward compatibility
|
72
72
|
#
|
73
73
|
def submit!(*ios)
|
74
|
-
warn "#{caller(1)
|
74
|
+
warn "#{caller(1..1).first}: warning: Transloadit::Assembly#submit!" \
|
75
75
|
" is deprecated. use Transloadit::Assembly#create! instead"
|
76
|
-
|
76
|
+
create!(*ios)
|
77
77
|
end
|
78
78
|
|
79
79
|
#
|
@@ -81,7 +81,7 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
81
81
|
# @param [Hash] additional GET data to submit with the request
|
82
82
|
#
|
83
83
|
def list(params = {})
|
84
|
-
_do_request(
|
84
|
+
_do_request("/assemblies", params)
|
85
85
|
end
|
86
86
|
|
87
87
|
#
|
@@ -98,8 +98,8 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
98
98
|
# @param [Hash] params additional POST data to submit with the request
|
99
99
|
#
|
100
100
|
def replay(id, params = {})
|
101
|
-
params
|
102
|
-
_do_request("/assemblies/#{id}/replay", params,
|
101
|
+
params[:wait] = false
|
102
|
+
_do_request("/assemblies/#{id}/replay", params, "post").extend!(Transloadit::Response::Assembly)
|
103
103
|
end
|
104
104
|
|
105
105
|
#
|
@@ -116,17 +116,17 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
116
116
|
# @param [Hash] params additional POST data to submit with the request
|
117
117
|
#
|
118
118
|
def replay_notification(id, params = {})
|
119
|
-
_do_request("/assembly_notifications/#{id}/replay", params,
|
119
|
+
_do_request("/assembly_notifications/#{id}/replay", params, "post")
|
120
120
|
end
|
121
121
|
|
122
122
|
#
|
123
123
|
# @return [Hash] a Transloadit-compatible Hash of the Assembly's contents
|
124
124
|
#
|
125
125
|
def to_hash
|
126
|
-
|
127
|
-
:
|
128
|
-
:
|
129
|
-
).delete_if {|k,v| v.nil?}
|
126
|
+
options.merge(
|
127
|
+
auth: transloadit.to_hash,
|
128
|
+
steps: steps
|
129
|
+
).delete_if { |k, v| v.nil? }
|
130
130
|
end
|
131
131
|
|
132
132
|
private
|
@@ -140,11 +140,14 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
140
140
|
#
|
141
141
|
def _wrap_steps_in_hash(steps)
|
142
142
|
case steps
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
when nil then steps
|
144
|
+
when Hash then steps
|
145
|
+
when Transloadit::Step then steps.to_hash
|
146
|
+
else
|
147
|
+
if steps.uniq(&:name) != steps
|
148
|
+
raise ArgumentError, "There are different Assembly steps using the same name"
|
149
|
+
end
|
150
|
+
steps.inject({}) { |h, s| h.update s }
|
148
151
|
end
|
149
152
|
end
|
150
153
|
|
@@ -160,7 +163,7 @@ class Transloadit::Assembly < Transloadit::ApiModel
|
|
160
163
|
warn "Rate limit reached. Waiting for #{response.wait_time} seconds before retrying."
|
161
164
|
sleep response.wait_time
|
162
165
|
# RestClient closes file streams at the end of a request.
|
163
|
-
ios.collect! {|file| open file.path }
|
166
|
+
ios.collect! { |file| File.open file.path }
|
164
167
|
else
|
165
168
|
raise Transloadit::Exception::RateLimitReached.new(response)
|
166
169
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rest-client"
|
4
4
|
|
5
5
|
module Transloadit::Exception
|
6
|
-
|
7
6
|
#
|
8
7
|
# Exception raised when Rate limit error response is returned from the API.
|
9
8
|
# See {Rate Limiting}[https://transloadit.com/docs/api-docs/#rate-limiting]
|
10
9
|
#
|
11
10
|
class RateLimitReached < RestClient::RequestEntityTooLarge
|
12
|
-
|
13
11
|
def default_message
|
14
12
|
retry_msg = " Retry in #{@response.wait_time} seconds" if @response
|
15
13
|
"Transloadit Rate Limit Reached.#{retry_msg}"
|
data/lib/transloadit/request.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rest-client"
|
4
|
+
require "openssl"
|
5
5
|
|
6
6
|
#
|
7
7
|
# Wraps requests to the Transloadit API. Ensures all API requests return a
|
@@ -10,16 +10,16 @@ require 'openssl'
|
|
10
10
|
#
|
11
11
|
class Transloadit::Request
|
12
12
|
# The default Transloadit API endpoint.
|
13
|
-
API_ENDPOINT = URI.parse(
|
13
|
+
API_ENDPOINT = URI.parse("https://api2.transloadit.com/")
|
14
14
|
|
15
15
|
# The default headers to send to the API.
|
16
|
-
API_HEADERS
|
16
|
+
API_HEADERS = {"Transloadit-Client" => "ruby-sdk:#{Transloadit::VERSION}"}
|
17
17
|
|
18
18
|
# The HMAC algorithm used for calculation request signatures.
|
19
|
-
HMAC_ALGORITHM = OpenSSL::Digest.new(
|
19
|
+
HMAC_ALGORITHM = OpenSSL::Digest.new("sha1")
|
20
20
|
|
21
21
|
# @return [String] the API endpoint for the request
|
22
|
-
attr_reader
|
22
|
+
attr_reader :url
|
23
23
|
|
24
24
|
# @return [String] the authentication secret to sign the request with
|
25
25
|
attr_accessor :secret
|
@@ -34,7 +34,7 @@ class Transloadit::Request
|
|
34
34
|
# @param [String] secret an optional secret with which to sign the request
|
35
35
|
#
|
36
36
|
def initialize(url, secret = nil)
|
37
|
-
self.url
|
37
|
+
self.url = URI.parse(url.to_s)
|
38
38
|
self.secret = secret
|
39
39
|
end
|
40
40
|
|
@@ -46,8 +46,8 @@ class Transloadit::Request
|
|
46
46
|
# @return [Transloadit::Response] the response
|
47
47
|
#
|
48
48
|
def get(params = {})
|
49
|
-
|
50
|
-
|
49
|
+
request! do
|
50
|
+
api[url.path + to_query(params)].get(API_HEADERS)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -59,9 +59,9 @@ class Transloadit::Request
|
|
59
59
|
# @return [Transloadit::Response] the response
|
60
60
|
#
|
61
61
|
def delete(payload = {})
|
62
|
-
|
63
|
-
options = {:
|
64
|
-
|
62
|
+
request! do
|
63
|
+
options = {payload: to_payload(payload)}
|
64
|
+
api(options)[url.path].delete(API_HEADERS)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -73,8 +73,8 @@ class Transloadit::Request
|
|
73
73
|
# @return [Transloadit::Response] the response
|
74
74
|
#
|
75
75
|
def post(payload = {})
|
76
|
-
|
77
|
-
|
76
|
+
request! do
|
77
|
+
api[url.path].post(to_payload(payload), API_HEADERS)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -86,8 +86,8 @@ class Transloadit::Request
|
|
86
86
|
# @return [Transloadit::Response] the response
|
87
87
|
#
|
88
88
|
def put(payload = {})
|
89
|
-
|
90
|
-
|
89
|
+
request! do
|
90
|
+
api[url.path].put(to_payload(payload), API_HEADERS)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -95,7 +95,18 @@ class Transloadit::Request
|
|
95
95
|
# @return [String] a human-readable version of the prepared Request
|
96
96
|
#
|
97
97
|
def inspect
|
98
|
-
|
98
|
+
url.to_s.inspect
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Computes an HMAC digest from the key and message.
|
103
|
+
#
|
104
|
+
# @param [String] key the secret key to sign with
|
105
|
+
# @param [String] message the message to sign
|
106
|
+
# @return [String] the signature of the message
|
107
|
+
#
|
108
|
+
def self._hmac(key, message)
|
109
|
+
OpenSSL::HMAC.hexdigest HMAC_ALGORITHM, key, message
|
99
110
|
end
|
100
111
|
|
101
112
|
protected
|
@@ -110,11 +121,9 @@ class Transloadit::Request
|
|
110
121
|
# @return [RestClient::Resource] the API endpoint for this instance
|
111
122
|
#
|
112
123
|
def api(options = {})
|
113
|
-
@api ||=
|
114
|
-
|
115
|
-
|
116
|
-
else RestClient::Resource.new(API_ENDPOINT.host, options = options)
|
117
|
-
end
|
124
|
+
@api ||= case url.host
|
125
|
+
when String then RestClient::Resource.new("#{url.scheme}://#{url.host}", options)
|
126
|
+
else RestClient::Resource.new("#{API_ENDPOINT.scheme}://#{API_ENDPOINT.host}", options)
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
@@ -128,13 +137,24 @@ class Transloadit::Request
|
|
128
137
|
#
|
129
138
|
def to_payload(payload = nil)
|
130
139
|
return {} if payload.nil?
|
131
|
-
return {} if payload.respond_to?(:empty?)
|
140
|
+
return {} if payload.respond_to?(:empty?) && payload.empty?
|
141
|
+
|
142
|
+
# Create a new hash with JSONified params and a signature if a secret was provided.
|
143
|
+
# Note: We first set :params and :signature to ensure that these are the first fields
|
144
|
+
# in the multipart requests, before any file. Otherwise, a signature will only be transmitted
|
145
|
+
# after all files have been uploaded. The order of the fields in a multipart request
|
146
|
+
# follows the order of the entries in the returned hash here.
|
147
|
+
# See https://github.com/transloadit/ruby-sdk/issues/51
|
148
|
+
new_payload = {
|
149
|
+
params: MultiJson.dump(payload[:params])
|
150
|
+
}
|
151
|
+
sig = signature(new_payload[:params])
|
152
|
+
new_payload[:signature] = sig unless sig.nil?
|
153
|
+
|
154
|
+
# Copy all values, excluding :params and :signature keys.
|
155
|
+
new_payload.update payload.reject { |key, _| key == :params || key == :signature }
|
132
156
|
|
133
|
-
|
134
|
-
payload.update :params => MultiJson.dump(payload[:params])
|
135
|
-
payload.update :signature => self.signature(payload[:params])
|
136
|
-
payload.delete :signature if payload[:signature].nil?
|
137
|
-
payload
|
157
|
+
new_payload
|
138
158
|
end
|
139
159
|
|
140
160
|
#
|
@@ -146,19 +166,18 @@ class Transloadit::Request
|
|
146
166
|
# @return [String] the URI-encoded and escaped query parameters
|
147
167
|
#
|
148
168
|
def to_query(params = nil)
|
149
|
-
return
|
150
|
-
return
|
169
|
+
return "" if params.nil?
|
170
|
+
return "" if params.respond_to?(:empty?) && params.empty?
|
151
171
|
|
152
|
-
escape = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
|
153
172
|
params_in_json = MultiJson.dump(params)
|
154
|
-
uri_params = URI.
|
173
|
+
uri_params = URI.encode_www_form_component(params_in_json)
|
155
174
|
|
156
|
-
params
|
157
|
-
:
|
158
|
-
:
|
175
|
+
params = {
|
176
|
+
params: uri_params,
|
177
|
+
signature: signature(params_in_json)
|
159
178
|
}
|
160
179
|
|
161
|
-
|
180
|
+
"?" + params.map { |k, v| "#{k}=#{v}" if v }.compact.join("&")
|
162
181
|
end
|
163
182
|
|
164
183
|
#
|
@@ -166,7 +185,7 @@ class Transloadit::Request
|
|
166
185
|
# is raised by RestClient.
|
167
186
|
#
|
168
187
|
def request!(&request)
|
169
|
-
Transloadit::Response.new
|
188
|
+
Transloadit::Response.new yield
|
170
189
|
rescue RestClient::Exception => e
|
171
190
|
Transloadit::Response.new e.response
|
172
191
|
end
|
@@ -179,19 +198,6 @@ class Transloadit::Request
|
|
179
198
|
# @return [String] the HMAC signature for the params
|
180
199
|
#
|
181
200
|
def signature(params)
|
182
|
-
self.class._hmac(
|
183
|
-
end
|
184
|
-
|
185
|
-
private
|
186
|
-
|
187
|
-
#
|
188
|
-
# Computes an HMAC digest from the key and message.
|
189
|
-
#
|
190
|
-
# @param [String] key the secret key to sign with
|
191
|
-
# @param [String] message the message to sign
|
192
|
-
# @return [String] the signature of the message
|
193
|
-
#
|
194
|
-
def self._hmac(key, message)
|
195
|
-
OpenSSL::HMAC.hexdigest HMAC_ALGORITHM, key, message
|
201
|
+
self.class._hmac(secret, params) if secret.to_s.length > 0
|
196
202
|
end
|
197
203
|
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
3
|
module Transloadit::Response::Assembly
|
4
4
|
def reload!
|
5
|
-
|
5
|
+
replace Transloadit::Request.new(self["assembly_ssl_url"]).get
|
6
6
|
end
|
7
7
|
|
8
8
|
def cancel!
|
9
|
-
|
9
|
+
replace Transloadit::Request.new(self["assembly_ssl_url"]).delete
|
10
10
|
end
|
11
11
|
|
12
12
|
def aborted?
|
13
|
-
self[
|
13
|
+
self["ok"] == "REQUEST_ABORTED"
|
14
14
|
end
|
15
15
|
|
16
16
|
def canceled?
|
17
|
-
self[
|
17
|
+
self["ok"] == "ASSEMBLY_CANCELED"
|
18
18
|
end
|
19
19
|
|
20
20
|
def completed?
|
21
|
-
self[
|
21
|
+
self["ok"] == "ASSEMBLY_COMPLETED"
|
22
22
|
end
|
23
23
|
|
24
24
|
def error?
|
25
|
-
self[
|
25
|
+
self["error"] != nil
|
26
26
|
end
|
27
27
|
|
28
28
|
def executing?
|
29
|
-
self[
|
29
|
+
self["ok"] == "ASSEMBLY_EXECUTING"
|
30
30
|
end
|
31
31
|
|
32
32
|
def replaying?
|
33
|
-
self[
|
33
|
+
self["ok"] == "ASSEMBLY_REPLAYING"
|
34
34
|
end
|
35
35
|
|
36
36
|
def finished?
|
@@ -38,15 +38,15 @@ module Transloadit::Response::Assembly
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def uploading?
|
41
|
-
self[
|
41
|
+
self["ok"] == "ASSEMBLY_UPLOADING"
|
42
42
|
end
|
43
43
|
|
44
44
|
def rate_limit?
|
45
|
-
self[
|
45
|
+
self["error"] == "RATE_LIMIT_REACHED"
|
46
46
|
end
|
47
47
|
|
48
48
|
def wait_time
|
49
|
-
self[
|
49
|
+
self["info"]["retryIn"] || 0
|
50
50
|
end
|
51
51
|
|
52
52
|
DEFAULT_RELOAD_TRIES = 600
|
@@ -55,7 +55,8 @@ module Transloadit::Response::Assembly
|
|
55
55
|
tries = options[:tries] || DEFAULT_RELOAD_TRIES
|
56
56
|
|
57
57
|
tries.times do
|
58
|
-
sleep 1
|
58
|
+
sleep 1
|
59
|
+
reload!
|
59
60
|
return self if finished?
|
60
61
|
end
|
61
62
|
|
data/lib/transloadit/response.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rest-client"
|
4
|
+
require "delegate"
|
5
5
|
|
6
6
|
class Transloadit::Response < Delegator
|
7
|
-
autoload :Assembly,
|
7
|
+
autoload :Assembly, "transloadit/response/assembly"
|
8
8
|
|
9
9
|
#
|
10
10
|
# Creates an enhanced response wrapped around a RestClient response.
|
@@ -12,7 +12,7 @@ class Transloadit::Response < Delegator
|
|
12
12
|
# @param [RestClient::Response] response the JSON response to wrap
|
13
13
|
#
|
14
14
|
def initialize(response)
|
15
|
-
|
15
|
+
__setobj__(response)
|
16
16
|
end
|
17
17
|
|
18
18
|
#
|
@@ -22,7 +22,7 @@ class Transloadit::Response < Delegator
|
|
22
22
|
# @return [String] the value for the attribute
|
23
23
|
#
|
24
24
|
def [](attribute)
|
25
|
-
|
25
|
+
body[attribute.to_s]
|
26
26
|
end
|
27
27
|
|
28
28
|
#
|
@@ -31,7 +31,7 @@ class Transloadit::Response < Delegator
|
|
31
31
|
# @return [Hash] the parsed JSON body hash
|
32
32
|
#
|
33
33
|
def body
|
34
|
-
MultiJson.load
|
34
|
+
MultiJson.load __getobj__.body
|
35
35
|
end
|
36
36
|
|
37
37
|
#
|
@@ -40,7 +40,7 @@ class Transloadit::Response < Delegator
|
|
40
40
|
# @return [String] a human-readable version of the body
|
41
41
|
#
|
42
42
|
def inspect
|
43
|
-
|
43
|
+
body.inspect
|
44
44
|
end
|
45
45
|
|
46
46
|
#
|
@@ -51,7 +51,7 @@ class Transloadit::Response < Delegator
|
|
51
51
|
# @return [Transloadit::Response] the extended response
|
52
52
|
#
|
53
53
|
def extend!(mod)
|
54
|
-
|
54
|
+
extend(mod)
|
55
55
|
self
|
56
56
|
end
|
57
57
|
|
@@ -84,7 +84,7 @@ class Transloadit::Response < Delegator
|
|
84
84
|
# @return [Transloadit::Response] this response
|
85
85
|
#
|
86
86
|
def replace(other)
|
87
|
-
|
87
|
+
__setobj__ other.__getobj__
|
88
88
|
self
|
89
89
|
end
|
90
90
|
end
|
data/lib/transloadit/step.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
3
|
#
|
4
4
|
# Implements the concept of a step in the Transloadit API. Each Step has a
|
5
5
|
# +robot+ (e.g., '/image/resize' or '/video/thumbnail') and a hash of
|
6
6
|
# +options+ specific to the chosen robot.
|
7
7
|
#
|
8
|
-
# See the Transloadit {documentation}[
|
8
|
+
# See the Transloadit {documentation}[https://transloadit.com/docs/building-assembly-instructions]
|
9
9
|
# for futher information on robot types and their parameters.
|
10
10
|
#
|
11
11
|
class Transloadit::Step
|
@@ -27,8 +27,8 @@ class Transloadit::Step
|
|
27
27
|
# {Transloadit#step} for possible values
|
28
28
|
#
|
29
29
|
def initialize(name, robot, options = {})
|
30
|
-
self.name
|
31
|
-
self.robot
|
30
|
+
self.name = name
|
31
|
+
self.robot = robot
|
32
32
|
self.options = options
|
33
33
|
end
|
34
34
|
|
@@ -38,7 +38,7 @@ class Transloadit::Step
|
|
38
38
|
#
|
39
39
|
# @param [Step, Array<Step>, Symbol, nil] input The input
|
40
40
|
# step to use. Follows the conventions outlined in the
|
41
|
-
# online {documentation}[
|
41
|
+
# online {documentation}[https://transloadit.com/docs/building-assembly-instructions#special-parameters].
|
42
42
|
# The symbol +:original+ specifies that the original file should be sent
|
43
43
|
# to the robot. A Step indicates that this Step's output should be used
|
44
44
|
# as the input to this one. Likewise, an array of Steps tells Transloadit
|
@@ -49,12 +49,12 @@ class Transloadit::Step
|
|
49
49
|
# that will actually be sent to the REST API.
|
50
50
|
#
|
51
51
|
def use(input)
|
52
|
-
|
52
|
+
options.delete(:use) && return if input.nil?
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
options[:use] = case input
|
55
|
+
when Symbol then input.inspect
|
56
|
+
when Array then input.map { |i| i.name }
|
57
|
+
else [input.name]
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,21 +62,21 @@ class Transloadit::Step
|
|
62
62
|
# @return [String] a human-readable version of the Step
|
63
63
|
#
|
64
64
|
def inspect
|
65
|
-
|
65
|
+
to_hash[name].inspect
|
66
66
|
end
|
67
67
|
|
68
68
|
#
|
69
69
|
# @return [Hash] a Transloadit-compatible Hash of the Step's contents
|
70
70
|
#
|
71
71
|
def to_hash
|
72
|
-
{
|
72
|
+
{name => options.merge(robot: robot)}
|
73
73
|
end
|
74
74
|
|
75
75
|
#
|
76
76
|
# @return [String] JSON-encoded String containing the Step's hash contents
|
77
77
|
#
|
78
78
|
def to_json
|
79
|
-
MultiJson.dump(
|
79
|
+
MultiJson.dump(to_hash)
|
80
80
|
end
|
81
81
|
|
82
82
|
protected
|
data/lib/transloadit/template.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "transloadit"
|
2
2
|
|
3
3
|
#
|
4
4
|
# Represents a Template API ready to interact with its corresponding REST API.
|
@@ -18,7 +18,7 @@ class Transloadit::Template < Transloadit::ApiModel
|
|
18
18
|
# see {template}[https://transloadit.com/templates]
|
19
19
|
#
|
20
20
|
def create(params)
|
21
|
-
_do_request(
|
21
|
+
_do_request("/templates", params, "post")
|
22
22
|
end
|
23
23
|
|
24
24
|
#
|
@@ -26,7 +26,7 @@ class Transloadit::Template < Transloadit::ApiModel
|
|
26
26
|
# @param [Hash] additional GET data to submit with the request
|
27
27
|
#
|
28
28
|
def list(params = {})
|
29
|
-
_do_request(
|
29
|
+
_do_request("/templates", params)
|
30
30
|
end
|
31
31
|
|
32
32
|
#
|
@@ -49,7 +49,7 @@ class Transloadit::Template < Transloadit::ApiModel
|
|
49
49
|
# see {template}[https://transloadit.com/templates]
|
50
50
|
#
|
51
51
|
def update(id, params = {})
|
52
|
-
_do_request("/templates/#{id}", params,
|
52
|
+
_do_request("/templates/#{id}", params, "put")
|
53
53
|
end
|
54
54
|
|
55
55
|
#
|
@@ -58,6 +58,6 @@ class Transloadit::Template < Transloadit::ApiModel
|
|
58
58
|
# @param [Hash] additional POST data to submit with the request
|
59
59
|
#
|
60
60
|
def delete(id, params = {})
|
61
|
-
_do_request("/templates/#{id}", params,
|
61
|
+
_do_request("/templates/#{id}", params, "delete")
|
62
62
|
end
|
63
63
|
end
|
data/lib/transloadit/version.rb
CHANGED