@@ -11,7 +11,7 @@ A **Ruby** Integration for [Transloadit](https://transloadit.com)'s file uploadi
1111
1212This is a ** Ruby** SDK to make it easy to talk to the [ Transloadit] ( https://transloadit.com ) REST API.
1313
14- * If you run Ruby on Rails and are looking to integrate with the browser for file uploads, checkout the [ rails-sdk] ( https://github.com/transloadit/rails-sdk ) .*
14+ _ If you run Ruby on Rails and are looking to integrate with the browser for file uploads, checkout the [ rails-sdk] ( https://github.com/transloadit/rails-sdk ) ._
1515
1616## Install
1717
@@ -29,14 +29,14 @@ $ irb -rubygems
2929=> true
3030```
3131
32- Then create a Transloadit instance, which will maintain your
33- [ authentication credentials] ( https://transloadit.com/accounts/credentials )
32+ Then create a Transloadit instance, which will maintain your
33+ [ authentication credentials] ( https://transloadit.com/accounts/credentials )
3434and allow us to make requests to [ the API] ( https://transloadit.com/docs/api/ ) .
3535
3636``` ruby
3737transloadit = Transloadit .new (
38- :key => ' YOUR_TRANSLOADIT_KEY ' ,
39- :secret => ' YOUR_TRANSLOADIT_SECRET '
38+ :key => ' MY_TRANSLOADIT_KEY ' ,
39+ :secret => ' MY_TRANSLOADIT_SECRET '
4040)
4141```
4242
@@ -49,8 +49,8 @@ and store the result on [Amazon S3](https://aws.amazon.com/s3/).
4949require ' transloadit'
5050
5151transloadit = Transloadit .new (
52- :key => ' YOUR_TRANSLOADIT_KEY ' ,
53- :secret => ' YOUR_TRANSLOADIT_SECRET '
52+ :key => ' MY_TRANSLOADIT_KEY ' ,
53+ :secret => ' MY_TRANSLOADIT_SECRET '
5454)
5555
5656# First, we create two steps: one to resize the image to 320x240, and another to
@@ -60,9 +60,9 @@ resize = transloadit.step 'resize', '/image/resize',
6060 :height => 240
6161
6262store = transloadit.step ' store' , ' /s3/store' ,
63- :key => ' YOUR_AWS_KEY ' ,
64- :secret => ' YOUR_AWS_SECRET ' ,
65- :bucket => ' YOUR_S3_BUCKET '
63+ :key => ' MY_AWS_KEY ' ,
64+ :secret => ' MY_AWS_SECRET ' ,
65+ :bucket => ' MY_S3_BUCKET '
6666
6767# Now that we have the steps, we create an assembly (which is just a request to
6868# process a file or set of files) and let Transloadit do the rest.
@@ -125,7 +125,7 @@ API at the time the <dfn>Assembly</dfn> was created. You have to explicitly ask
125125# reloads the response's contents from the REST API
126126response.reload!
127127
128- # reloads once per second until all processing is finished, up to number of
128+ # reloads once per second until all processing is finished, up to number of
129129# times specified in :tries option, otherwise will raise ReloadLimitReached
130130response.reload_until_finished! tries: 300 # default is 600
131131```
@@ -147,8 +147,8 @@ than one file in the same request. You can also pass a single <dfn>Step</dfn> fo
147147require ' transloadit'
148148
149149transloadit = Transloadit .new (
150- :key => ' YOUR_TRANSLOADIT_KEY ' ,
151- :secret => ' YOUR_TRANSLOADIT_SECRET '
150+ :key => ' MY_TRANSLOADIT_KEY ' ,
151+ :secret => ' MY_TRANSLOADIT_SECRET '
152152)
153153
154154assembly = transloadit.assembly(steps: store)
@@ -160,7 +160,7 @@ response = assembly.create!(
160160)
161161```
162162
163- You can also pass an array of files to the ` create! ` method.
163+ You can also pass an array of files to the ` create! ` method.
164164Just unpack the array using the splat ` * ` operator.
165165
166166``` ruby
@@ -178,8 +178,8 @@ simply need to `use` other <dfn>Steps</dfn>. Following
178178require ' transloadit'
179179
180180transloadit = Transloadit .new (
181- :key => ' YOUR_TRANSLOADIT_KEY ' ,
182- :secret => ' YOUR_TRANSLOADIT_SECRET '
181+ :key => ' MY_TRANSLOADIT_KEY ' ,
182+ :secret => ' MY_TRANSLOADIT_SECRET '
183183)
184184
185185encode = transloadit.step ' encode' , ' /video/encode' , { ... }
@@ -208,17 +208,17 @@ for recurring encoding tasks. In order to use these do the following:
208208require ' transloadit'
209209
210210transloadit = Transloadit .new (
211- :key => ' YOUR_TRANSLOADIT_KEY ' ,
212- :secret => ' YOUR_TRANSLOADIT_SECRET '
211+ :key => ' MY_TRANSLOADIT_KEY ' ,
212+ :secret => ' MY_TRANSLOADIT_SECRET '
213213)
214214
215215transloadit.assembly(
216- :template_id => ' YOUR_TEMPLATE_ID '
216+ :template_id => ' MY_TEMPLATE_ID '
217217).create! open (' /PATH/TO/FILE.mpg' )
218218```
219219
220220You can use your steps together with this template and even use variables.
221- The [ Transloadit documentation] ( https://transloadit.com/docs/#passing-variables-into-a-template )
221+ The [ Transloadit documentation] ( https://transloadit.com/docs/#passing-variables-into-a-template )
222222has some nice examples for that.
223223
224224### 5. Using fields
@@ -231,8 +231,8 @@ to the upload itself. You can use fields like the following:
231231require ' transloadit'
232232
233233transloadit = Transloadit .new (
234- :key => ' YOUR_TRANSLOADIT_KEY ' ,
235- :secret => ' YOUR_TRANSLOADIT_SECRET '
234+ :key => ' MY_TRANSLOADIT_KEY ' ,
235+ :secret => ' MY_TRANSLOADIT_SECRET '
236236)
237237
238238transloadit.assembly(
@@ -252,8 +252,8 @@ a Notify URL for the <dfn>Assembly</dfn>.
252252require ' transloadit'
253253
254254transloadit = Transloadit .new (
255- :key => ' YOUR_TRANSLOADIT_KEY ' ,
256- :secret => ' YOUR_TRANSLOADIT_SECRET '
255+ :key => ' MY_TRANSLOADIT_KEY ' ,
256+ :secret => ' MY_TRANSLOADIT_SECRET '
257257)
258258
259259transloadit.assembly(
@@ -271,8 +271,8 @@ Transloadit also provides methods to retrieve/replay <dfn>Assemblies</dfn> and t
271271require ' transloadit'
272272
273273transloadit = Transloadit .new (
274- :key => ' YOUR_TRANSLOADIT_KEY ' ,
275- :secret => ' YOUR_TRANSLOADIT_SECRET '
274+ :key => ' MY_TRANSLOADIT_KEY ' ,
275+ :secret => ' MY_TRANSLOADIT_SECRET '
276276)
277277
278278assembly = transloadit.assembly
@@ -281,18 +281,18 @@ assembly = transloadit.assembly
281281assembly.list
282282
283283# returns a specific assembly
284- assembly.get ' YOUR_ASSEMBLY_ID '
284+ assembly.get ' MY_ASSEMBLY_ID '
285285
286286# replays a specific assembly
287- response = assembly.replay ' YOUR_ASSEMBLY_ID '
287+ response = assembly.replay ' MY_ASSEMBLY_ID '
288288# should return true if assembly is replaying and false otherwise.
289289response.replaying?
290290
291291# returns all assembly notifications
292292assembly.get_notifications
293293
294294# replays an assembly notification
295- assembly.replay_notification ' YOUR_ASSEMBLY_ID '
295+ assembly.replay_notification ' MY_ASSEMBLY_ID '
296296```
297297
298298### 8. Templates
@@ -304,8 +304,8 @@ for recurring encoding tasks. Here's how you would create a <dfn>Template</dfn>:
304304require ' transloadit'
305305
306306transloadit = Transloadit .new (
307- :key => ' YOUR_TRANSLOADIT_KEY ' ,
308- :secret => ' YOUR_TRANSLOADIT_SECRET '
307+ :key => ' MY_TRANSLOADIT_KEY ' ,
308+ :secret => ' MY_TRANSLOADIT_SECRET '
309309)
310310
311311template = transloadit.template
@@ -331,8 +331,8 @@ There are also some other methods to retrieve, update and delete a <dfn>Template
331331require ' transloadit'
332332
333333transloadit = Transloadit .new (
334- :key => ' YOUR_TRANSLOADIT_KEY ' ,
335- :secret => ' YOUR_TRANSLOADIT_SECRET '
334+ :key => ' MY_TRANSLOADIT_KEY ' ,
335+ :secret => ' MY_TRANSLOADIT_SECRET '
336336)
337337
338338template = transloadit.template
@@ -341,11 +341,11 @@ template = transloadit.template
341341template.list
342342
343343# returns a specific template.
344- template.get ' YOUR_TEMPLATE_ID '
344+ template.get ' MY_TEMPLATE_ID '
345345
346346# updates the template whose id is specified.
347347template.update(
348- ' YOUR_TEMPLATE_ID ' ,
348+ ' MY_TEMPLATE_ID ' ,
349349 :name => ' CHANGED_TEMPLATE_NAME' ,
350350 :template => {
351351 :steps => {
@@ -358,7 +358,7 @@ template.update(
358358)
359359
360360# deletes a specific template
361- template.delete ' YOUR_TEMPLATE_ID '
361+ template.delete ' MY_TEMPLATE_ID '
362362```
363363
364364### 9. Getting Bill reports
@@ -370,8 +370,8 @@ you can use the `bill` method passing the required month and year like the follo
370370require ' transloadit'
371371
372372transloadit = Transloadit .new (
373- :key => ' YOUR_TRANSLOADIT_KEY ' ,
374- :secret => ' YOUR_TRANSLOADIT_SECRET '
373+ :key => ' MY_TRANSLOADIT_KEY ' ,
374+ :secret => ' MY_TRANSLOADIT_SECRET '
375375)
376376
377377# returns bill report for February, 2016.
@@ -380,7 +380,48 @@ transloadit.bill(2, 2016)
380380
381381Not specifying the ` month ` or ` year ` would default to the current month or year.
382382
383- ### 10. Rate limits
383+ ### 10. Signing Smart CDN URLs
384+
385+ You can generate signed [ Smart CDN] ( https://transloadit.com/services/content-delivery/ ) URLs using your Transloadit instance:
386+
387+ ``` ruby
388+ require ' transloadit'
389+
390+ transloadit = Transloadit .new (
391+ :key => ' MY_TRANSLOADIT_KEY' ,
392+ :secret => ' MY_TRANSLOADIT_SECRET'
393+ )
394+
395+ # Generate a signed URL using instance credentials
396+ url = transloadit.signed_smart_cdn_url(
397+ workspace: " MY_WORKSPACE" ,
398+ template: " MY_TEMPLATE" ,
399+ input: " avatars/jane.jpg"
400+ )
401+
402+ # Add URL parameters
403+ url = transloadit.signed_smart_cdn_url(
404+ workspace: " MY_WORKSPACE" ,
405+ template: " MY_TEMPLATE" ,
406+ input: " avatars/jane.jpg" ,
407+ url_params: {
408+ width: 100 ,
409+ height: 200
410+ }
411+ )
412+
413+ # Set expiration time
414+ url = transloadit.signed_smart_cdn_url(
415+ workspace: " MY_WORKSPACE" ,
416+ template: " MY_TEMPLATE" ,
417+ input: " avatars/jane.jpg" ,
418+ expire_at_ms: 1732550672867 # Specific timestamp
419+ )
420+ ```
421+
422+ The generated URL will be signed using your Transloadit credentials and can be used to access files through the Smart CDN in a secure manner.
423+
424+ ### 11. Rate limits
384425
385426Transloadit enforces rate limits to guarantee that no customers are adversely affected by the usage
386427of any given customer. See [ Rate Limiting] ( https://transloadit.com/docs/api/#rate-limiting ) .
@@ -393,8 +434,8 @@ To change the number of attempts that will be made when creating an <dfn>Assembl
393434require ' transloadit'
394435
395436transloadit = Transloadit .new (
396- :key => ' YOUR_TRANSLOADIT_KEY ' ,
397- :secret => ' YOUR_TRANSLOADIT_SECRET '
437+ :key => ' MY_TRANSLOADIT_KEY ' ,
438+ :secret => ' MY_TRANSLOADIT_SECRET '
398439)
399440
400441# would make one extra attempt after a failed attempt.
@@ -423,3 +464,24 @@ Please see [ci.yml](https://github.com/transloadit/ruby-sdk/tree/main/.github/wo
423464### Ruby 2.x
424465
425466If you still need support for Ruby 2.x, 2.0.1 is the last version that supports it.
467+
468+ ## Contributing
469+
470+ ### Running tests
471+
472+ ``` bash
473+ bundle install
474+ bundle exec rake test
475+ ```
476+
477+ To also test parity against the Node.js reference implementation, run:
478+
479+ ``` bash
480+ TEST_NODE_PARITY=1 bundle exec rake test
481+ ```
482+
483+ To disable coverage reporting, run:
484+
485+ ``` bash
486+ COVERAGE=0 bundle exec rake test
487+ ```
0 commit comments