transloadit 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +23 -0
  3. data/.standard.yml +0 -0
  4. data/CHANGELOG.md +70 -55
  5. data/Gemfile +1 -1
  6. data/README.md +162 -86
  7. data/Rakefile +12 -17
  8. data/examples/README.md +94 -55
  9. data/examples/basic/audio-concat-transcoder.rb +29 -19
  10. data/examples/basic/audio-transcoder.rb +32 -22
  11. data/examples/basic/image-transcoder.rb +22 -17
  12. data/examples/basic/main.rb +31 -37
  13. data/examples/basic/media-transcoder.rb +2 -7
  14. data/lib/transloadit/api_model.rb +13 -13
  15. data/lib/transloadit/assembly.rb +27 -24
  16. data/lib/transloadit/exception.rb +2 -4
  17. data/lib/transloadit/request.rb +58 -52
  18. data/lib/transloadit/response/assembly.rb +14 -13
  19. data/lib/transloadit/response.rb +10 -10
  20. data/lib/transloadit/step.rb +13 -13
  21. data/lib/transloadit/template.rb +5 -5
  22. data/lib/transloadit/version.rb +1 -1
  23. data/lib/transloadit.rb +24 -24
  24. data/test/fixtures/cassettes/cancel_assembly.yml +3 -3
  25. data/test/fixtures/cassettes/create_template.yml +1 -1
  26. data/test/fixtures/cassettes/delete_template.yml +1 -1
  27. data/test/fixtures/cassettes/fetch_assemblies.yml +1 -1
  28. data/test/fixtures/cassettes/fetch_assembly_aborted.yml +3 -3
  29. data/test/fixtures/cassettes/fetch_assembly_errors.yml +3 -3
  30. data/test/fixtures/cassettes/fetch_assembly_executing.yml +3 -3
  31. data/test/fixtures/cassettes/fetch_assembly_notifications.yml +1 -1
  32. data/test/fixtures/cassettes/fetch_assembly_ok.yml +6 -6
  33. data/test/fixtures/cassettes/fetch_assembly_uploading.yml +3 -3
  34. data/test/fixtures/cassettes/fetch_billing.yml +1 -1
  35. data/test/fixtures/cassettes/fetch_root.yml +3 -3
  36. data/test/fixtures/cassettes/fetch_template.yml +1 -1
  37. data/test/fixtures/cassettes/fetch_templates.yml +1 -1
  38. data/test/fixtures/cassettes/post_assembly.yml +2 -2
  39. data/test/fixtures/cassettes/rate_limit_fail.yml +3 -3
  40. data/test/fixtures/cassettes/rate_limit_succeed.yml +4 -4
  41. data/test/fixtures/cassettes/replay_assembly.yml +2 -2
  42. data/test/fixtures/cassettes/replay_assembly_notification.yml +1 -1
  43. data/test/fixtures/cassettes/submit_assembly.yml +3 -3
  44. data/test/fixtures/cassettes/update_template.yml +1 -1
  45. data/test/test_helper.rb +10 -10
  46. data/test/unit/test_transloadit.rb +66 -66
  47. data/test/unit/transloadit/test_api.rb +35 -33
  48. data/test/unit/transloadit/test_assembly.rb +148 -112
  49. data/test/unit/transloadit/test_request.rb +41 -42
  50. data/test/unit/transloadit/test_response.rb +76 -76
  51. data/test/unit/transloadit/test_step.rb +52 -52
  52. data/test/unit/transloadit/test_template.rb +49 -54
  53. data/transloadit.gemspec +25 -26
  54. metadata +25 -41
  55. data/.travis.yml +0 -13
data/Rakefile CHANGED
@@ -1,30 +1,25 @@
1
- require 'rubygems/package_task'
2
- require 'rake/testtask'
3
-
4
- GEMSPEC = 'transloadit.gemspec'
5
-
6
- spec = eval open(GEMSPEC).read
7
- Gem::PackageTask.new(spec) do |gem|
8
- gem.need_tar = true
9
- end
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
10
3
 
11
4
  Rake::TestTask.new do |test|
12
- test.libs << 'test'
13
- test.pattern = 'test/**/test_*.rb'
5
+ test.libs << "test"
6
+ test.pattern = "test/**/test_*.rb"
14
7
  end
15
8
 
16
9
  begin
17
- require 'yard'
18
- require 'yard/rake/yardoc_task'
10
+ require "yard"
11
+ require "yard/rake/yardoc_task"
19
12
 
20
13
  YARD::Rake::YardocTask.new :doc do |yard|
21
- yard.options = %w{
22
- --title Transloadit
14
+ yard.options = %w[
15
+ --title Transloadit
23
16
  --readme README.md
24
17
  --markup rdoc
25
- }
18
+ ]
26
19
  end
27
20
  rescue
28
- desc 'You need the `yard` gem to generate documentation'
21
+ desc "You need the `yard` gem to generate documentation"
29
22
  task :doc
30
23
  end
24
+
25
+ task default: :test
data/examples/README.md CHANGED
@@ -3,6 +3,15 @@
3
3
  ### See an example
4
4
  Navigate to an example directory (e.g. ```basic```) and then run the following, making sure to
5
5
  substitute your own values for the environment variables below:
6
+
7
+ ```bash
8
+ TRANSLOADIT_KEY=<your-transloadit-key> \
9
+ TRANSLOADIT_SECRET=<your-transloadit-secret> \
10
+ main.rb
11
+ ```
12
+
13
+ If you wish to store results from the encoding in an s3 bucket of your own, you can set your s3 credentials as well like so:
14
+
6
15
  ```bash
7
16
  TRANSLOADIT_KEY=<your-transloadit-key> \
8
17
  TRANSLOADIT_SECRET=<your-transloadit-secret> \
@@ -13,66 +22,77 @@ S3_REGION=<your-s3-region> \
13
22
  main.rb
14
23
  ```
15
24
 
25
+ Please be sure you have the `transloadit` gem installed by running `gem install transloadit` before running these examples.
26
+
16
27
  ## Code Review
17
28
 
18
29
  ### Overview
19
30
 
20
- In each example we utilize a simple base class `MediaTranscoder`. This class provides us
21
- with two methods:
31
+ In each example we utilize a simple base class `MediaTranscoder`. This class provides us a simple method:
22
32
 
23
33
  ```
24
34
  transloadit_client
25
- get_status!
26
35
  ```
27
36
 
28
- The first method is responsible for returning us an instance of the Transloadit SDK object,
37
+ The method is responsible for returning us an instance of the Transloadit SDK object,
29
38
  utilizing our credentials that we set in environment variables.
30
39
 
31
- The second method is responsible for returning us the status of an assembly. Note that it
32
- extends `Transloadit::Response::Assembly` to give us access to convenience methods like
33
- `finished?`.
34
-
35
40
  ### First example
36
41
 
37
- In the first example that gets played, we fetch an image from the cat api, optimize it
38
- using the Transloadit `/image/optimize` robot, and then store it in s3.
42
+ In the [first example](https://github.com/transloadit/ruby-sdk/blob/main/examples/basic/image-transcoder.rb)
43
+ that gets played, we fetch an image from the cat api, optimize it using the Transloadit `/image/optimize` robot, and then optionally
44
+ stores it in s3 if the s3 credentials are set.
39
45
 
40
46
  There are only two steps:
41
- ```
47
+
48
+ ```ruby
42
49
  optimize = transloadit_client.step('image', '/image/optimize', {
43
50
  progressive: true,
44
51
  use: ':original',
45
52
  result: true
46
53
  })
47
- store = transloadit_client.step('store', '/s3/store', {
48
- key: ENV.fetch('S3_ACCESS_KEY'),
49
- secret: ENV.fetch('S3_SECRET_KEY'),
50
- bucket: ENV.fetch('S3_BUCKET'),
51
- bucket_region: ENV.fetch('S3_REGION'),
52
- use: 'image'
53
- })
54
+
55
+ steps = [optimize]
56
+
57
+ begin
58
+ store = transloadit_client.step('store', '/s3/store', {
59
+ key: ENV.fetch('S3_ACCESS_KEY'),
60
+ secret: ENV.fetch('S3_SECRET_KEY'),
61
+ bucket: ENV.fetch('S3_BUCKET'),
62
+ bucket_region: ENV.fetch('S3_REGION'),
63
+ use: 'image'
64
+ })
65
+
66
+ steps.push(store)
67
+ rescue KeyError => e
68
+ p 's3 config not set. Skipping s3 storage...'
69
+ end
70
+
54
71
  ```
55
- Again, we utilize environment variables to access our s3 credentials and pass them to
56
- our assembly.
72
+
73
+ Again, we utilize environment variables to access our s3 credentials if given and pass them to
74
+ our assembly. If the s3 credentials are not set, this step is skipped and the transloadit temporary s3 storage is used.
57
75
 
58
76
  The job is invoked by running the following:
77
+
78
+ ```ruby
79
+ assembly = transloadit_client.assembly(steps: steps)
80
+ assembly.create! open(file)
59
81
  ```
60
- assembly = transloadit_client.assembly(steps: [optimize, store])
61
- assembly.submit! open(file)
62
- ```
63
- We pass the two steps we defined above and call `open` on the file passed in. This method
82
+
83
+ We pass the steps we defined above and call `open` on the file passed in. This method
64
84
  assumes the file object passed in responds to `open`.
65
85
 
66
86
  ### Second example
67
87
 
68
- In the second example, we take a non-mp3 audio file, encode it as an mp3, add ID3 tags to it,
69
- and then store it in s3. There are many use cases for audio uploads, and adding ID3 tags
70
- provides the necessary metadata to display artist and track information in audio players
71
- such as iTunes.
88
+ In the [second example](https://github.com/transloadit/ruby-sdk/blob/main/examples/basic/audio-transcoder.rb),
89
+ we take a non-mp3 audio file, encode it as an mp3, add ID3 tags to it, and then optionally store it in s3.
90
+ There are many use cases for audio uploads, and adding ID3 tags provides the necessary metadata to display artist and track information
91
+ in audio players such as iTunes.
72
92
 
73
93
  We have the following steps:
74
94
 
75
- ```
95
+ ```ruby
76
96
  encode_mp3 = transloadit_client.step('mp3_encode', '/audio/encode', {
77
97
  use: ':original',
78
98
  preset: 'mp3',
@@ -85,13 +105,22 @@ write_metadata = transloadit_client.step('mp3', '/meta/write', {
85
105
  result: true,
86
106
  data_to_write: mp3_metadata
87
107
  })
88
- store = transloadit_client.step('store', '/s3/store', {
89
- key: ENV.fetch('S3_ACCESS_KEY'),
90
- secret: ENV.fetch('S3_SECRET_KEY'),
91
- bucket: ENV.fetch('S3_BUCKET'),
92
- bucket_region: ENV.fetch('S3_REGION'),
93
- use: ['mp3']
94
- })
108
+
109
+ steps = [encode_mp3, write_metadata]
110
+
111
+ begin
112
+ store = transloadit_client.step('store', '/s3/store', {
113
+ key: ENV.fetch('S3_ACCESS_KEY'),
114
+ secret: ENV.fetch('S3_SECRET_KEY'),
115
+ bucket: ENV.fetch('S3_BUCKET'),
116
+ bucket_region: ENV.fetch('S3_REGION'),
117
+ use: ['mp3']
118
+ })
119
+
120
+ steps.push(store)
121
+ rescue KeyError => e
122
+ p 's3 config not set. Skipping s3 storage...'
123
+ end
95
124
  ```
96
125
 
97
126
  The first step simply uses the original file to create an mp3 version using the `audio/encode`
@@ -102,7 +131,7 @@ robot. In our simple example we set the track name to the name of the file using
102
131
  name substitution (see https://transloadit.com/docs/#assembly-variables), and set canned
103
132
  values for all other ID3 fields
104
133
 
105
- ```
134
+ ```ruby
106
135
  def mp3_metadata
107
136
  meta = { publisher: 'Transloadit', title: '${file.name}' }
108
137
  meta[:album] = 'Transloadit Compilation'
@@ -112,23 +141,26 @@ def mp3_metadata
112
141
  end
113
142
  ```
114
143
 
144
+ Again, we utilize environment variables to access our s3 credentials if given and pass them to
145
+ our assembly. If the s3 credentials are not set, this step is skipped and the transloadit temporary s3 storage is used.
146
+
115
147
  Finally, we submit the assembly in the same way as the previous example:
116
148
 
117
- ```
118
- assembly = transloadit_client.assembly(steps: [encode_mp3, write_metadata, store])
119
- assembly.submit! open(file)
149
+ ```ruby
150
+ assembly = transloadit_client.assembly(steps: steps)
151
+ assembly.create! open(file)
120
152
  ```
121
153
 
122
154
  ### Third example
123
155
 
124
- In the third example, we take a series of mp3 files and concatenate them together.
125
- We upload the result to s3.
156
+ In the [third example](https://github.com/transloadit/ruby-sdk/blob/main/examples/basic/audio-concat-transcoder.rb),
157
+ we take a series of mp3 files and concatenate them together. We then optionally upload the result to s3.
126
158
 
127
159
  This example is provided to showcase advanced usage of the `use` parameter in the `audio/concat` assembly.
128
160
 
129
161
  In our `transcode` method, note that this time we are passed an array of files.
130
162
 
131
- ```
163
+ ```ruby
132
164
  concat = transloadit_client.step('concat', '/audio/concat', {
133
165
  ffmpeg_stack: 'v2.2.3',
134
166
  preset: 'mp3',
@@ -159,21 +191,28 @@ by its position in the array.
159
191
  This is why it is important to define the ordering in the `steps` array, as there is no guarantee that items
160
192
  will finish uploading in the order they are sent.
161
193
 
162
- With that step complete, we can finalize our store step and submit the assembly.
194
+ With that step complete, we can finalize our store step (which is optionally added if the s3 credentials are set) and submit the assembly.
195
+
196
+ ```ruby
197
+ begin
198
+ store = transloadit_client.step('store', '/s3/store', {
199
+ key: ENV.fetch('S3_ACCESS_KEY'),
200
+ secret: ENV.fetch('S3_SECRET_KEY'),
201
+ bucket: ENV.fetch('S3_BUCKET'),
202
+ bucket_region: ENV.fetch('S3_REGION'),
203
+ use: ['concat']
204
+ })
205
+
206
+ steps.push(store)
207
+ rescue KeyError => e
208
+ p 's3 config not set. Skipping s3 storage...'
209
+ end
163
210
 
164
- ```
165
- store = transloadit_client.step('store', '/s3/store', {
166
- key: ENV.fetch('S3_ACCESS_KEY'),
167
- secret: ENV.fetch('S3_SECRET_KEY'),
168
- bucket: ENV.fetch('S3_BUCKET'),
169
- bucket_region: ENV.fetch('S3_REGION'),
170
- use: ['concat']
171
- })
172
- assembly = transloadit_client.assembly(steps: [concat, store])
173
- assembly.submit! *open_files(files)
211
+ assembly = transloadit_client.assembly(steps: steps)
212
+ assembly.create! *open_files(files)
174
213
  ```
175
214
 
176
- Note the final call to `submit` and usage of the splat (`*`) operator. The `submit!` method expects
215
+ Note the final call to `create` and usage of the splat (`*`) operator. The `create!` method expects
177
216
  one or more arguments. If you would like to pass an array to this method, you must unpack the contents of the array
178
217
  or the method will treat the argument passed in as a single object, and you may have unexpected results in your
179
218
  final results.
@@ -1,40 +1,50 @@
1
1
  class AudioConcatTranscoder < MediaTranscoder
2
- require 'transloadit'
3
- require_relative 'media-transcoder'
2
+ require "transloadit"
3
+ require_relative "media-transcoder"
4
4
 
5
5
  # in this example a file is encoded as an mp3, id3 tags are added, and it is stored in s3
6
6
  def transcode!(files)
7
- concat = transloadit_client.step('concat', '/audio/concat', {
8
- preset: 'mp3',
7
+ concat = transloadit_client.step("concat", "/audio/concat", {
8
+ preset: "mp3",
9
9
  use: {
10
10
  steps: files.map.each_with_index do |f, i|
11
- { name: ':original', as: "audio_#{i}", fields: "file_#{i}" }
11
+ {name: ":original", as: "audio_#{i}", fields: "file_#{i}"}
12
12
  end
13
13
  },
14
14
  result: true
15
15
  })
16
- store = transloadit_client.step('store', '/s3/store', {
17
- key: ENV.fetch('S3_ACCESS_KEY'),
18
- secret: ENV.fetch('S3_SECRET_KEY'),
19
- bucket: ENV.fetch('S3_BUCKET'),
20
- bucket_region: ENV.fetch('S3_REGION'),
21
- use: ['concat']
22
- })
23
- assembly = transloadit_client.assembly(steps: [concat, store])
24
- assembly.submit! *open_files(files)
16
+
17
+ steps = [concat]
18
+
19
+ begin
20
+ store = transloadit_client.step("store", "/s3/store", {
21
+ key: ENV.fetch("S3_ACCESS_KEY"),
22
+ secret: ENV.fetch("S3_SECRET_KEY"),
23
+ bucket: ENV.fetch("S3_BUCKET"),
24
+ bucket_region: ENV.fetch("S3_REGION"),
25
+ use: ["concat"]
26
+ })
27
+
28
+ steps.push(store)
29
+ rescue KeyError
30
+ p "s3 config not set. Skipping s3 storage..."
31
+ end
32
+
33
+ assembly = transloadit_client.assembly(steps: steps)
34
+ assembly.create!(*open_files(files))
25
35
  end
26
36
 
27
37
  def open_files(files)
28
38
  files.map do |f|
29
- open(f)
39
+ File.open(f)
30
40
  end
31
41
  end
32
42
 
33
43
  def mp3_metadata
34
- meta = { publisher: 'Transloadit', title: '${file.name}' }
35
- meta[:album] = 'Transloadit Compilation'
36
- meta[:artist] = 'Transloadit'
37
- meta[:track] = '1/1'
44
+ meta = {publisher: "Transloadit", title: "${file.name}"}
45
+ meta[:album] = "Transloadit Compilation"
46
+ meta[:artist] = "Transloadit"
47
+ meta[:track] = "1/1"
38
48
  meta
39
49
  end
40
50
  end
@@ -1,37 +1,47 @@
1
1
  class AudioTranscoder < MediaTranscoder
2
- require 'transloadit'
3
- require_relative 'media-transcoder'
2
+ require "transloadit"
3
+ require_relative "media-transcoder"
4
4
 
5
5
  # in this example a file is encoded as an mp3, id3 tags are added, and it is stored in s3
6
6
  def transcode!(file)
7
- encode_mp3 = transloadit_client.step('mp3_encode', '/audio/encode', {
8
- use: ':original',
9
- preset: 'mp3',
10
- ffmpeg_stack: 'v2.2.3',
7
+ encode_mp3 = transloadit_client.step("mp3_encode", "/audio/encode", {
8
+ use: ":original",
9
+ preset: "mp3",
10
+ ffmpeg_stack: "v2.2.3",
11
11
  result: true
12
12
  })
13
- write_metadata = transloadit_client.step('mp3', '/meta/write', {
14
- use: 'mp3_encode',
15
- ffmpeg_stack: 'v2.2.3',
13
+ write_metadata = transloadit_client.step("mp3", "/meta/write", {
14
+ use: "mp3_encode",
15
+ ffmpeg_stack: "v2.2.3",
16
16
  result: true,
17
17
  data_to_write: mp3_metadata
18
18
  })
19
- store = transloadit_client.step('store', '/s3/store', {
20
- key: ENV.fetch('S3_ACCESS_KEY'),
21
- secret: ENV.fetch('S3_SECRET_KEY'),
22
- bucket: ENV.fetch('S3_BUCKET'),
23
- bucket_region: ENV.fetch('S3_REGION'),
24
- use: ['mp3']
25
- })
26
- assembly = transloadit_client.assembly(steps: [encode_mp3, write_metadata, store])
27
- assembly.submit! open(file)
19
+
20
+ steps = [encode_mp3, write_metadata]
21
+
22
+ begin
23
+ store = transloadit_client.step("store", "/s3/store", {
24
+ key: ENV.fetch("S3_ACCESS_KEY"),
25
+ secret: ENV.fetch("S3_SECRET_KEY"),
26
+ bucket: ENV.fetch("S3_BUCKET"),
27
+ bucket_region: ENV.fetch("S3_REGION"),
28
+ use: ["mp3"]
29
+ })
30
+
31
+ steps.push(store)
32
+ rescue KeyError
33
+ p "s3 config not set. Skipping s3 storage..."
34
+ end
35
+
36
+ assembly = transloadit_client.assembly(steps: steps)
37
+ assembly.create! File.open(file)
28
38
  end
29
39
 
30
40
  def mp3_metadata
31
- meta = { publisher: 'Transloadit', title: '${file.name}' }
32
- meta[:album] = 'Transloadit Compilation'
33
- meta[:artist] = 'Transloadit'
34
- meta[:track] = '1/1'
41
+ meta = {publisher: "Transloadit", title: "${file.name}"}
42
+ meta[:album] = "Transloadit Compilation"
43
+ meta[:artist] = "Transloadit"
44
+ meta[:track] = "1/1"
35
45
  meta
36
46
  end
37
47
  end
@@ -1,27 +1,32 @@
1
1
  class ImageTranscoder < MediaTranscoder
2
- require 'transloadit'
3
- require_relative 'media-transcoder'
2
+ require "transloadit"
3
+ require_relative "media-transcoder"
4
4
 
5
5
  # in this example a file is submitted, optimized, and then stored in s3
6
6
  def transcode!(file)
7
- optimize = transloadit_client.step('image', '/image/optimize', {
7
+ optimize = transloadit_client.step("image", "/image/optimize", {
8
8
  progressive: true,
9
- use: ':original',
9
+ use: ":original",
10
10
  result: true
11
11
  })
12
- store = transloadit_client.step('store', '/s3/store', {
13
- key: ENV.fetch('S3_ACCESS_KEY'),
14
- secret: ENV.fetch('S3_SECRET_KEY'),
15
- bucket: ENV.fetch('S3_BUCKET'),
16
- bucket_region: ENV.fetch('S3_REGION'),
17
- use: 'image'
18
- })
19
- assembly = transloadit_client.assembly(steps: [optimize, store])
20
- assembly.submit! open(file)
21
- end
22
12
 
23
- def get_status!(assembly_id)
24
- req = Transloadit::Request.new('/assemblies/' + assembly_id.to_s, ENV.fetch('TRANSLOADIT_SECRET'))
25
- req.get.extend!(Transloadit::Response::Assembly)
13
+ steps = [optimize]
14
+
15
+ begin
16
+ store = transloadit_client.step("store", "/s3/store", {
17
+ key: ENV.fetch("S3_ACCESS_KEY"),
18
+ secret: ENV.fetch("S3_SECRET_KEY"),
19
+ bucket: ENV.fetch("S3_BUCKET"),
20
+ bucket_region: ENV.fetch("S3_REGION"),
21
+ use: "image"
22
+ })
23
+
24
+ steps.push(store)
25
+ rescue KeyError
26
+ p "s3 config not set. Skipping s3 storage..."
27
+ end
28
+
29
+ assembly = transloadit_client.assembly(steps: steps)
30
+ assembly.create! File.open(file)
26
31
  end
27
32
  end
@@ -1,69 +1,63 @@
1
- require 'open-uri'
2
- require_relative 'media-transcoder'
3
- require_relative 'image-transcoder'
4
- require_relative 'audio-transcoder'
5
- require_relative 'audio-concat-transcoder'
1
+ require "open-uri"
2
+ require_relative "media-transcoder"
3
+ require_relative "image-transcoder"
4
+ require_relative "audio-transcoder"
5
+ require_relative "audio-concat-transcoder"
6
6
 
7
- p 'starting image transcoding job...'
8
- p 'fetching image from the cat api...'
7
+ p "starting image transcoding job..."
8
+ p "fetching image from the cat api..."
9
9
 
10
- open('http://thecatapi.com/api/images/get') do |f|
11
- p 'starting transcoding job...'
10
+ open("http://thecatapi.com/api/images/get") do |f|
11
+ p "starting transcoding job..."
12
12
  image_transcoder = ImageTranscoder.new
13
13
  response = image_transcoder.transcode!(f)
14
14
 
15
15
  # if you are using rails one thing you can do would be to start an ActiveJob process that recursively
16
16
  # checks on the status of the assembly until it is finished
17
- while !response.finished?
18
- sleep 1
19
- p 'checking job status...'
20
- response = image_transcoder.get_status!(response[:assembly_id])
21
- end
17
+ p "checking job status..."
18
+ response.reload_until_finished!
19
+
22
20
  p response[:message]
23
- p response[:results]['image'][0]['url']
21
+ p response[:results]["image"][0]["url"]
24
22
  end
25
23
 
26
- p 'starting audio transcoding job...'
27
- p 'fetching soundbite from nasa...'
24
+ p "starting audio transcoding job..."
25
+ p "fetching soundbite from nasa..."
28
26
  p "\n"
29
27
 
30
- open('http://www.nasa.gov/640379main_Computers_are_in_Control.m4r') do |f|
31
- p 'starting transcoding job...'
28
+ open("https://www.nasa.gov/640379main_Computers_are_in_Control.m4r") do |f|
29
+ p "starting transcoding job..."
32
30
  audio_transcoder = AudioTranscoder.new
33
31
  response = audio_transcoder.transcode!(f)
34
32
 
35
33
  # if you are using rails one thing you can do would be to start an ActiveJob process that recursively
36
34
  # checks on the status of the assembly until it is finished
37
- while !response.finished?
38
- sleep 1
39
- p 'checking job status...'
40
- response = audio_transcoder.get_status!(response[:assembly_id])
41
- end
35
+ p "checking job status..."
36
+ response.reload_until_finished!
37
+
42
38
  p response[:message]
43
- p response[:results]['mp3'][0]['url']
39
+ p response[:results]["mp3"][0]["url"]
44
40
  p "\n"
45
41
  end
46
42
 
47
- p 'starting audio concat transcoding job...'
48
- p 'fetching 3 soundbites from nasa...'
43
+ p "starting audio concat transcoding job..."
44
+ p "fetching 3 soundbites from nasa..."
49
45
 
50
46
  files = [
51
- 'http://www.nasa.gov/mp3/640148main_APU%20Shutdown.mp3',
52
- 'http://www.nasa.gov/mp3/640164main_Go%20for%20Deploy.mp3',
53
- 'http://www.nasa.gov/mp3/640165main_Lookin%20At%20It.mp3'
47
+ "https://www.nasa.gov/mp3/640148main_APU%20Shutdown.mp3",
48
+ "https://www.nasa.gov/mp3/640164main_Go%20for%20Deploy.mp3",
49
+ "https://www.nasa.gov/mp3/640165main_Lookin%20At%20It.mp3"
54
50
  ]
55
51
 
56
- p 'starting transcoding job...'
52
+ p "starting transcoding job..."
57
53
  audio_concat_transcoder = AudioConcatTranscoder.new
58
54
  response = audio_concat_transcoder.transcode!(files)
59
55
 
60
56
  # if you are using rails one thing you can do would be to start an ActiveJob process that recursively
61
57
  # checks on the status of the assembly until it is finished
62
- while !response.finished?
63
- sleep 1
64
- p 'checking job status...'
65
- response = audio_concat_transcoder.get_status!(response[:assembly_id])
66
- end
58
+ p "checking job status..."
59
+ response.reload_until_finished!
60
+
67
61
  p response[:message]
68
- p response[:results]['concat'][0]['url']
62
+ p response[:results]["concat"][0]["url"]
69
63
  p "\n"
@@ -1,13 +1,8 @@
1
1
  class MediaTranscoder
2
2
  def transloadit_client
3
3
  @transloadit ||= Transloadit.new({
4
- key: ENV.fetch('TRANSLOADIT_KEY'),
5
- secret: ENV.fetch('TRANSLOADIT_SECRET')
4
+ key: ENV.fetch("TRANSLOADIT_KEY"),
5
+ secret: ENV.fetch("TRANSLOADIT_SECRET")
6
6
  })
7
7
  end
8
-
9
- def get_status!(assembly_id)
10
- req = Transloadit::Request.new('/assemblies/' + assembly_id.to_s, ENV.fetch('TRANSLOADIT_SECRET'))
11
- req.get.extend!(Transloadit::Response::Assembly)
12
- end
13
8
  end
@@ -1,4 +1,4 @@
1
- require 'transloadit'
1
+ require "transloadit"
2
2
 
3
3
  #
4
4
  # Represents an API class that more Transloadit specific API classes
@@ -20,30 +20,30 @@ class Transloadit::ApiModel
20
20
  #
21
21
  def initialize(transloadit, options = {})
22
22
  self.transloadit = transloadit
23
- self.options = options
23
+ self.options = options
24
24
  end
25
25
 
26
26
  #
27
27
  # @return [String] a human-readable version of the API
28
28
  #
29
29
  def inspect
30
- self.to_hash.inspect
30
+ to_hash.inspect
31
31
  end
32
32
 
33
33
  #
34
34
  # @return [Hash] a Transloadit-compatible Hash of the API's contents
35
35
  #
36
36
  def to_hash
37
- self.options.merge(
38
- :auth => self.transloadit.to_hash,
39
- ).delete_if {|_,v| v.nil?}
37
+ options.merge(
38
+ auth: transloadit.to_hash
39
+ ).delete_if { |_, v| v.nil? }
40
40
  end
41
41
 
42
42
  #
43
43
  # @return [String] JSON-encoded String containing the API's contents
44
44
  #
45
45
  def to_json
46
- MultiJson.dump(self.to_hash)
46
+ MultiJson.dump(to_hash)
47
47
  end
48
48
 
49
49
  protected
@@ -62,12 +62,12 @@ class Transloadit::ApiModel
62
62
  #
63
63
  # @return [Transloadit::Response] the response
64
64
  #
65
- def _do_request(path, params = nil, method = 'get', extra_params = nil)
66
- if !params.nil?
67
- params = self.to_hash.update(params)
68
- params = { :params => params } if ['post', 'put', 'delete'].include? method
69
- params.merge!(extra_params) if !extra_params.nil?
65
+ def _do_request(path, params = nil, method = "get", extra_params = nil)
66
+ unless params.nil?
67
+ params = to_hash.update(params)
68
+ params = {params: params} if ["post", "put", "delete"].include? method
69
+ params.merge!(extra_params) unless extra_params.nil?
70
70
  end
71
- Transloadit::Request.new(path, self.transloadit.secret).public_send(method, params)
71
+ Transloadit::Request.new(path, transloadit.secret).public_send(method, params)
72
72
  end
73
73
  end