transloadit 0.1.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/lib/transloadit/assembly.rb +8 -2
- data/lib/transloadit/request.rb +100 -8
- data/lib/transloadit/response/assembly.rb +1 -1
- data/lib/transloadit/response.rb +50 -3
- data/lib/transloadit/step.rb +6 -13
- data/lib/transloadit/version.rb +1 -1
- data/lib/transloadit.rb +3 -2
- data/test/fixtures/cassettes/cancel_assembly.yml +30 -0
- data/test/fixtures/cassettes/fetch_assembly.yml +28 -0
- data/test/fixtures/cassettes/fetch_bored.yml +63 -0
- data/test/fixtures/cassettes/post_assembly.yml +36 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/test_transloadit.rb +6 -5
- data/test/unit/transloadit/test_assembly.rb +3 -3
- data/test/unit/transloadit/test_request.rb +51 -1
- data/test/unit/transloadit/test_response.rb +64 -1
- data/test/unit/transloadit/test_step.rb +10 -16
- metadata +10 -2
data/README.md
CHANGED
@@ -35,11 +35,11 @@ and store the result on [Amazon S3](http://aws.amazon.com/s3/).
|
|
35
35
|
First, we create two steps: one to resize the image to 320x240, and another to
|
36
36
|
store the image in our S3 bucket.
|
37
37
|
|
38
|
-
resize = transloadit.step '/image/resize',
|
38
|
+
resize = transloadit.step 'resize', '/image/resize',
|
39
39
|
width: 320,
|
40
40
|
height: 240
|
41
41
|
|
42
|
-
store = transloadit.step '/s3/store',
|
42
|
+
store = transloadit.step 'store', '/s3/store',
|
43
43
|
key: 'aws-access-key-id',
|
44
44
|
secret: 'aws-secret-access-key',
|
45
45
|
bucket: 's3-bucket-name'
|
@@ -108,9 +108,9 @@ Transloadit allows you to perform several processing steps in parallel. You
|
|
108
108
|
simply need to `use` other steps. Following
|
109
109
|
[their example](http://transloadit.com/docs/assemblies#special-parameters):
|
110
110
|
|
111
|
-
encode = transloadit.step '/video/encode', { ... }
|
112
|
-
thumbs = transloadit.step '/video/thumbs', { ... }
|
113
|
-
export = transloadit.step '/s3/store', { ... }
|
111
|
+
encode = transloadit.step 'encode', '/video/encode', { ... }
|
112
|
+
thumbs = transloadit.step 'thumbs', '/video/thumbs', { ... }
|
113
|
+
export = transloadit.step 'store', '/s3/store', { ... }
|
114
114
|
|
115
115
|
export.use [ encode, thumbs ]
|
116
116
|
|
data/lib/transloadit/assembly.rb
CHANGED
@@ -50,14 +50,20 @@ class Transloadit::Assembly
|
|
50
50
|
# @param [Hash] params additional POST data to submit with the request
|
51
51
|
#
|
52
52
|
def submit!(*ios)
|
53
|
-
params = _extract_options!(
|
53
|
+
params = _extract_options!(ios)
|
54
54
|
payload = { :params => self.to_hash.update(params) }
|
55
55
|
|
56
|
+
# update the payload with file entries
|
56
57
|
ios.each_with_index {|f, i| payload.update :"file_#{i}" => f }
|
57
58
|
|
59
|
+
# find a bored instance
|
60
|
+
Transloadit::Request.bored!
|
61
|
+
|
62
|
+
# create the request
|
58
63
|
request = Transloadit::Request.new '/assemblies',
|
59
64
|
self.transloadit.secret
|
60
65
|
|
66
|
+
# post the request, extend it with the Assembly extensions
|
61
67
|
request.post(payload).extend!(Transloadit::Response::Assembly)
|
62
68
|
end
|
63
69
|
|
@@ -115,7 +121,7 @@ class Transloadit::Assembly
|
|
115
121
|
# @param *args the arguments to search for an options hash
|
116
122
|
# @return [Hash] the options passed, otherwise an empty hash
|
117
123
|
#
|
118
|
-
def _extract_options!(
|
124
|
+
def _extract_options!(args)
|
119
125
|
args.last.is_a?(Hash) ? args.pop : {}
|
120
126
|
end
|
121
127
|
end
|
data/lib/transloadit/request.rb
CHANGED
@@ -24,33 +24,70 @@ class Transloadit::Request
|
|
24
24
|
# @return [String] the authentication secret to sign the request with
|
25
25
|
attr_accessor :secret
|
26
26
|
|
27
|
+
#
|
28
|
+
# Automatically sets the API endpoint to the server with the most free
|
29
|
+
# resources. This is called automatically the first time a request is made.
|
30
|
+
#
|
27
31
|
def self.bored!
|
28
|
-
self.api
|
32
|
+
self.api self.bored
|
29
33
|
end
|
30
34
|
|
35
|
+
#
|
36
|
+
# Prepares a request against an endpoint URL, optionally with an encryption
|
37
|
+
# secret. If only a path is passed, the API will automatically determine the
|
38
|
+
# best server to use. If a full URL is given, the host provided will be
|
39
|
+
# used.
|
40
|
+
#
|
41
|
+
# @param [String] url the API endpoint
|
42
|
+
# @param [String] secret an optional secret with which to sign the request
|
43
|
+
#
|
31
44
|
def initialize(url, secret = nil)
|
32
45
|
self.url = URI.parse(url.to_s)
|
33
46
|
self.secret = secret
|
34
47
|
end
|
35
48
|
|
49
|
+
#
|
50
|
+
# Performs an HTTP GET to the request's URL. Takes an optional hash of
|
51
|
+
# query params.
|
52
|
+
#
|
53
|
+
# @param [Hash] params additional query parameters
|
54
|
+
# @return [Transloadit::Response] the response
|
55
|
+
#
|
36
56
|
def get(params = {})
|
37
57
|
self.request! do
|
38
58
|
self.api[url.path + self.to_query(params)].get(API_HEADERS)
|
39
59
|
end
|
40
60
|
end
|
41
61
|
|
62
|
+
#
|
63
|
+
# Performs an HTTP DELETE to the request's URL. Takes an optional hash of
|
64
|
+
# query params.
|
65
|
+
#
|
66
|
+
# @param [Hash] params additional query parameters
|
67
|
+
# @return [Transloadit::Response] the response
|
68
|
+
#
|
42
69
|
def delete(params = {})
|
43
70
|
self.request! do
|
44
71
|
self.api[url.path + self.to_query(params)].delete(API_HEADERS)
|
45
72
|
end
|
46
73
|
end
|
47
74
|
|
75
|
+
#
|
76
|
+
# Performs an HTTP POST to the request's URL. Takes an optional hash
|
77
|
+
# containing the form-encoded payload.
|
78
|
+
#
|
79
|
+
# @param [Hash] payload the payload to form-encode along with the POST
|
80
|
+
# @return [Transloadit::Response] the response
|
81
|
+
#
|
48
82
|
def post(payload = {})
|
49
83
|
self.request! do
|
50
84
|
self.api[url.path].post(self.to_payload(payload), API_HEADERS)
|
51
85
|
end
|
52
86
|
end
|
53
87
|
|
88
|
+
#
|
89
|
+
# @return [String] a human-readable version of the prepared Request
|
90
|
+
#
|
54
91
|
def inspect
|
55
92
|
self.url.to_s.inspect
|
56
93
|
end
|
@@ -59,15 +96,37 @@ class Transloadit::Request
|
|
59
96
|
|
60
97
|
attr_writer :url
|
61
98
|
|
99
|
+
#
|
100
|
+
# Locates the API server with the smallest job queue.
|
101
|
+
#
|
102
|
+
# @return [String] the hostname of the most bored server
|
103
|
+
#
|
62
104
|
def self.bored
|
63
105
|
self.new(API_ENDPOINT + '/instances/bored').get['api2_host']
|
64
106
|
end
|
65
107
|
|
108
|
+
#
|
109
|
+
# Sets or retrieves the base URI of the API endpoint.
|
110
|
+
#
|
111
|
+
# @overload self.api
|
112
|
+
# @return [RestClient::Resource] the current API endpoint
|
113
|
+
#
|
114
|
+
# @overload self.api(uri)
|
115
|
+
# @param [String] the hostname or URI to set the API endpoint to
|
116
|
+
# @return [RestClient::Resource] the new API endpoint
|
117
|
+
#
|
66
118
|
def self.api(uri = nil)
|
67
119
|
@api = RestClient::Resource.new(uri) if uri
|
68
120
|
@api ||= RestClient::Resource.new(self.bored)
|
69
121
|
end
|
70
122
|
|
123
|
+
#
|
124
|
+
# Retrieves the current API endpoint. If the URL of the request contains a
|
125
|
+
# hostname, then the hostname is used as the base endpoint of the API.
|
126
|
+
# Otherwise uses the class-level API base.
|
127
|
+
#
|
128
|
+
# @return [RestClient::Resource] the API endpoint for this instance
|
129
|
+
#
|
71
130
|
def api
|
72
131
|
@api ||= begin
|
73
132
|
case self.url.host
|
@@ -77,6 +136,14 @@ class Transloadit::Request
|
|
77
136
|
end
|
78
137
|
end
|
79
138
|
|
139
|
+
#
|
140
|
+
# Updates the POST payload passed to be compliant with the Transloadit API
|
141
|
+
# spec. JSONifies the value for the +params+ key and signs the request with
|
142
|
+
# the instance's +secret+ if it exists.
|
143
|
+
#
|
144
|
+
# @param [Hash] the payload to update
|
145
|
+
# @return [Hash] the Transloadit-compliant POST payload
|
146
|
+
#
|
80
147
|
def to_payload(payload = nil)
|
81
148
|
return {} if payload.nil?
|
82
149
|
return {} if payload.respond_to?(:empty?) and payload.empty?
|
@@ -88,32 +155,57 @@ class Transloadit::Request
|
|
88
155
|
payload
|
89
156
|
end
|
90
157
|
|
158
|
+
#
|
159
|
+
# Updates the GET/DELETE params hash to be compliant with the Transloadit
|
160
|
+
# API by URI escaping and encoding the params hash, and attaching a
|
161
|
+
# signature.
|
162
|
+
#
|
163
|
+
# @param [Hash] params the params to encode
|
164
|
+
# @return [String] the URI-encoded and escaped query parameters
|
165
|
+
#
|
91
166
|
def to_query(params = nil)
|
92
167
|
return '' if params.nil?
|
93
168
|
return '' if params.respond_to?(:empty?) and params.empty?
|
94
169
|
|
95
|
-
escape
|
96
|
-
params
|
170
|
+
escape = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
|
171
|
+
params = {
|
172
|
+
:params => URI.escape(params.to_json, escape),
|
173
|
+
:signature => self.signature(params)
|
174
|
+
}
|
97
175
|
|
98
|
-
|
99
|
-
'?' + self.to_hash.
|
100
|
-
update(:params => params).
|
101
|
-
map {|k,v| "#{k}=#{v}" }.
|
102
|
-
join('&')
|
176
|
+
'?' + params.map {|k,v| "#{k}=#{v}" if v }.compact.join('&')
|
103
177
|
end
|
104
178
|
|
179
|
+
#
|
180
|
+
# Wraps a request's results in a Transloadit::Response, even if an exception
|
181
|
+
# is raised by RestClient.
|
182
|
+
#
|
105
183
|
def request!(&request)
|
106
184
|
Transloadit::Response.new request.call
|
107
185
|
rescue RestClient::Exception => e
|
108
186
|
Transloadit::Response.new e.response
|
109
187
|
end
|
110
188
|
|
189
|
+
#
|
190
|
+
# Computes the HMAC digest of the params hash, if a secret was given to the
|
191
|
+
# instance.
|
192
|
+
#
|
193
|
+
# @param [Hash] params the payload to sign
|
194
|
+
# @return [String] the HMAC signature for the params
|
195
|
+
#
|
111
196
|
def signature(params)
|
112
197
|
self.class._hmac(self.secret, params.to_json) if self.secret
|
113
198
|
end
|
114
199
|
|
115
200
|
private
|
116
201
|
|
202
|
+
#
|
203
|
+
# Computes an HMAC digest from the key and message.
|
204
|
+
#
|
205
|
+
# @param [String] key the secret key to sign with
|
206
|
+
# @param [String] message the message to sign
|
207
|
+
# @return [String] the signature of the message
|
208
|
+
#
|
117
209
|
def self._hmac(key, message)
|
118
210
|
OpenSSL::HMAC.hexdigest HMAC_ALGORITHM, key, message
|
119
211
|
end
|
data/lib/transloadit/response.rb
CHANGED
@@ -1,27 +1,55 @@
|
|
1
1
|
require 'transloadit'
|
2
|
+
|
3
|
+
require 'rest-client'
|
2
4
|
require 'delegate'
|
3
5
|
|
4
6
|
class Transloadit::Response < Delegator
|
5
7
|
autoload :Assembly, 'transloadit/response/assembly'
|
6
8
|
|
7
|
-
|
9
|
+
#
|
10
|
+
# Creates an enhanced response wrapped around a RestClient response.
|
11
|
+
#
|
12
|
+
# @param [RestClient::Response] response the JSON response to wrap
|
13
|
+
#
|
14
|
+
def initialize(response)
|
8
15
|
self.__setobj__(response)
|
9
|
-
|
10
|
-
instance_eval(&extension) if block_given?
|
11
16
|
end
|
12
17
|
|
18
|
+
#
|
19
|
+
# Returns the attribute from the JSON response.
|
20
|
+
#
|
21
|
+
# @param [String] attribute the attribute name to look up
|
22
|
+
# @return [String] the value for the attribute
|
23
|
+
#
|
13
24
|
def [](attribute)
|
14
25
|
self.body[attribute]
|
15
26
|
end
|
16
27
|
|
28
|
+
#
|
29
|
+
# Returns the parsed JSON body.
|
30
|
+
#
|
31
|
+
# @return [Hash] the parsed JSON body hash
|
32
|
+
#
|
17
33
|
def body
|
18
34
|
JSON.parse self.__getobj__.body
|
19
35
|
end
|
20
36
|
|
37
|
+
#
|
38
|
+
# Inspects the body of the response.
|
39
|
+
#
|
40
|
+
# @return [String] a human-readable version of the body
|
41
|
+
#
|
21
42
|
def inspect
|
22
43
|
self.body.inspect
|
23
44
|
end
|
24
45
|
|
46
|
+
#
|
47
|
+
# Chainably extends the response with additional methods. Used to add
|
48
|
+
# context-specific functionality to a response.
|
49
|
+
#
|
50
|
+
# @param [Module] mod the module to extend with
|
51
|
+
# @return [Transloadit::Response] the extended response
|
52
|
+
#
|
25
53
|
def extend!(mod)
|
26
54
|
self.extend(mod)
|
27
55
|
self
|
@@ -29,15 +57,34 @@ class Transloadit::Response < Delegator
|
|
29
57
|
|
30
58
|
protected
|
31
59
|
|
60
|
+
#
|
61
|
+
# The object to delegate method calls to.
|
62
|
+
#
|
63
|
+
# @return [RestClient::Response]
|
64
|
+
#
|
32
65
|
def __getobj__
|
33
66
|
@response
|
34
67
|
end
|
35
68
|
|
69
|
+
#
|
70
|
+
# Sets the object to delegate method calls to.
|
71
|
+
#
|
72
|
+
# @param [RestClient::Response] response the response to delegate to
|
73
|
+
# @return [RestClient::Response] the delegated response
|
74
|
+
#
|
36
75
|
def __setobj__(response)
|
37
76
|
@response = response
|
38
77
|
end
|
39
78
|
|
79
|
+
#
|
80
|
+
# Replaces the object this instance delegates to with the one the other
|
81
|
+
# object uses.
|
82
|
+
#
|
83
|
+
# @param [Delegator] other the object whose delegate to use
|
84
|
+
# @return [Transloadit::Response] this response
|
85
|
+
#
|
40
86
|
def replace(other)
|
41
87
|
self.__setobj__ other.__getobj__
|
88
|
+
self
|
42
89
|
end
|
43
90
|
end
|
data/lib/transloadit/step.rb
CHANGED
@@ -9,6 +9,9 @@ require 'transloadit'
|
|
9
9
|
# for futher information on robot types and their parameters.
|
10
10
|
#
|
11
11
|
class Transloadit::Step
|
12
|
+
# @return [String] the name to give the step
|
13
|
+
attr_accessor :name
|
14
|
+
|
12
15
|
# @return [String] the robot to use
|
13
16
|
attr_reader :robot
|
14
17
|
|
@@ -18,27 +21,17 @@ class Transloadit::Step
|
|
18
21
|
#
|
19
22
|
# Creates a new Step with the given +robot+.
|
20
23
|
#
|
24
|
+
# @param [String] name the explicit name to give the step
|
21
25
|
# @param [String] robot the robot to use
|
22
26
|
# @param [Hash] options the configuration options for the robot; see
|
23
27
|
# {Transloadit#step} for possible values
|
24
28
|
#
|
25
|
-
def initialize(robot, options = {})
|
29
|
+
def initialize(name, robot, options = {})
|
30
|
+
self.name = name
|
26
31
|
self.robot = robot
|
27
32
|
self.options = options
|
28
33
|
end
|
29
34
|
|
30
|
-
#
|
31
|
-
# Automatically generates a unique, 32-character hex name for the step that
|
32
|
-
# uses this robot.
|
33
|
-
#
|
34
|
-
# @return [String] a randomly generated name
|
35
|
-
#
|
36
|
-
def name
|
37
|
-
# rand() is "good enough" for this; we generate 128 random bits (same
|
38
|
-
# length as a UUID for future compatibility) and convert it to hex
|
39
|
-
@name ||= rand(2 ** 128).to_s(16).rjust(32, '0')
|
40
|
-
end
|
41
|
-
|
42
35
|
#
|
43
36
|
# Specifies that this Step should process the provided +input+ instead of
|
44
37
|
# the output of the Step before it.
|
data/lib/transloadit/version.rb
CHANGED
data/lib/transloadit.rb
CHANGED
@@ -38,14 +38,15 @@ class Transloadit
|
|
38
38
|
#
|
39
39
|
# Creates a Transloadit::Step describing a step in an upload assembly.
|
40
40
|
#
|
41
|
+
# @param [String] name the name to give the step
|
41
42
|
# @param [String] robot the robot to use in this step (e.g., '/image/resize')
|
42
43
|
# @param [Hash] options a hash of options to customize the robot's
|
43
44
|
# operation; see the {online documentation}[http://transloadit.com/docs/building-assembly-instructions]
|
44
45
|
# for robot-specific options
|
45
46
|
# @return [Step] the created Step
|
46
47
|
#
|
47
|
-
def step(robot, options = {})
|
48
|
-
Transloadit::Step.new(robot, options)
|
48
|
+
def step(name, robot, options = {})
|
49
|
+
Transloadit::Step.new(name, robot, options)
|
49
50
|
end
|
50
51
|
|
51
52
|
#
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :delete
|
5
|
+
uri: http://api2.jane.transloadit.com:80/assemblies/76fe5df1c93a0a530f3e583805cf98b4
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- "*/*; q=0.5, application/xml"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
user-agent:
|
13
|
+
- Transloadit Ruby SDK 0.1.2
|
14
|
+
response: !ruby/struct:VCR::Response
|
15
|
+
status: !ruby/struct:VCR::ResponseStatus
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
content-type:
|
20
|
+
- text/plain
|
21
|
+
access-control-allow-origin:
|
22
|
+
- "*"
|
23
|
+
access-control-allow-methods:
|
24
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
25
|
+
access-control-allow-headers:
|
26
|
+
- X-Requested-With, Content-Type, Accept, Content-Length
|
27
|
+
transfer-encoding:
|
28
|
+
- chunked
|
29
|
+
body: "{\"ok\":\"ASSEMBLY_CANCELED\",\"message\":\"The assembly was canceled.\",\"assembly_id\":\"76fe5df1c93a0a530f3e583805cf98b4\",\"assembly_url\":\"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4\",\"bytes_received\":95355,\"bytes_expected\":95355,\"client_agent\":\"Transloadit Ruby SDK 0.1.2\",\"client_ip\":\"74.95.29.209\",\"client_referer\":null,\"start_date\":\"2011/02/21 15:54:17 GMT\",\"upload_duration\":0.394,\"execution_duration\":0.006,\"fields\":{},\"uploads\":[{\"id\":\"0767b43537389a177a1be96ab06e8a4b\",\"name\":\"test.png\",\"basename\":\"test\",\"ext\":\"png\",\"size\":95010,\"mime\":\"image/jpeg\",\"type\":\"image\",\"field\":\"file_0\",\"original_id\":\"0767b43537389a177a1be96ab06e8a4b\",\"url\":\"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png\",\"meta\":{\"width\":640,\"height\":480,\"date_recorded\":null,\"date_file_created\":null,\"date_file_modified\":\"2011/02/21 15:54:17 GMT\",\"title\":null,\"description\":null,\"location\":null,\"city\":null,\"state\":null,\"country\":null,\"country_code\":null,\"keywords\":\"Photo Booth\",\"aperture\":null,\"exposure_compensation\":null,\"exposure_mode\":null,\"exposure_time\":null,\"flash\":null,\"focal_length\":null,\"f_number\":null,\"iso\":null,\"light_value\":null,\"metering_mode\":null,\"shutter_speed\":null,\"white_balance\":null,\"device_name\":null,\"device_vendor\":null,\"device_software\":null,\"latitude\":null,\"longitude\":null,\"frame_count\":null}}],\"results\":{}}"
|
30
|
+
http_version: "1.1"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api2.jane.transloadit.com:80/assemblies/76fe5df1c93a0a530f3e583805cf98b4
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- "*/*; q=0.5, application/xml"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
content-type:
|
18
|
+
- text/plain
|
19
|
+
access-control-allow-origin:
|
20
|
+
- "*"
|
21
|
+
access-control-allow-methods:
|
22
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
23
|
+
access-control-allow-headers:
|
24
|
+
- X-Requested-With, Content-Type, Accept, Content-Length
|
25
|
+
transfer-encoding:
|
26
|
+
- chunked
|
27
|
+
body: "{\"ok\":\"ASSEMBLY_COMPLETED\",\"message\":\"The assembly was successfully completed.\",\"assembly_id\":\"76fe5df1c93a0a530f3e583805cf98b4\",\"assembly_url\":\"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4\",\"bytes_received\":95355,\"bytes_expected\":95355,\"client_agent\":\"Transloadit Ruby SDK 0.1.2\",\"client_ip\":\"74.95.29.209\",\"client_referer\":null,\"start_date\":\"2011/02/21 15:54:17 GMT\",\"upload_duration\":0.394,\"execution_duration\":0.006,\"fields\":{},\"uploads\":[{\"id\":\"0767b43537389a177a1be96ab06e8a4b\",\"name\":\"test.png\",\"basename\":\"test\",\"ext\":\"png\",\"size\":95010,\"mime\":\"image/jpeg\",\"type\":\"image\",\"field\":\"file_0\",\"original_id\":\"0767b43537389a177a1be96ab06e8a4b\",\"url\":\"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png\",\"meta\":{\"width\":640,\"height\":480,\"date_recorded\":null,\"date_file_created\":null,\"date_file_modified\":\"2011/02/21 15:54:17 GMT\",\"title\":null,\"description\":null,\"location\":null,\"city\":null,\"state\":null,\"country\":null,\"country_code\":null,\"keywords\":\"Photo Booth\",\"aperture\":null,\"exposure_compensation\":null,\"exposure_mode\":null,\"exposure_time\":null,\"flash\":null,\"focal_length\":null,\"f_number\":null,\"iso\":null,\"light_value\":null,\"metering_mode\":null,\"shutter_speed\":null,\"white_balance\":null,\"device_name\":null,\"device_vendor\":null,\"device_software\":null,\"latitude\":null,\"longitude\":null,\"frame_count\":null}}],\"results\":{}}"
|
28
|
+
http_version: "1.1"
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api2.transloadit.com:80/instances/bored
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- "*/*; q=0.5, application/xml"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
user-agent:
|
13
|
+
- Transloadit Ruby SDK 0.1.2
|
14
|
+
response: !ruby/struct:VCR::Response
|
15
|
+
status: !ruby/struct:VCR::ResponseStatus
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
access-control-allow-headers:
|
20
|
+
- X-Requested-With, Content-Type, Accept, Content-Length
|
21
|
+
access-control-allow-methods:
|
22
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
23
|
+
access-control-allow-origin:
|
24
|
+
- "*"
|
25
|
+
content-type:
|
26
|
+
- text/plain
|
27
|
+
content-length:
|
28
|
+
- "94"
|
29
|
+
connection:
|
30
|
+
- keep-alive
|
31
|
+
body: "{\"ok\":\"BORED_INSTANCE_FOUND\",\"host\":\"jane.transloadit.com\",\"api2_host\":\"jane.transloadit.com\"}"
|
32
|
+
http_version: "1.1"
|
33
|
+
- !ruby/struct:VCR::HTTPInteraction
|
34
|
+
request: !ruby/struct:VCR::Request
|
35
|
+
method: :get
|
36
|
+
uri: http://api2.transloadit.com:80/instances/bored?params=%7B%22params%22:%7B%22foo%22:%22bar%22%7D%7D
|
37
|
+
body:
|
38
|
+
headers:
|
39
|
+
accept:
|
40
|
+
- "*/*; q=0.5, application/xml"
|
41
|
+
accept-encoding:
|
42
|
+
- gzip, deflate
|
43
|
+
user-agent:
|
44
|
+
- Transloadit Ruby SDK 0.1.2
|
45
|
+
response: !ruby/struct:VCR::Response
|
46
|
+
status: !ruby/struct:VCR::ResponseStatus
|
47
|
+
code: 200
|
48
|
+
message: OK
|
49
|
+
headers:
|
50
|
+
access-control-allow-headers:
|
51
|
+
- X-Requested-With, Content-Type, Accept, Content-Length
|
52
|
+
access-control-allow-methods:
|
53
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
54
|
+
access-control-allow-origin:
|
55
|
+
- "*"
|
56
|
+
content-type:
|
57
|
+
- text/plain
|
58
|
+
content-length:
|
59
|
+
- "94"
|
60
|
+
connection:
|
61
|
+
- keep-alive
|
62
|
+
body: "{\"ok\":\"BORED_INSTANCE_FOUND\",\"host\":\"jane.transloadit.com\",\"api2_host\":\"jane.transloadit.com\"}"
|
63
|
+
http_version: "1.1"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: http://api2.transloadit.com:80/assemblies
|
6
|
+
body: params=%7B%22auth%22%3A%7B%22key%22%3A%22%22%2C%22expires%22%3A%222011%2F02%2F21%2023%3A15%3A43%2B00%3A00%22%7D%2C%22steps%22%3A%7B%22encode%22%3A%7B%22robot%22%3A%22%2Fvideo%2Fencode%22%7D%7D%7D&signature=d1a856e3d04103da448a512070139d3e721594cc
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- "*/*; q=0.5, application/xml"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
user-agent:
|
13
|
+
- Transloadit Ruby SDK 0.1.2
|
14
|
+
content-length:
|
15
|
+
- "278"
|
16
|
+
content-type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
response: !ruby/struct:VCR::Response
|
19
|
+
status: !ruby/struct:VCR::ResponseStatus
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
access-control-allow-headers:
|
24
|
+
- X-Requested-With, Content-Type, Accept, Content-Length
|
25
|
+
access-control-allow-methods:
|
26
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
27
|
+
access-control-allow-origin:
|
28
|
+
- "*"
|
29
|
+
content-type:
|
30
|
+
- text/plain
|
31
|
+
content-length:
|
32
|
+
- "482"
|
33
|
+
connection:
|
34
|
+
- keep-alive
|
35
|
+
body: "{\"ok\":\"ASSEMBLY_COMPLETED\",\"message\":\"The assembly was successfully completed.\",\"assembly_id\":\"2a4cb778995be35ffe5fcda3c01e4267\",\"assembly_url\":\"http://api2.jane.transloadit.com/assemblies/2a4cb778995be35ffe5fcda3c01e4267\",\"bytes_received\":278,\"bytes_expected\":278,\"client_agent\":\"Transloadit Ruby SDK 0.1.2\",\"client_ip\":\"74.95.29.209\",\"client_referer\":null,\"start_date\":\"2011/02/21 23:15:33 GMT\",\"upload_duration\":0.094,\"execution_duration\":0,\"fields\":{},\"uploads\":[],\"results\":{}}"
|
36
|
+
http_version: "1.1"
|
data/test/test_helper.rb
CHANGED
@@ -41,15 +41,16 @@ describe Transloadit do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'must create steps' do
|
44
|
-
step = @transloadit.step('/image/resize', :width => 320)
|
45
|
-
|
44
|
+
step = @transloadit.step('resize', '/image/resize', :width => 320)
|
45
|
+
|
46
46
|
step.must_be_kind_of Transloadit::Step
|
47
|
+
step.name. must_equal 'resize'
|
47
48
|
step.robot. must_equal '/image/resize'
|
48
49
|
step.options.must_equal :width => 320
|
49
50
|
end
|
50
51
|
|
51
52
|
it 'must create assemblies' do
|
52
|
-
step = @transloadit.step(
|
53
|
+
step = @transloadit.step(nil, nil)
|
53
54
|
assembly = @transloadit.assembly :steps => step
|
54
55
|
|
55
56
|
assembly.must_be_kind_of Transloadit::Assembly
|
@@ -58,8 +59,8 @@ describe Transloadit do
|
|
58
59
|
|
59
60
|
it 'must create assemblies with multiple steps' do
|
60
61
|
steps = [
|
61
|
-
@transloadit.step(
|
62
|
-
@transloadit.step(
|
62
|
+
@transloadit.step(nil, nil),
|
63
|
+
@transloadit.step(nil, nil),
|
63
64
|
]
|
64
65
|
|
65
66
|
assembly = @transloadit.assembly :steps => steps
|
@@ -12,7 +12,7 @@ describe Transloadit::Assembly do
|
|
12
12
|
|
13
13
|
describe 'when initialized' do
|
14
14
|
before do
|
15
|
-
@step = @transloadit.step '/video/thumbs'
|
15
|
+
@step = @transloadit.step 'thumbs', '/video/thumbs'
|
16
16
|
@redirect = 'http://foo.bar/'
|
17
17
|
|
18
18
|
@assembly = Transloadit::Assembly.new @transloadit,
|
@@ -72,8 +72,8 @@ describe Transloadit::Assembly do
|
|
72
72
|
|
73
73
|
describe 'with multiple steps' do
|
74
74
|
before do
|
75
|
-
@encode = @transloadit.step '/video/encode'
|
76
|
-
@thumbs = @transloadit.step '/video/thumbs'
|
75
|
+
@encode = @transloadit.step 'encode', '/video/encode'
|
76
|
+
@thumbs = @transloadit.step 'thumbs', '/video/thumbs'
|
77
77
|
|
78
78
|
@assembly = Transloadit::Assembly.new @transloadit,
|
79
79
|
:steps => [ @encode, @thumbs ]
|
@@ -1,5 +1,55 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe Transloadit::Request do
|
4
|
-
|
4
|
+
REQUEST_URI = 'http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4'
|
5
|
+
|
6
|
+
before do
|
7
|
+
# reset the API endpoint between tests
|
8
|
+
Transloadit::Request.api Transloadit::Request::API_ENDPOINT
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must allow initialization' do
|
12
|
+
request = Transloadit::Request.new '/'
|
13
|
+
request.must_be_kind_of Transloadit::Request
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'must locate bored instances' do
|
17
|
+
VCR.use_cassette 'fetch_bored' do
|
18
|
+
Transloadit::Request.bored!.
|
19
|
+
wont_equal Transloadit::Request::API_ENDPOINT.host
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'when performing a GET' do
|
24
|
+
before do
|
25
|
+
@request = Transloadit::Request.new('instances/bored')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'must inspect to the API URL' do
|
29
|
+
@request.inspect.must_equal @request.url.to_s.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'must perform a GET against the resource' do
|
33
|
+
VCR.use_cassette 'fetch_bored' do
|
34
|
+
@request.get(:params => { :foo => 'bar'})['ok'].
|
35
|
+
must_equal 'BORED_INSTANCE_FOUND'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when performing a POST' do
|
41
|
+
before do
|
42
|
+
@request = Transloadit::Request.new('assemblies', '')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'must perform a POST against the resource' do
|
46
|
+
VCR.use_cassette 'post_assembly' do
|
47
|
+
@request.post(:params => {
|
48
|
+
:auth => { :key => '',
|
49
|
+
:expires => (Time.now + 10).utc.strftime('%Y/%m/%d %H:%M:%S+00:00') },
|
50
|
+
:steps => { :encode => { :robot => '/video/encode' } }
|
51
|
+
})['ok'].must_equal 'ASSEMBLY_COMPLETED'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
5
55
|
end
|
@@ -1,5 +1,68 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe Transloadit::Response do
|
4
|
-
|
4
|
+
REQUEST_URI = 'http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4'
|
5
|
+
|
6
|
+
it 'must allow delegate initialization' do
|
7
|
+
response = Transloadit::Response.new('test')
|
8
|
+
response.class.must_equal Transloadit::Response
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when initialized' do
|
12
|
+
before do
|
13
|
+
VCR.use_cassette 'fetch_assembly' do
|
14
|
+
@response = Transloadit::Response.new(
|
15
|
+
RestClient::Resource.new(REQUEST_URI).get
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'must parse the body' do
|
21
|
+
@response.body.must_be_kind_of Hash
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'must allow access to body attributes' do
|
25
|
+
%w{ ok message assembly_id assembly_url }.each do |attribute|
|
26
|
+
@response[attribute].must_equal @response.body[attribute]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'must inspect as the body' do
|
31
|
+
@response.inspect.must_equal @response.body.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'when extended as an assembly' do
|
36
|
+
before do
|
37
|
+
VCR.use_cassette 'fetch_assembly' do
|
38
|
+
@response = Transloadit::Response.new(
|
39
|
+
RestClient::Resource.new(REQUEST_URI).get
|
40
|
+
).extend!(Transloadit::Response::Assembly)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'must allow checking for completion' do
|
45
|
+
@response.completed?.must_equal true
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: can this be tested better?
|
49
|
+
it 'must allow reloading the assembly' do
|
50
|
+
VCR.use_cassette 'fetch_assembly' do
|
51
|
+
@response.send(:__getobj__).
|
52
|
+
wont_be_same_as @response.reload!.send(:__getobj__)
|
53
|
+
|
54
|
+
@response.object_id.
|
55
|
+
must_equal @response.reload!.object_id
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'must allow canceling' do
|
60
|
+
VCR.use_cassette 'cancel_assembly' do
|
61
|
+
@response.cancel!
|
62
|
+
|
63
|
+
@response.completed?.must_equal false
|
64
|
+
@response['ok'] .must_equal 'ASSEMBLY_CANCELED'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
5
68
|
end
|
@@ -2,32 +2,26 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe Transloadit::Step do
|
4
4
|
it 'must allow initialization' do
|
5
|
-
Transloadit::Step.new('/s3/store').
|
5
|
+
Transloadit::Step.new('store', '/s3/store').
|
6
|
+
must_be_kind_of Transloadit::Step
|
6
7
|
end
|
7
8
|
|
8
9
|
describe 'when initialized' do
|
9
10
|
before do
|
11
|
+
@name = 'store'
|
10
12
|
@robot = '/s3/store'
|
11
13
|
@key = 'aws-access-key-id'
|
12
14
|
@secret = 'aws-secret-access-key'
|
13
15
|
@bucket = 's3-bucket-name'
|
14
16
|
|
15
|
-
@step = Transloadit::Step.new
|
17
|
+
@step = Transloadit::Step.new @name, @robot,
|
16
18
|
:key => @key,
|
17
19
|
:secret => @secret,
|
18
20
|
:bucket => @bucket
|
19
21
|
end
|
20
22
|
|
21
|
-
it '
|
22
|
-
@step.name.
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'must generate a unique name' do
|
26
|
-
@step.name.wont_equal Transloadit::Step.new('').name
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'must generate a name with 32 hex characters' do
|
30
|
-
@step.name.length.must_equal 32
|
23
|
+
it 'should use the name given' do
|
24
|
+
@step.name.must_equal @name
|
31
25
|
end
|
32
26
|
|
33
27
|
it 'must remember the type' do
|
@@ -64,7 +58,7 @@ describe Transloadit::Step do
|
|
64
58
|
|
65
59
|
describe 'when using alternative inputs' do
|
66
60
|
before do
|
67
|
-
@step = Transloadit::Step.new '/image/resize'
|
61
|
+
@step = Transloadit::Step.new 'resize', '/image/resize'
|
68
62
|
end
|
69
63
|
|
70
64
|
it 'must allow using the original file as input' do
|
@@ -73,7 +67,7 @@ describe Transloadit::Step do
|
|
73
67
|
end
|
74
68
|
|
75
69
|
it 'must allow using another step' do
|
76
|
-
input = Transloadit::Step.new '/video/thumbnail'
|
70
|
+
input = Transloadit::Step.new 'thumbnail', '/video/thumbnail'
|
77
71
|
|
78
72
|
@step.use(input). must_equal [ input.name ]
|
79
73
|
@step.options[:use].must_equal [ input.name ]
|
@@ -81,8 +75,8 @@ describe Transloadit::Step do
|
|
81
75
|
|
82
76
|
it 'must allow using multiple steps' do
|
83
77
|
inputs = [
|
84
|
-
Transloadit::Step.new('/video/thumbnail'),
|
85
|
-
Transloadit::Step.new('/image/resize')
|
78
|
+
Transloadit::Step.new('thumbnail', '/video/thumbnail'),
|
79
|
+
Transloadit::Step.new('resize', '/image/resize')
|
86
80
|
]
|
87
81
|
|
88
82
|
@step.use(inputs). must_equal inputs.map {|i| i.name }
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: transloadit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.9.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Stephen
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-02-
|
14
|
+
date: 2011-02-21 00:00:00 -05:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -134,6 +134,10 @@ files:
|
|
134
134
|
- lib/transloadit/response/assembly.rb
|
135
135
|
- lib/transloadit/step.rb
|
136
136
|
- lib/transloadit/version.rb
|
137
|
+
- test/fixtures/cassettes/cancel_assembly.yml
|
138
|
+
- test/fixtures/cassettes/fetch_assembly.yml
|
139
|
+
- test/fixtures/cassettes/fetch_bored.yml
|
140
|
+
- test/fixtures/cassettes/post_assembly.yml
|
137
141
|
- test/fixtures/cassettes/submit_assembly.yml
|
138
142
|
- test/test_helper.rb
|
139
143
|
- test/unit/test_transloadit.rb
|
@@ -171,6 +175,10 @@ signing_key:
|
|
171
175
|
specification_version: 3
|
172
176
|
summary: Official Ruby gem for Transloadit
|
173
177
|
test_files:
|
178
|
+
- test/fixtures/cassettes/cancel_assembly.yml
|
179
|
+
- test/fixtures/cassettes/fetch_assembly.yml
|
180
|
+
- test/fixtures/cassettes/fetch_bored.yml
|
181
|
+
- test/fixtures/cassettes/post_assembly.yml
|
174
182
|
- test/fixtures/cassettes/submit_assembly.yml
|
175
183
|
- test/test_helper.rb
|
176
184
|
- test/unit/test_transloadit.rb
|