Skip to content

Commit

Permalink
Update example (#68)
Browse files Browse the repository at this point in the history
* Use static files for example instead of online services

* Print secure URLs for results

* Cleanup log output

* Fix linting
  • Loading branch information
Acconut committed Jan 10, 2024
1 parent 94c5c84 commit 9e09ffc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 37 deletions.
14 changes: 7 additions & 7 deletions examples/README.md
Expand Up @@ -40,8 +40,8 @@ utilizing our credentials that we set in environment variables.
### First example

In the [first example](https://github.com/transloadit/ruby-sdk/blob/main/examples/basic/image-transcoder.rb)
that gets played, we fetch an image from the cat api, optimize it using the Transloadit `/image/optimize` robot, and then optionally
stores it in s3 if the s3 credentials are set.
that gets played, we load an image, optimize it using the Transloadit `/image/optimize` robot, and then optionally
store it in s3 if the s3 credentials are set.

There are only two steps:

Expand All @@ -65,7 +65,7 @@ begin

steps.push(store)
rescue KeyError => e
p 's3 config not set. Skipping s3 storage...'
puts 's3 config not set. Skipping s3 storage...'
end

```
Expand Down Expand Up @@ -119,7 +119,7 @@ begin

steps.push(store)
rescue KeyError => e
p 's3 config not set. Skipping s3 storage...'
puts 's3 config not set. Skipping s3 storage...'
end
```

Expand Down Expand Up @@ -175,10 +175,10 @@ concat = transloadit_client.step('concat', '/audio/concat', {

Taking a look at the `concat` step, we see a different usage of the `use` parameter
than we have seen in previous examples. We are effectively able to define the ordering of the
concatenation by specifying the ```name```, `as` and `fields` parameters.
concatenation by specifying the ```name```, `as` and `fields` parameters.

In this example, we have set the name for each to `:original`, specifying that the input
at index `i` should be the input file defined at index `i`.
at index `i` should be the input file defined at index `i`.

It is equally important to specify the `as` parameter. This simple parameter tells the assembly
the ordering.
Expand All @@ -205,7 +205,7 @@ begin

steps.push(store)
rescue KeyError => e
p 's3 config not set. Skipping s3 storage...'
puts 's3 config not set. Skipping s3 storage...'
end

assembly = transloadit_client.assembly(steps: steps)
Expand Down
Binary file added examples/basic/assets/APU_Shutdown.mp3
Binary file not shown.
Binary file not shown.
Binary file added examples/basic/assets/Go_for_Deploy.mp3
Binary file not shown.
Binary file added examples/basic/assets/Lookin_At_It.mp3
Binary file not shown.
Binary file added examples/basic/assets/cat.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/basic/audio-concat-transcoder.rb
Expand Up @@ -27,7 +27,7 @@ def transcode!(files)

steps.push(store)
rescue KeyError
p "s3 config not set. Skipping s3 storage..."
puts "s3 config not set. Skipping s3 storage..."
end

assembly = transloadit_client.assembly(steps: steps)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/audio-transcoder.rb
Expand Up @@ -30,7 +30,7 @@ def transcode!(file)

steps.push(store)
rescue KeyError
p "s3 config not set. Skipping s3 storage..."
puts "s3 config not set. Skipping s3 storage..."
end

assembly = transloadit_client.assembly(steps: steps)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/image-transcoder.rb
Expand Up @@ -23,7 +23,7 @@ def transcode!(file)

steps.push(store)
rescue KeyError
p "s3 config not set. Skipping s3 storage..."
puts "s3 config not set. Skipping s3 storage..."
end

assembly = transloadit_client.assembly(steps: steps)
Expand Down
47 changes: 20 additions & 27 deletions examples/basic/main.rb
@@ -1,63 +1,56 @@
require "open-uri"
require_relative "media-transcoder"
require_relative "image-transcoder"
require_relative "audio-transcoder"
require_relative "audio-concat-transcoder"

p "starting image transcoding job..."
p "fetching image from the cat api..."
puts "starting image transcoding job..."

open("http://thecatapi.com/api/images/get") do |f|
p "starting transcoding job..."
File.open("#{__dir__}/assets/cat.jpg") do |f|
image_transcoder = ImageTranscoder.new
response = image_transcoder.transcode!(f)

# if you are using rails one thing you can do would be to start an ActiveJob process that recursively
# checks on the status of the assembly until it is finished
p "checking job status..."
puts "checking job status..."
response.reload_until_finished!

p response[:message]
p response[:results]["image"][0]["url"]
puts response[:message]
puts response[:results]["image"][0]["ssl_url"]
puts "\n"
end

p "starting audio transcoding job..."
p "fetching soundbite from nasa..."
p "\n"
puts "starting audio transcoding job..."

open("https://www.nasa.gov/640379main_Computers_are_in_Control.m4r") do |f|
p "starting transcoding job..."
File.open("#{__dir__}/assets/Computers_are_in_Control.flac") do |f|
audio_transcoder = AudioTranscoder.new
response = audio_transcoder.transcode!(f)

# if you are using rails one thing you can do would be to start an ActiveJob process that recursively
# checks on the status of the assembly until it is finished
p "checking job status..."
puts "checking job status..."
response.reload_until_finished!

p response[:message]
p response[:results]["mp3"][0]["url"]
p "\n"
puts response[:message]
puts response[:results]["mp3"][0]["ssl_url"]
puts "\n"
end

p "starting audio concat transcoding job..."
p "fetching 3 soundbites from nasa..."
puts "starting audio concat transcoding job..."

files = [
"https://www.nasa.gov/mp3/640148main_APU%20Shutdown.mp3",
"https://www.nasa.gov/mp3/640164main_Go%20for%20Deploy.mp3",
"https://www.nasa.gov/mp3/640165main_Lookin%20At%20It.mp3"
"#{__dir__}/assets/APU_Shutdown.mp3",
"#{__dir__}/assets/Go_for_Deploy.mp3",
"#{__dir__}/assets/Lookin_At_It.mp3"
]

p "starting transcoding job..."
audio_concat_transcoder = AudioConcatTranscoder.new
response = audio_concat_transcoder.transcode!(files)

# if you are using rails one thing you can do would be to start an ActiveJob process that recursively
# checks on the status of the assembly until it is finished
p "checking job status..."
puts "checking job status..."
response.reload_until_finished!

p response[:message]
p response[:results]["concat"][0]["url"]
p "\n"
puts response[:message]
puts response[:results]["concat"][0]["ssl_url"]
puts "\n"

0 comments on commit 9e09ffc

Please sign in to comment.