shotstack 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6293628e93b0b33cd83ba41500dfc12f8f729784a697c562e95b74ee1bdccc92
4
- data.tar.gz: 22cf3c4fa7e787c8e85d7236870c609b9054e590e9d106844451ba7b689381b7
3
+ metadata.gz: beaf3d5fe2f52979dd1568eda4493f3b7a17ed4c6d31617cde1fb9fd2380c490
4
+ data.tar.gz: 5285621fb3665111d6604b6bc0ee6b5bf4b0a7a419c5394a2cff017419a70c04
5
5
  SHA512:
6
- metadata.gz: a7bbe3ee1e9813148d25ecf3144ab30b9a6d4d309271ba45c7e2b648cbfda84e7a18589c2c1e4cc5e20d1ada0e7811679b82b7176547dda9a3985022fa84cea4
7
- data.tar.gz: 730d8872e80f2e3bcf5102c8785570c0873bfe4e46ee69ee6fa219d6c6c5567e28972d91a943cac48d1704e88b3e85463c93e691a5068ef29affbb39fe36b169
6
+ metadata.gz: d906ed85a8bc07db5d69b65edac025ddfb85c4820881e0e9f783e227f61e5bfddd5db1ea3d514c00249c418e9ee95e9a8aac72a04e3838b6ec1565653a1ef8a2
7
+ data.tar.gz: 84179e26341f4a1a12a1beade04d07dac1fcb9e782fd2b983acc5b185cf98035b074f8ccdc0580d15b86df17dd7461cf6445a4e12cf79c1c80633e80e962bae3
data/README.md CHANGED
@@ -1,21 +1,26 @@
1
1
  # Shotstack Ruby SDK
2
2
 
3
- Ruby SDK for Shotstack, the cloud video editing API.
3
+ Ruby SDK for [Shotstack](http://shotstack.io), the cloud video editing API.
4
4
 
5
- ## Build Instructions
5
+ Shotstack is a cloud based video editing platform that enables the editing of videos using code.
6
6
 
7
- First make sure the version in `shotstack/version.rb` is correct.
7
+ The platform uses an API and a JSON format for specifying how videos should be edited and what assets and titles should be used.
8
8
 
9
- Then, to build as a gem:
9
+ A server based render farm takes care of rendering the videos allowing multiple videos to be created simultaneously.
10
10
 
11
- ```bash
12
- rm shotstack-*.gem
13
- gem build shotstack
14
- gem push shotstack-*.*.*.gem # use the correct version number
15
- ```
11
+ For examples of how to use the SDK to create videos using code checkout the Ruby demo repo: https://github.com/shotstack/ruby-demos
16
12
 
17
- For local development install the gem:
13
+ ## Installation
18
14
 
19
- ```bash
20
- sudo gem install shotstack
21
15
  ```
16
+ bundle install
17
+ ```
18
+
19
+ ## Documentation
20
+
21
+ - [Getting Started Guide](https://shotstack.gitbook.io/docs/guides/getting-started)
22
+ - [API Reference](https://shotstack.restlet.io/)
23
+ - [Examples](https://github.com/shotstack/ruby-demos)
24
+ - [Shotstack Website](http://shotstack.io)
25
+
26
+ ###
data/lib/shotstack.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details check https://shotstack.io
4
+ #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation.
5
5
 
6
6
  The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.2.1
9
+ OpenAPI Generator version: 5.0.0
10
10
 
11
11
  =end
12
12
 
@@ -19,6 +19,7 @@ require 'shotstack/configuration'
19
19
  # Models
20
20
  require 'shotstack/models/audio_asset'
21
21
  require 'shotstack/models/clip'
22
+ require 'shotstack/models/crop'
22
23
  require 'shotstack/models/edit'
23
24
  require 'shotstack/models/font'
24
25
  require 'shotstack/models/html_asset'
@@ -29,6 +30,7 @@ require 'shotstack/models/output'
29
30
  require 'shotstack/models/poster'
30
31
  require 'shotstack/models/queued_response'
31
32
  require 'shotstack/models/queued_response_data'
33
+ require 'shotstack/models/range'
32
34
  require 'shotstack/models/render_response'
33
35
  require 'shotstack/models/render_response_data'
34
36
  require 'shotstack/models/soundtrack'
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details check https://shotstack.io
4
+ #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation.
5
5
 
6
6
  The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.2.1
9
+ OpenAPI Generator version: 5.0.0
10
10
 
11
11
  =end
12
12
 
@@ -19,6 +19,7 @@ module Shotstack
19
19
  def initialize(api_client = ApiClient.default)
20
20
  @api_client = api_client
21
21
  end
22
+ # Get Render Status
22
23
  # Get the rendering status, video url and details of a timeline by ID.
23
24
  # @param id [String] The id of the timeline render task in UUID format
24
25
  # @param [Hash] opts the optional parameters
@@ -28,6 +29,7 @@ module Shotstack
28
29
  data
29
30
  end
30
31
 
32
+ # Get Render Status
31
33
  # Get the rendering status, video url and details of a timeline by ID.
32
34
  # @param id [String] The id of the timeline render task in UUID format
33
35
  # @param [Hash] opts the optional parameters
@@ -60,15 +62,16 @@ module Shotstack
60
62
  form_params = opts[:form_params] || {}
61
63
 
62
64
  # http body (model)
63
- post_body = opts[:body]
65
+ post_body = opts[:debug_body]
64
66
 
65
67
  # return_type
66
- return_type = opts[:return_type] || 'RenderResponse'
68
+ return_type = opts[:debug_return_type] || 'RenderResponse'
67
69
 
68
70
  # auth_names
69
- auth_names = opts[:auth_names] || ['DeveloperKey']
71
+ auth_names = opts[:debug_auth_names] || ['DeveloperKey']
70
72
 
71
73
  new_options = opts.merge(
74
+ :operation => :"EndpointsApi.get_render",
72
75
  :header_params => header_params,
73
76
  :query_params => query_params,
74
77
  :form_params => form_params,
@@ -84,18 +87,22 @@ module Shotstack
84
87
  return data, status_code, headers
85
88
  end
86
89
 
87
- # Render the contents of a timeline as a video file.
88
- # @param edit [Edit]
90
+ # Render Video
91
+ # Queue and render the contents of a timeline as a video file.
92
+ # @param edit [Edit] The video edit specified using JSON.
89
93
  # @param [Hash] opts the optional parameters
94
+ # @option opts [String] :x_api_queue_id The id of a dedicated queue (enterprise customers only).
90
95
  # @return [QueuedResponse]
91
96
  def post_render(edit, opts = {})
92
97
  data, _status_code, _headers = post_render_with_http_info(edit, opts)
93
98
  data
94
99
  end
95
100
 
96
- # Render the contents of a timeline as a video file.
97
- # @param edit [Edit]
101
+ # Render Video
102
+ # Queue and render the contents of a timeline as a video file.
103
+ # @param edit [Edit] The video edit specified using JSON.
98
104
  # @param [Hash] opts the optional parameters
105
+ # @option opts [String] :x_api_queue_id The id of a dedicated queue (enterprise customers only).
99
106
  # @return [Array<(QueuedResponse, Integer, Hash)>] QueuedResponse data, response status code and response headers
100
107
  def post_render_with_http_info(edit, opts = {})
101
108
  if @api_client.config.debugging
@@ -117,20 +124,22 @@ module Shotstack
117
124
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
118
125
  # HTTP header 'Content-Type'
119
126
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
127
+ header_params[:'x-api-queue-id'] = opts[:'x_api_queue_id'] if !opts[:'x_api_queue_id'].nil?
120
128
 
121
129
  # form parameters
122
130
  form_params = opts[:form_params] || {}
123
131
 
124
132
  # http body (model)
125
- post_body = opts[:body] || @api_client.object_to_http_body(edit)
133
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(edit)
126
134
 
127
135
  # return_type
128
- return_type = opts[:return_type] || 'QueuedResponse'
136
+ return_type = opts[:debug_return_type] || 'QueuedResponse'
129
137
 
130
138
  # auth_names
131
- auth_names = opts[:auth_names] || ['DeveloperKey']
139
+ auth_names = opts[:debug_auth_names] || ['DeveloperKey']
132
140
 
133
141
  new_options = opts.merge(
142
+ :operation => :"EndpointsApi.post_render",
134
143
  :header_params => header_params,
135
144
  :query_params => query_params,
136
145
  :form_params => form_params,
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details check https://shotstack.io
4
+ #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation.
5
5
 
6
6
  The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.2.1
9
+ OpenAPI Generator version: 5.0.0
10
10
 
11
11
  =end
12
12
 
@@ -14,6 +14,7 @@ require 'date'
14
14
  require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
+ require 'time'
17
18
  require 'typhoeus'
18
19
 
19
20
  module Shotstack
@@ -86,7 +87,7 @@ module Shotstack
86
87
  # @option opts [Object] :body HTTP body (JSON/XML)
87
88
  # @return [Typhoeus::Request] A Typhoeus Request
88
89
  def build_request(http_method, path, opts = {})
89
- url = build_request_url(path)
90
+ url = build_request_url(path, opts)
90
91
  http_method = http_method.to_sym.downcase
91
92
 
92
93
  header_params = @default_headers.merge(opts[:header_params] || {})
@@ -155,6 +156,44 @@ module Shotstack
155
156
  data
156
157
  end
157
158
 
159
+ # Save response body into a file in (the defined) temporary folder, using the filename
160
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
161
+ # The response body is written to the file in chunks in order to handle files which
162
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
163
+ # process can use.
164
+ #
165
+ # @see Configuration#temp_folder_path
166
+ def download_file(request)
167
+ tempfile = nil
168
+ encoding = nil
169
+ request.on_headers do |response|
170
+ content_disposition = response.headers['Content-Disposition']
171
+ if content_disposition && content_disposition =~ /filename=/i
172
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
173
+ prefix = sanitize_filename(filename)
174
+ else
175
+ prefix = 'download-'
176
+ end
177
+ prefix = prefix + '-' unless prefix.end_with?('-')
178
+ encoding = response.body.encoding
179
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
180
+ @tempfile = tempfile
181
+ end
182
+ request.on_body do |chunk|
183
+ chunk.force_encoding(encoding)
184
+ tempfile.write(chunk)
185
+ end
186
+ request.on_complete do |response|
187
+ if tempfile
188
+ tempfile.close
189
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
190
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
191
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
192
+ "explicitly with `tempfile.delete`"
193
+ end
194
+ end
195
+ end
196
+
158
197
  # Check if the given MIME is a JSON MIME.
159
198
  # JSON MIME examples:
160
199
  # application/json
@@ -191,7 +230,7 @@ module Shotstack
191
230
  begin
192
231
  data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
193
232
  rescue JSON::ParserError => e
194
- if %w(String Date DateTime).include?(return_type)
233
+ if %w(String Date Time).include?(return_type)
195
234
  data = body
196
235
  else
197
236
  raise e
@@ -216,9 +255,9 @@ module Shotstack
216
255
  data.to_f
217
256
  when 'Boolean'
218
257
  data == true
219
- when 'DateTime'
258
+ when 'Time'
220
259
  # parse date time (expecting ISO 8601 format)
221
- DateTime.parse data
260
+ Time.parse data
222
261
  when 'Date'
223
262
  # parse date time (expecting ISO 8601 format)
224
263
  Date.parse data
@@ -236,44 +275,9 @@ module Shotstack
236
275
  data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
237
276
  end
238
277
  else
239
- # models, e.g. Pet
240
- Shotstack.const_get(return_type).build_from_hash(data)
241
- end
242
- end
243
-
244
- # Save response body into a file in (the defined) temporary folder, using the filename
245
- # from the "Content-Disposition" header if provided, otherwise a random filename.
246
- # The response body is written to the file in chunks in order to handle files which
247
- # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
248
- # process can use.
249
- #
250
- # @see Configuration#temp_folder_path
251
- def download_file(request)
252
- tempfile = nil
253
- encoding = nil
254
- request.on_headers do |response|
255
- content_disposition = response.headers['Content-Disposition']
256
- if content_disposition && content_disposition =~ /filename=/i
257
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
258
- prefix = sanitize_filename(filename)
259
- else
260
- prefix = 'download-'
261
- end
262
- prefix = prefix + '-' unless prefix.end_with?('-')
263
- encoding = response.body.encoding
264
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
265
- @tempfile = tempfile
266
- end
267
- request.on_body do |chunk|
268
- chunk.force_encoding(encoding)
269
- tempfile.write(chunk)
270
- end
271
- request.on_complete do |response|
272
- tempfile.close if tempfile
273
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
274
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
275
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
276
- "explicitly with `tempfile.delete`"
278
+ # models (e.g. Pet) or oneOf
279
+ klass = Shotstack.const_get(return_type)
280
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
277
281
  end
278
282
  end
279
283
 
@@ -286,10 +290,10 @@ module Shotstack
286
290
  filename.gsub(/.*[\/\\]/, '')
287
291
  end
288
292
 
289
- def build_request_url(path)
293
+ def build_request_url(path, opts = {})
290
294
  # Add leading and trailing slashes to path
291
295
  path = "/#{path}".gsub(/\/+/, '/')
292
- @config.base_url + path
296
+ @config.base_url(opts[:operation]) + path
293
297
  end
294
298
 
295
299
  # Update hearder and query params based on authentication settings.
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details check https://shotstack.io
4
+ #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation.
5
5
 
6
6
  The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.2.1
9
+ OpenAPI Generator version: 5.0.0
10
10
 
11
11
  =end
12
12
 
@@ -1,12 +1,12 @@
1
1
  =begin
2
2
  #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details check https://shotstack.io
4
+ #The Shotstack API is a video editing service that allows for the automated creation of videos using JSON. You can configure an edit and POST it to the Shotstack API which will render your video and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.gitbook.io/docs/guides/getting-started) documentation.
5
5
 
6
6
  The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.2.1
9
+ OpenAPI Generator version: 5.0.0
10
10
 
11
11
  =end
12
12
 
@@ -21,6 +21,18 @@ module Shotstack
21
21
  # Defines url base path
22
22
  attr_accessor :base_path
23
23
 
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
24
36
  # Defines API keys used with API Key authentications.
25
37
  #
26
38
  # @return [Hash] key: parameter name, value: parameter value (API key)
@@ -129,6 +141,10 @@ module Shotstack
129
141
  @scheme = 'https'
130
142
  @host = 'api.shotstack.io'
131
143
  @base_path = '/v1'
144
+ @server_index = 0
145
+ @server_operation_index = {}
146
+ @server_variables = {}
147
+ @server_operation_variables = {}
132
148
  @api_key = {}
133
149
  @api_key_prefix = {}
134
150
  @timeout = 0
@@ -171,8 +187,12 @@ module Shotstack
171
187
  @base_path = '' if @base_path == '/'
172
188
  end
173
189
 
174
- def base_url
175
- "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
190
+ # Returns base URL for specified operation based on server settings
191
+ def base_url(operation = nil)
192
+ index = server_operation_index.fetch(operation, server_index)
193
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') # if index == nil
194
+
195
+ #server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
176
196
  end
177
197
 
178
198
  # Gets API key (with prefix if set).
@@ -208,10 +228,10 @@ module Shotstack
208
228
  [
209
229
  {
210
230
  url: "https://api.shotstack.io/{version}",
211
- description: "No descriptoin provided",
231
+ description: "No description provided",
212
232
  variables: {
213
233
  version: {
214
- description: "No descriptoin provided",
234
+ description: "No description provided",
215
235
  default_value: "v1",
216
236
  enum_values: [
217
237
  "v1",
@@ -223,12 +243,17 @@ module Shotstack
223
243
  ]
224
244
  end
225
245
 
246
+ def operation_server_settings
247
+ {
248
+ }
249
+ end
250
+
226
251
  # Returns URL based on server settings
227
252
  #
228
253
  # @param index array index of the server settings
229
254
  # @param variables hash of variable and the corresponding value
230
- def server_url(index, variables = {})
231
- servers = server_settings
255
+ def server_url(index, variables = {}, servers = nil)
256
+ servers = server_settings if servers == nil
232
257
 
233
258
  # check array index out of bound
234
259
  if (index < 0 || index >= servers.size)
@@ -238,10 +263,12 @@ module Shotstack
238
263
  server = servers[index]
239
264
  url = server[:url]
240
265
 
266
+ return url unless server.key? :variables
267
+
241
268
  # go through variable and assign a value
242
269
  server[:variables].each do |name, variable|
243
270
  if variables.key?(name)
244
- if (server[:variables][name][:enum_values].include? variables[name])
271
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
245
272
  url.gsub! "{" + name.to_s + "}", variables[name]
246
273
  else
247
274
  fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."