shotstack 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shotstack.rb +12 -2
- data/lib/shotstack/api/edit_api.rb +155 -0
- data/lib/shotstack/api/endpoints_api.rb +10 -8
- data/lib/shotstack/api/serve_api.rb +224 -0
- data/lib/shotstack/api_client.rb +50 -46
- data/lib/shotstack/api_error.rb +2 -2
- data/lib/shotstack/configuration.rb +50 -9
- data/lib/shotstack/models/asset_render_response.rb +222 -0
- data/lib/shotstack/models/asset_response.rb +219 -0
- data/lib/shotstack/models/asset_response_attributes.rb +334 -0
- data/lib/shotstack/models/asset_response_data.rb +229 -0
- data/lib/shotstack/models/audio_asset.rb +68 -12
- data/lib/shotstack/models/clip.rb +23 -11
- data/lib/shotstack/models/crop.rb +346 -0
- data/lib/shotstack/models/destinations.rb +17 -0
- data/lib/shotstack/models/edit.rb +72 -14
- data/lib/shotstack/models/font.rb +21 -9
- data/lib/shotstack/models/html_asset.rb +26 -14
- data/lib/shotstack/models/image_asset.rb +34 -13
- data/lib/shotstack/models/luma_asset.rb +24 -12
- data/lib/shotstack/models/offset.rb +20 -8
- data/lib/shotstack/models/output.rb +111 -26
- data/lib/shotstack/models/poster.rb +20 -8
- data/lib/shotstack/models/queued_response.rb +21 -8
- data/lib/shotstack/models/queued_response_data.rb +21 -8
- data/lib/shotstack/models/range.rb +260 -0
- data/lib/shotstack/models/render_response.rb +21 -8
- data/lib/shotstack/models/render_response_data.rb +25 -12
- data/lib/shotstack/models/shotstack_destination.rb +240 -0
- data/lib/shotstack/models/size.rb +278 -0
- data/lib/shotstack/models/soundtrack.rb +20 -8
- data/lib/shotstack/models/thumbnail.rb +21 -9
- data/lib/shotstack/models/timeline.rb +37 -13
- data/lib/shotstack/models/title_asset.rb +20 -8
- data/lib/shotstack/models/track.rb +20 -8
- data/lib/shotstack/models/transition.rb +26 -14
- data/lib/shotstack/models/video_asset.rb +33 -12
- data/lib/shotstack/version.rb +3 -3
- data/shotstack.gemspec +4 -5
- metadata +22 -27
data/lib/shotstack/api_client.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
=begin
|
|
2
2
|
#Shotstack
|
|
3
3
|
|
|
4
|
-
#
|
|
4
|
+
#Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media 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. There are two main API's, one for editing and generating assets (Edit API) and one for managing hosted assets (Serve API). The Edit API base URL is: <b>https://api.shotstack.io/{version}</b> The Serve API base URL is: <b>https://api.shotstack.io/serve/{version}</b>
|
|
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:
|
|
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
|
|
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 '
|
|
258
|
+
when 'Time'
|
|
220
259
|
# parse date time (expecting ISO 8601 format)
|
|
221
|
-
|
|
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
|
|
240
|
-
Shotstack.const_get(return_type)
|
|
241
|
-
|
|
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.
|
data/lib/shotstack/api_error.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
=begin
|
|
2
2
|
#Shotstack
|
|
3
3
|
|
|
4
|
-
#
|
|
4
|
+
#Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media 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. There are two main API's, one for editing and generating assets (Edit API) and one for managing hosted assets (Serve API). The Edit API base URL is: <b>https://api.shotstack.io/{version}</b> The Serve API base URL is: <b>https://api.shotstack.io/serve/{version}</b>
|
|
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:
|
|
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
|
-
#
|
|
4
|
+
#Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media 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. There are two main API's, one for editing and generating assets (Edit API) and one for managing hosted assets (Serve API). The Edit API base URL is: <b>https://api.shotstack.io/{version}</b> The Serve API base URL is: <b>https://api.shotstack.io/serve/{version}</b>
|
|
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:
|
|
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
|
-
|
|
175
|
-
|
|
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,24 @@ module Shotstack
|
|
|
208
228
|
[
|
|
209
229
|
{
|
|
210
230
|
url: "https://api.shotstack.io/{version}",
|
|
211
|
-
description: "No
|
|
231
|
+
description: "No description provided",
|
|
232
|
+
variables: {
|
|
233
|
+
version: {
|
|
234
|
+
description: "Set the stage to `v1` for production usage without watermarks. Set to `stage` to use the development sandbox.",
|
|
235
|
+
default_value: "v1",
|
|
236
|
+
enum_values: [
|
|
237
|
+
"v1",
|
|
238
|
+
"stage"
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
url: "https://api.shotstack.io/serve/{version}",
|
|
245
|
+
description: "No description provided",
|
|
212
246
|
variables: {
|
|
213
247
|
version: {
|
|
214
|
-
description: "
|
|
248
|
+
description: "Set the stage to `v1` for production usage. Set to `stage` to use the development sandbox.",
|
|
215
249
|
default_value: "v1",
|
|
216
250
|
enum_values: [
|
|
217
251
|
"v1",
|
|
@@ -223,12 +257,17 @@ module Shotstack
|
|
|
223
257
|
]
|
|
224
258
|
end
|
|
225
259
|
|
|
260
|
+
def operation_server_settings
|
|
261
|
+
{
|
|
262
|
+
}
|
|
263
|
+
end
|
|
264
|
+
|
|
226
265
|
# Returns URL based on server settings
|
|
227
266
|
#
|
|
228
267
|
# @param index array index of the server settings
|
|
229
268
|
# @param variables hash of variable and the corresponding value
|
|
230
|
-
def server_url(index, variables = {})
|
|
231
|
-
servers = server_settings
|
|
269
|
+
def server_url(index, variables = {}, servers = nil)
|
|
270
|
+
servers = server_settings if servers == nil
|
|
232
271
|
|
|
233
272
|
# check array index out of bound
|
|
234
273
|
if (index < 0 || index >= servers.size)
|
|
@@ -238,10 +277,12 @@ module Shotstack
|
|
|
238
277
|
server = servers[index]
|
|
239
278
|
url = server[:url]
|
|
240
279
|
|
|
280
|
+
return url unless server.key? :variables
|
|
281
|
+
|
|
241
282
|
# go through variable and assign a value
|
|
242
283
|
server[:variables].each do |name, variable|
|
|
243
284
|
if variables.key?(name)
|
|
244
|
-
if (server[:variables][name][:enum_values].include?
|
|
285
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
|
245
286
|
url.gsub! "{" + name.to_s + "}", variables[name]
|
|
246
287
|
else
|
|
247
288
|
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#Shotstack
|
|
3
|
+
|
|
4
|
+
#Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media 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. There are two main API's, one for editing and generating assets (Edit API) and one for managing hosted assets (Serve API). The Edit API base URL is: <b>https://api.shotstack.io/{version}</b> The Serve API base URL is: <b>https://api.shotstack.io/serve/{version}</b>
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: v1
|
|
7
|
+
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
OpenAPI Generator version: 5.0.0
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require 'date'
|
|
14
|
+
require 'time'
|
|
15
|
+
|
|
16
|
+
module Shotstack
|
|
17
|
+
# The response returned by the Serve API [get asset by render id](#get-asset-by-render-id) request. The response is an array of asset resources, including video, image, audio, thumbnail and poster image. The response follows the [json:api](https://jsonapi.org/) specification.
|
|
18
|
+
class AssetRenderResponse
|
|
19
|
+
# An array of asset resources grouped by render id.
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
23
|
+
def self.attribute_map
|
|
24
|
+
{
|
|
25
|
+
:'data' => :'data'
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Returns all the JSON keys this model knows about
|
|
30
|
+
def self.acceptable_attributes
|
|
31
|
+
attribute_map.values
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Attribute type mapping.
|
|
35
|
+
def self.openapi_types
|
|
36
|
+
{
|
|
37
|
+
:'data' => :'Array<AssetResponseData>'
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# List of attributes with nullable: true
|
|
42
|
+
def self.openapi_nullable
|
|
43
|
+
Set.new([
|
|
44
|
+
])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Initializes the object
|
|
48
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
49
|
+
def initialize(attributes = {})
|
|
50
|
+
if (!attributes.is_a?(Hash))
|
|
51
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Shotstack::AssetRenderResponse` initialize method"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
55
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
56
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
|
57
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Shotstack::AssetRenderResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
|
58
|
+
end
|
|
59
|
+
h[k.to_sym] = v
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if attributes.key?(:'data')
|
|
63
|
+
if (value = attributes[:'data']).is_a?(Array)
|
|
64
|
+
self.data = value
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
70
|
+
# @return Array for valid properties with the reasons
|
|
71
|
+
def list_invalid_properties
|
|
72
|
+
invalid_properties = Array.new
|
|
73
|
+
invalid_properties
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Check to see if the all the properties in the model are valid
|
|
77
|
+
# @return true if the model is valid
|
|
78
|
+
def valid?
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Checks equality by comparing each attribute.
|
|
83
|
+
# @param [Object] Object to be compared
|
|
84
|
+
def ==(o)
|
|
85
|
+
return true if self.equal?(o)
|
|
86
|
+
self.class == o.class &&
|
|
87
|
+
data == o.data
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @see the `==` method
|
|
91
|
+
# @param [Object] Object to be compared
|
|
92
|
+
def eql?(o)
|
|
93
|
+
self == o
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Calculates hash code according to all attributes.
|
|
97
|
+
# @return [Integer] Hash code
|
|
98
|
+
def hash
|
|
99
|
+
[data].hash
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Builds the object from hash
|
|
103
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
104
|
+
# @return [Object] Returns the model itself
|
|
105
|
+
def self.build_from_hash(attributes)
|
|
106
|
+
new.build_from_hash(attributes)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Builds the object from hash
|
|
110
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
111
|
+
# @return [Object] Returns the model itself
|
|
112
|
+
def build_from_hash(attributes)
|
|
113
|
+
return nil unless attributes.is_a?(Hash)
|
|
114
|
+
self.class.openapi_types.each_pair do |key, type|
|
|
115
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
|
116
|
+
self.send("#{key}=", nil)
|
|
117
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
118
|
+
# check to ensure the input is an array given that the attribute
|
|
119
|
+
# is documented as an array but the input is not
|
|
120
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
|
121
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
|
122
|
+
end
|
|
123
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
|
124
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
self
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Deserializes the data based on type
|
|
132
|
+
# @param string type Data type
|
|
133
|
+
# @param string value Value to be deserialized
|
|
134
|
+
# @return [Object] Deserialized data
|
|
135
|
+
def _deserialize(type, value)
|
|
136
|
+
case type.to_sym
|
|
137
|
+
when :Time
|
|
138
|
+
Time.parse(value)
|
|
139
|
+
when :Date
|
|
140
|
+
Date.parse(value)
|
|
141
|
+
when :String
|
|
142
|
+
value.to_s
|
|
143
|
+
when :Integer
|
|
144
|
+
value.to_i
|
|
145
|
+
when :Float
|
|
146
|
+
value.to_f
|
|
147
|
+
when :Boolean
|
|
148
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
149
|
+
true
|
|
150
|
+
else
|
|
151
|
+
false
|
|
152
|
+
end
|
|
153
|
+
when :Object
|
|
154
|
+
# generic object (usually a Hash), return directly
|
|
155
|
+
value
|
|
156
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
157
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
158
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
159
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
160
|
+
k_type = Regexp.last_match[:k_type]
|
|
161
|
+
v_type = Regexp.last_match[:v_type]
|
|
162
|
+
{}.tap do |hash|
|
|
163
|
+
value.each do |k, v|
|
|
164
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
else # model
|
|
168
|
+
# models (e.g. Pet) or oneOf
|
|
169
|
+
klass = Shotstack.const_get(type)
|
|
170
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Returns the string representation of the object
|
|
175
|
+
# @return [String] String presentation of the object
|
|
176
|
+
def to_s
|
|
177
|
+
to_hash.to_s
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
181
|
+
# @return [Hash] Returns the object in the form of hash
|
|
182
|
+
def to_body
|
|
183
|
+
to_hash
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Returns the object in the form of hash
|
|
187
|
+
# @return [Hash] Returns the object in the form of hash
|
|
188
|
+
def to_hash
|
|
189
|
+
hash = {}
|
|
190
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
191
|
+
value = self.send(attr)
|
|
192
|
+
if value.nil?
|
|
193
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
194
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
hash[param] = _to_hash(value)
|
|
198
|
+
end
|
|
199
|
+
hash
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Outputs non-array value in the form of hash
|
|
203
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
204
|
+
# @param [Object] value Any valid value
|
|
205
|
+
# @return [Hash] Returns the value in the form of hash
|
|
206
|
+
def _to_hash(value)
|
|
207
|
+
if value.is_a?(Array)
|
|
208
|
+
value.compact.map { |v| _to_hash(v) }
|
|
209
|
+
elsif value.is_a?(Hash)
|
|
210
|
+
{}.tap do |hash|
|
|
211
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
212
|
+
end
|
|
213
|
+
elsif value.respond_to? :to_hash
|
|
214
|
+
value.to_hash
|
|
215
|
+
else
|
|
216
|
+
value
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|