shotstack 0.0.11 → 0.1.4

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: 991d9e463ec387c1f9b95ece6cd397a6435f6584f44082a8176ee129f9691cdc
4
- data.tar.gz: 6ca22d52cae38255a0faa0eb62ca6e2a351e8c5f98852ee246b6f057dbafaab7
3
+ metadata.gz: 579d1ec5fccbd70b7208291c253e5445b322951876de459b3e9ebd997611c402
4
+ data.tar.gz: 0cf0f98748009d2d237d6a65725b84f13321d8fed9226af5a7b0a021b826e538
5
5
  SHA512:
6
- metadata.gz: 7932a40f77cdfcd9f2d6a698ef42929ce697ed68d4144c97c0a76dcc8f0c3d008eed0fb4e4582081b796f2e6767914e76f00b97c523c409c44c1447c40635cd2
7
- data.tar.gz: f368b586aab6dfdaa9795edb4af23d06ef7fab69d29f691e4924e9048ea5457abea5cd60105e3e5b8e466f1df774f69e1cf157b0e6a5d619d31dc65934142046
6
+ metadata.gz: 1b276ccfa85b833e0412c9ba9e453e94a30afcfce6fb03e4cd03376da11b94c699a0b4bf28ed4f3b82271616e629316bd8a6351a4b0d40d20e8ef985915c610c
7
+ data.tar.gz: da0323bac62db522fc290062d405b620821ff9630cee43715d83e5647a49a73225f1f66aaadbe10460ee8f0c24c75cc0cce13d7fbdb593c77b5a2c2bbe37c485
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
+ ###
@@ -1,12 +1,12 @@
1
1
  =begin
2
- #shotstack
2
+ #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the programatic creation of videos using JSON.
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
5
5
 
6
- OpenAPI spec version: v1
6
+ The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.0.0-beta3
9
+ OpenAPI Generator version: 4.2.1
10
10
 
11
11
  =end
12
12
 
@@ -17,15 +17,22 @@ require 'shotstack/version'
17
17
  require 'shotstack/configuration'
18
18
 
19
19
  # Models
20
+ require 'shotstack/models/audio_asset'
20
21
  require 'shotstack/models/clip'
21
22
  require 'shotstack/models/edit'
23
+ require 'shotstack/models/font'
24
+ require 'shotstack/models/html_asset'
22
25
  require 'shotstack/models/image_asset'
26
+ require 'shotstack/models/luma_asset'
27
+ require 'shotstack/models/offset'
23
28
  require 'shotstack/models/output'
29
+ require 'shotstack/models/poster'
24
30
  require 'shotstack/models/queued_response'
25
31
  require 'shotstack/models/queued_response_data'
26
32
  require 'shotstack/models/render_response'
27
33
  require 'shotstack/models/render_response_data'
28
34
  require 'shotstack/models/soundtrack'
35
+ require 'shotstack/models/thumbnail'
29
36
  require 'shotstack/models/timeline'
30
37
  require 'shotstack/models/title_asset'
31
38
  require 'shotstack/models/track'
@@ -33,7 +40,7 @@ require 'shotstack/models/transition'
33
40
  require 'shotstack/models/video_asset'
34
41
 
35
42
  # APIs
36
- require 'shotstack/api/default_api'
43
+ require 'shotstack/api/endpoints_api'
37
44
 
38
45
  module Shotstack
39
46
  class << self
@@ -1,52 +1,54 @@
1
1
  =begin
2
- #shotstack
2
+ #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the programatic creation of videos using JSON.
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
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.0.0
9
+ OpenAPI Generator version: 4.2.1
10
10
 
11
11
  =end
12
12
 
13
- require 'uri'
13
+ require 'cgi'
14
14
 
15
15
  module Shotstack
16
- class DefaultApi
16
+ class EndpointsApi
17
17
  attr_accessor :api_client
18
18
 
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
25
26
  # @return [RenderResponse]
26
27
  def get_render(id, opts = {})
27
- data, _status_code, _headers = g_et_render_id_with_http_info(id, opts)
28
+ data, _status_code, _headers = get_render_with_http_info(id, opts)
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
34
36
  # @return [Array<(RenderResponse, Integer, Hash)>] RenderResponse data, response status code and response headers
35
- def g_et_render_id_with_http_info(id, opts = {})
37
+ def get_render_with_http_info(id, opts = {})
36
38
  if @api_client.config.debugging
37
- @api_client.config.logger.debug 'Calling API: DefaultApi.g_et_render_id ...'
39
+ @api_client.config.logger.debug 'Calling API: EndpointsApi.get_render ...'
38
40
  end
39
41
  # verify the required parameter 'id' is set
40
42
  if @api_client.config.client_side_validation && id.nil?
41
- fail ArgumentError, "Missing the required parameter 'id' when calling DefaultApi.g_et_render_id"
43
+ fail ArgumentError, "Missing the required parameter 'id' when calling EndpointsApi.get_render"
42
44
  end
43
45
  pattern = Regexp.new(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)
44
46
  if @api_client.config.client_side_validation && id !~ pattern
45
- fail ArgumentError, "invalid value for 'id' when calling DefaultApi.get_render, must conform to the pattern #{pattern}."
47
+ fail ArgumentError, "invalid value for 'id' when calling EndpointsApi.get_render, must conform to the pattern #{pattern}."
46
48
  end
47
49
 
48
50
  # resource path
49
- local_var_path = '/render/{id}'.sub('{' + 'id' + '}', id.to_s)
51
+ local_var_path = '/render/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
50
52
 
51
53
  # query parameters
52
54
  query_params = opts[:query_params] || {}
@@ -79,31 +81,35 @@ module Shotstack
79
81
 
80
82
  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
81
83
  if @api_client.config.debugging
82
- @api_client.config.logger.debug "API called: DefaultApi#get_render\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
84
+ @api_client.config.logger.debug "API called: EndpointsApi#get_render\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
83
85
  end
84
86
  return data, status_code, headers
85
87
  end
86
88
 
87
- # Render the contents of a timeline as a video file.
88
- # @param edit [Edit]
89
+ # Render Video
90
+ # Queue and render the contents of a timeline as a video file.
91
+ # @param edit [Edit] The video edit specified using JSON.
89
92
  # @param [Hash] opts the optional parameters
93
+ # @option opts [String] :x_api_queue_id The id of a dedicated queue (enterprise customers only).
90
94
  # @return [QueuedResponse]
91
95
  def post_render(edit, opts = {})
92
- data, _status_code, _headers = p_ost_render_with_http_info(edit, opts)
96
+ data, _status_code, _headers = post_render_with_http_info(edit, opts)
93
97
  data
94
98
  end
95
99
 
96
- # Render the contents of a timeline as a video file.
97
- # @param edit [Edit]
100
+ # Render Video
101
+ # Queue and render the contents of a timeline as a video file.
102
+ # @param edit [Edit] The video edit specified using JSON.
98
103
  # @param [Hash] opts the optional parameters
104
+ # @option opts [String] :x_api_queue_id The id of a dedicated queue (enterprise customers only).
99
105
  # @return [Array<(QueuedResponse, Integer, Hash)>] QueuedResponse data, response status code and response headers
100
- def p_ost_render_with_http_info(edit, opts = {})
106
+ def post_render_with_http_info(edit, opts = {})
101
107
  if @api_client.config.debugging
102
- @api_client.config.logger.debug 'Calling API: DefaultApi.post_render ...'
108
+ @api_client.config.logger.debug 'Calling API: EndpointsApi.post_render ...'
103
109
  end
104
110
  # verify the required parameter 'edit' is set
105
111
  if @api_client.config.client_side_validation && edit.nil?
106
- fail ArgumentError, "Missing the required parameter 'edit' when calling DefaultApi.post_render"
112
+ fail ArgumentError, "Missing the required parameter 'edit' when calling EndpointsApi.post_render"
107
113
  end
108
114
  # resource path
109
115
  local_var_path = '/render'
@@ -117,6 +123,7 @@ module Shotstack
117
123
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
118
124
  # HTTP header 'Content-Type'
119
125
  header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
126
+ header_params[:'x-api-queue-id'] = opts[:'x_api_queue_id'] if !opts[:'x_api_queue_id'].nil?
120
127
 
121
128
  # form parameters
122
129
  form_params = opts[:form_params] || {}
@@ -141,7 +148,7 @@ module Shotstack
141
148
 
142
149
  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
143
150
  if @api_client.config.debugging
144
- @api_client.config.logger.debug "API called: DefaultApi#post_render\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
151
+ @api_client.config.logger.debug "API called: EndpointsApi#post_render\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
145
152
  end
146
153
  return data, status_code, headers
147
154
  end
@@ -1,12 +1,12 @@
1
1
  =begin
2
- #shotstack
2
+ #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the programatic creation of videos using JSON.
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
5
5
 
6
- OpenAPI spec version: v1
6
+ The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.0.0-beta3
9
+ OpenAPI Generator version: 4.2.1
10
10
 
11
11
  =end
12
12
 
@@ -15,7 +15,6 @@ require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
17
  require 'typhoeus'
18
- require 'uri'
19
18
 
20
19
  module Shotstack
21
20
  class ApiClient
@@ -128,6 +127,34 @@ module Shotstack
128
127
  request
129
128
  end
130
129
 
130
+ # Builds the HTTP request body
131
+ #
132
+ # @param [Hash] header_params Header parameters
133
+ # @param [Hash] form_params Query parameters
134
+ # @param [Object] body HTTP body (JSON/XML)
135
+ # @return [String] HTTP body data in the form of string
136
+ def build_request_body(header_params, form_params, body)
137
+ # http form
138
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
139
+ header_params['Content-Type'] == 'multipart/form-data'
140
+ data = {}
141
+ form_params.each do |key, value|
142
+ case value
143
+ when ::File, ::Array, nil
144
+ # let typhoeus handle File, Array and nil parameters
145
+ data[key] = value
146
+ else
147
+ data[key] = value.to_s
148
+ end
149
+ end
150
+ elsif body
151
+ data = body.is_a?(String) ? body : body.to_json
152
+ else
153
+ data = nil
154
+ end
155
+ data
156
+ end
157
+
131
158
  # Check if the given MIME is a JSON MIME.
132
159
  # JSON MIME examples:
133
160
  # application/json
@@ -262,35 +289,7 @@ module Shotstack
262
289
  def build_request_url(path)
263
290
  # Add leading and trailing slashes to path
264
291
  path = "/#{path}".gsub(/\/+/, '/')
265
- URI.encode(@config.base_url + path)
266
- end
267
-
268
- # Builds the HTTP request body
269
- #
270
- # @param [Hash] header_params Header parameters
271
- # @param [Hash] form_params Query parameters
272
- # @param [Object] body HTTP body (JSON/XML)
273
- # @return [String] HTTP body data in the form of string
274
- def build_request_body(header_params, form_params, body)
275
- # http form
276
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
277
- header_params['Content-Type'] == 'multipart/form-data'
278
- data = {}
279
- form_params.each do |key, value|
280
- case value
281
- when ::File, ::Array, nil
282
- # let typhoeus handle File, Array and nil parameters
283
- data[key] = value
284
- else
285
- data[key] = value.to_s
286
- end
287
- end
288
- elsif body
289
- data = body.is_a?(String) ? body : body.to_json
290
- else
291
- data = nil
292
- end
293
- data
292
+ @config.base_url + path
294
293
  end
295
294
 
296
295
  # Update hearder and query params based on authentication settings.
@@ -1,12 +1,12 @@
1
1
  =begin
2
- #shotstack
2
+ #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the programatic creation of videos using JSON.
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
5
5
 
6
- OpenAPI spec version: v1
6
+ The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.0.0-beta3
9
+ OpenAPI Generator version: 4.2.1
10
10
 
11
11
  =end
12
12
 
@@ -1,17 +1,15 @@
1
1
  =begin
2
- #shotstack
2
+ #Shotstack
3
3
 
4
- #The Shotstack API is a video editing service that allows for the programatic creation of videos using JSON.
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
5
5
 
6
- OpenAPI spec version: v1
6
+ The version of the OpenAPI document: v1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.0.0-beta3
9
+ OpenAPI Generator version: 4.2.1
10
10
 
11
11
  =end
12
12
 
13
- require 'uri'
14
-
15
13
  module Shotstack
16
14
  class Configuration
17
15
  # Defines url scheme
@@ -130,7 +128,7 @@ module Shotstack
130
128
  def initialize
131
129
  @scheme = 'https'
132
130
  @host = 'api.shotstack.io'
133
- @base_path = '/version'
131
+ @base_path = '/v1'
134
132
  @api_key = {}
135
133
  @api_key_prefix = {}
136
134
  @timeout = 0
@@ -174,8 +172,7 @@ module Shotstack
174
172
  end
175
173
 
176
174
  def base_url
177
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
178
- URI.encode(url)
175
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
179
176
  end
180
177
 
181
178
  # Gets API key (with prefix if set).
@@ -215,7 +212,11 @@ module Shotstack
215
212
  variables: {
216
213
  version: {
217
214
  description: "No descriptoin provided",
218
- default_value: "version",
215
+ default_value: "v1",
216
+ enum_values: [
217
+ "v1",
218
+ "stage"
219
+ ]
219
220
  }
220
221
  }
221
222
  }
@@ -0,0 +1,253 @@
1
+ =begin
2
+ #Shotstack
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
5
+
6
+ The version of the OpenAPI document: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require_relative 'asset'
15
+
16
+ module Shotstack
17
+ # The AudioAsset is used to add sound effects and audio at specific intervals on the timeline. The src must be a publicly accessible URL to an audio resource such as an mp3 file.
18
+ class AudioAsset < Asset
19
+ # The type of asset - set to `audio` for audio assets.
20
+ attr_accessor :type
21
+
22
+ # The audio source URL. The URL must be publicly accessible or include credentials.
23
+ attr_accessor :src
24
+
25
+ # The start trim point of the audio clip, in seconds (defaults to 0). Audio will start from the in trim point. The audio will play until the file ends or the Clip length is reached.
26
+ attr_accessor :trim
27
+
28
+ # Set the volume for the audio clip between 0 and 1 where 0 is muted and 1 is full volume (defaults to 1).
29
+ attr_accessor :volume
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'type' => :'type',
35
+ :'src' => :'src',
36
+ :'trim' => :'trim',
37
+ :'volume' => :'volume'
38
+ }
39
+ end
40
+
41
+ # Attribute type mapping.
42
+ def self.openapi_types
43
+ {
44
+ :'type' => :'String',
45
+ :'src' => :'String',
46
+ :'trim' => :'Float',
47
+ :'volume' => :'Float'
48
+ }
49
+ end
50
+
51
+ # List of attributes with nullable: true
52
+ def self.openapi_nullable
53
+ Set.new([
54
+ ])
55
+ end
56
+
57
+ # Initializes the object
58
+ # @param [Hash] attributes Model attributes in the form of hash
59
+ def initialize(attributes = {})
60
+ if (!attributes.is_a?(Hash))
61
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Shotstack::AudioAsset` initialize method"
62
+ end
63
+
64
+ # check to see if the attribute exists and convert string to symbol for hash key
65
+ attributes = attributes.each_with_object({}) { |(k, v), h|
66
+ if (!self.class.attribute_map.key?(k.to_sym))
67
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Shotstack::AudioAsset`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
68
+ end
69
+ h[k.to_sym] = v
70
+ }
71
+
72
+ if attributes.key?(:'type')
73
+ self.type = attributes[:'type']
74
+ else
75
+ self.type = 'audio'
76
+ end
77
+
78
+ if attributes.key?(:'src')
79
+ self.src = attributes[:'src']
80
+ end
81
+
82
+ if attributes.key?(:'trim')
83
+ self.trim = attributes[:'trim']
84
+ end
85
+
86
+ if attributes.key?(:'volume')
87
+ self.volume = attributes[:'volume']
88
+ else
89
+ self.volume = 1
90
+ end
91
+ end
92
+
93
+ # Show invalid properties with the reasons. Usually used together with valid?
94
+ # @return Array for valid properties with the reasons
95
+ def list_invalid_properties
96
+ invalid_properties = Array.new
97
+ if @type.nil?
98
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
99
+ end
100
+
101
+ if @src.nil?
102
+ invalid_properties.push('invalid value for "src", src cannot be nil.')
103
+ end
104
+
105
+ invalid_properties
106
+ end
107
+
108
+ # Check to see if the all the properties in the model are valid
109
+ # @return true if the model is valid
110
+ def valid?
111
+ return false if @type.nil?
112
+ return false if @src.nil?
113
+ true
114
+ end
115
+
116
+ # Checks equality by comparing each attribute.
117
+ # @param [Object] Object to be compared
118
+ def ==(o)
119
+ return true if self.equal?(o)
120
+ self.class == o.class &&
121
+ type == o.type &&
122
+ src == o.src &&
123
+ trim == o.trim &&
124
+ volume == o.volume
125
+ end
126
+
127
+ # @see the `==` method
128
+ # @param [Object] Object to be compared
129
+ def eql?(o)
130
+ self == o
131
+ end
132
+
133
+ # Calculates hash code according to all attributes.
134
+ # @return [Integer] Hash code
135
+ def hash
136
+ [type, src, trim, volume].hash
137
+ end
138
+
139
+ # Builds the object from hash
140
+ # @param [Hash] attributes Model attributes in the form of hash
141
+ # @return [Object] Returns the model itself
142
+ def self.build_from_hash(attributes)
143
+ new.build_from_hash(attributes)
144
+ end
145
+
146
+ # Builds the object from hash
147
+ # @param [Hash] attributes Model attributes in the form of hash
148
+ # @return [Object] Returns the model itself
149
+ def build_from_hash(attributes)
150
+ return nil unless attributes.is_a?(Hash)
151
+ self.class.openapi_types.each_pair do |key, type|
152
+ if type =~ /\AArray<(.*)>/i
153
+ # check to ensure the input is an array given that the attribute
154
+ # is documented as an array but the input is not
155
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
156
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
157
+ end
158
+ elsif !attributes[self.class.attribute_map[key]].nil?
159
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
160
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
161
+ end
162
+
163
+ self
164
+ end
165
+
166
+ # Deserializes the data based on type
167
+ # @param string type Data type
168
+ # @param string value Value to be deserialized
169
+ # @return [Object] Deserialized data
170
+ def _deserialize(type, value)
171
+ case type.to_sym
172
+ when :DateTime
173
+ DateTime.parse(value)
174
+ when :Date
175
+ Date.parse(value)
176
+ when :String
177
+ value.to_s
178
+ when :Integer
179
+ value.to_i
180
+ when :Float
181
+ value.to_f
182
+ when :Boolean
183
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
184
+ true
185
+ else
186
+ false
187
+ end
188
+ when :Object
189
+ # generic object (usually a Hash), return directly
190
+ value
191
+ when /\AArray<(?<inner_type>.+)>\z/
192
+ inner_type = Regexp.last_match[:inner_type]
193
+ value.map { |v| _deserialize(inner_type, v) }
194
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
195
+ k_type = Regexp.last_match[:k_type]
196
+ v_type = Regexp.last_match[:v_type]
197
+ {}.tap do |hash|
198
+ value.each do |k, v|
199
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
200
+ end
201
+ end
202
+ else # model
203
+ Shotstack.const_get(type).build_from_hash(value)
204
+ end
205
+ end
206
+
207
+ # Returns the string representation of the object
208
+ # @return [String] String presentation of the object
209
+ def to_s
210
+ to_hash.to_s
211
+ end
212
+
213
+ # to_body is an alias to to_hash (backward compatibility)
214
+ # @return [Hash] Returns the object in the form of hash
215
+ def to_body
216
+ to_hash
217
+ end
218
+
219
+ # Returns the object in the form of hash
220
+ # @return [Hash] Returns the object in the form of hash
221
+ def to_hash
222
+ hash = {}
223
+ self.class.attribute_map.each_pair do |attr, param|
224
+ value = self.send(attr)
225
+ if value.nil?
226
+ is_nullable = self.class.openapi_nullable.include?(attr)
227
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
228
+ end
229
+
230
+ hash[param] = _to_hash(value)
231
+ end
232
+ hash
233
+ end
234
+
235
+ # Outputs non-array value in the form of hash
236
+ # For object, use to_hash. Otherwise, just return the value
237
+ # @param [Object] value Any valid value
238
+ # @return [Hash] Returns the value in the form of hash
239
+ def _to_hash(value)
240
+ if value.is_a?(Array)
241
+ value.compact.map { |v| _to_hash(v) }
242
+ elsif value.is_a?(Hash)
243
+ {}.tap do |hash|
244
+ value.each { |k, v| hash[k] = _to_hash(v) }
245
+ end
246
+ elsif value.respond_to? :to_hash
247
+ value.to_hash
248
+ else
249
+ value
250
+ end
251
+ end
252
+ end
253
+ end