shotstack 0.0.9 → 0.1.2

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.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +17 -0
  3. data/lib/shotstack.rb +31 -15
  4. data/lib/shotstack/api/endpoints_api.rb +149 -0
  5. data/lib/shotstack/api_client.rb +142 -74
  6. data/lib/shotstack/api_error.rb +38 -5
  7. data/lib/shotstack/configuration.rb +93 -5
  8. data/lib/shotstack/models/asset.rb +17 -0
  9. data/lib/shotstack/models/audio_asset.rb +251 -0
  10. data/lib/shotstack/models/clip.rb +395 -0
  11. data/lib/shotstack/models/edit.rb +121 -42
  12. data/lib/shotstack/models/font.rb +213 -0
  13. data/lib/shotstack/models/html_asset.rb +319 -0
  14. data/lib/shotstack/models/image_asset.rb +231 -0
  15. data/lib/shotstack/models/luma_asset.rb +241 -0
  16. data/lib/shotstack/models/offset.rb +266 -0
  17. data/lib/shotstack/models/output.rb +207 -46
  18. data/lib/shotstack/models/poster.rb +213 -0
  19. data/lib/shotstack/models/queued_response.rb +121 -49
  20. data/lib/shotstack/models/queued_response_data.rb +116 -46
  21. data/lib/shotstack/models/render_response.rb +121 -49
  22. data/lib/shotstack/models/render_response_data.rb +193 -69
  23. data/lib/shotstack/models/soundtrack.rb +152 -42
  24. data/lib/shotstack/models/thumbnail.rb +228 -0
  25. data/lib/shotstack/models/timeline.rb +124 -45
  26. data/lib/shotstack/models/title_asset.rb +354 -0
  27. data/lib/shotstack/models/track.rb +100 -34
  28. data/lib/shotstack/models/transition.rb +132 -43
  29. data/lib/shotstack/models/video_asset.rb +251 -0
  30. data/lib/shotstack/version.rb +13 -1
  31. data/shotstack.gemspec +23 -16
  32. metadata +37 -150
  33. data/lib/shotstack/api/render_api.rb +0 -137
  34. data/lib/shotstack/models/clips.rb +0 -147
  35. data/lib/shotstack/models/image_clip.rb +0 -216
  36. data/lib/shotstack/models/image_clip_options.rb +0 -175
  37. data/lib/shotstack/models/title_clip.rb +0 -216
  38. data/lib/shotstack/models/title_clip_options.rb +0 -194
  39. data/lib/shotstack/models/video_clip.rb +0 -216
  40. data/lib/shotstack/models/video_clip_options.rb +0 -185
  41. data/tags +0 -306
@@ -0,0 +1,266 @@
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
+
15
+ module Shotstack
16
+ # Offsets the position of an asset horizontally or vertically by a relative distance.
17
+ class Offset
18
+ # Offset an asset on the horizontal axis (left or right), range varies from -1 to 1. Positive numbers move the asset right, negative left. For all assets except titles the distance moved is relative to the width of the viewport - i.e. an X offset of 0.5 will move the asset half the screen width to the right.
19
+ attr_accessor :x
20
+
21
+ # Offset an asset on the vertical axis (up or down), range varies from -1 to 1. Positive numbers move the asset up, negative down. For all assets except titles the distance moved is relative to the height of the viewport - i.e. an Y offset of 0.5 will move the asset up half the screen height.
22
+ attr_accessor :y
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'x' => :'x',
28
+ :'y' => :'y'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'x' => :'Float',
36
+ :'y' => :'Float'
37
+ }
38
+ end
39
+
40
+ # List of attributes with nullable: true
41
+ def self.openapi_nullable
42
+ Set.new([
43
+ ])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Shotstack::Offset` initialize method"
51
+ end
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Shotstack::Offset`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
60
+
61
+ if attributes.key?(:'x')
62
+ self.x = attributes[:'x']
63
+ end
64
+
65
+ if attributes.key?(:'y')
66
+ self.y = attributes[:'y']
67
+ end
68
+ end
69
+
70
+ # Show invalid properties with the reasons. Usually used together with valid?
71
+ # @return Array for valid properties with the reasons
72
+ def list_invalid_properties
73
+ invalid_properties = Array.new
74
+ if !@x.nil? && @x > 1
75
+ invalid_properties.push('invalid value for "x", must be smaller than or equal to 1.')
76
+ end
77
+
78
+ if !@x.nil? && @x < -1
79
+ invalid_properties.push('invalid value for "x", must be greater than or equal to -1.')
80
+ end
81
+
82
+ if !@y.nil? && @y > 1
83
+ invalid_properties.push('invalid value for "y", must be smaller than or equal to 1.')
84
+ end
85
+
86
+ if !@y.nil? && @y < -1
87
+ invalid_properties.push('invalid value for "y", must be greater than or equal to -1.')
88
+ end
89
+
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ return false if !@x.nil? && @x > 1
97
+ return false if !@x.nil? && @x < -1
98
+ return false if !@y.nil? && @y > 1
99
+ return false if !@y.nil? && @y < -1
100
+ true
101
+ end
102
+
103
+ # Custom attribute writer method with validation
104
+ # @param [Object] x Value to be assigned
105
+ def x=(x)
106
+ if !x.nil? && x > 1
107
+ fail ArgumentError, 'invalid value for "x", must be smaller than or equal to 1.'
108
+ end
109
+
110
+ if !x.nil? && x < -1
111
+ fail ArgumentError, 'invalid value for "x", must be greater than or equal to -1.'
112
+ end
113
+
114
+ @x = x
115
+ end
116
+
117
+ # Custom attribute writer method with validation
118
+ # @param [Object] y Value to be assigned
119
+ def y=(y)
120
+ if !y.nil? && y > 1
121
+ fail ArgumentError, 'invalid value for "y", must be smaller than or equal to 1.'
122
+ end
123
+
124
+ if !y.nil? && y < -1
125
+ fail ArgumentError, 'invalid value for "y", must be greater than or equal to -1.'
126
+ end
127
+
128
+ @y = y
129
+ end
130
+
131
+ # Checks equality by comparing each attribute.
132
+ # @param [Object] Object to be compared
133
+ def ==(o)
134
+ return true if self.equal?(o)
135
+ self.class == o.class &&
136
+ x == o.x &&
137
+ y == o.y
138
+ end
139
+
140
+ # @see the `==` method
141
+ # @param [Object] Object to be compared
142
+ def eql?(o)
143
+ self == o
144
+ end
145
+
146
+ # Calculates hash code according to all attributes.
147
+ # @return [Integer] Hash code
148
+ def hash
149
+ [x, y].hash
150
+ end
151
+
152
+ # Builds the object from hash
153
+ # @param [Hash] attributes Model attributes in the form of hash
154
+ # @return [Object] Returns the model itself
155
+ def self.build_from_hash(attributes)
156
+ new.build_from_hash(attributes)
157
+ end
158
+
159
+ # Builds the object from hash
160
+ # @param [Hash] attributes Model attributes in the form of hash
161
+ # @return [Object] Returns the model itself
162
+ def build_from_hash(attributes)
163
+ return nil unless attributes.is_a?(Hash)
164
+ self.class.openapi_types.each_pair do |key, type|
165
+ if type =~ /\AArray<(.*)>/i
166
+ # check to ensure the input is an array given that the attribute
167
+ # is documented as an array but the input is not
168
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
169
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
170
+ end
171
+ elsif !attributes[self.class.attribute_map[key]].nil?
172
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
173
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
174
+ end
175
+
176
+ self
177
+ end
178
+
179
+ # Deserializes the data based on type
180
+ # @param string type Data type
181
+ # @param string value Value to be deserialized
182
+ # @return [Object] Deserialized data
183
+ def _deserialize(type, value)
184
+ case type.to_sym
185
+ when :DateTime
186
+ DateTime.parse(value)
187
+ when :Date
188
+ Date.parse(value)
189
+ when :String
190
+ value.to_s
191
+ when :Integer
192
+ value.to_i
193
+ when :Float
194
+ value.to_f
195
+ when :Boolean
196
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
197
+ true
198
+ else
199
+ false
200
+ end
201
+ when :Object
202
+ # generic object (usually a Hash), return directly
203
+ value
204
+ when /\AArray<(?<inner_type>.+)>\z/
205
+ inner_type = Regexp.last_match[:inner_type]
206
+ value.map { |v| _deserialize(inner_type, v) }
207
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
208
+ k_type = Regexp.last_match[:k_type]
209
+ v_type = Regexp.last_match[:v_type]
210
+ {}.tap do |hash|
211
+ value.each do |k, v|
212
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
213
+ end
214
+ end
215
+ else # model
216
+ Shotstack.const_get(type).build_from_hash(value)
217
+ end
218
+ end
219
+
220
+ # Returns the string representation of the object
221
+ # @return [String] String presentation of the object
222
+ def to_s
223
+ to_hash.to_s
224
+ end
225
+
226
+ # to_body is an alias to to_hash (backward compatibility)
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_body
229
+ to_hash
230
+ end
231
+
232
+ # Returns the object in the form of hash
233
+ # @return [Hash] Returns the object in the form of hash
234
+ def to_hash
235
+ hash = {}
236
+ self.class.attribute_map.each_pair do |attr, param|
237
+ value = self.send(attr)
238
+ if value.nil?
239
+ is_nullable = self.class.openapi_nullable.include?(attr)
240
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
241
+ end
242
+
243
+ hash[param] = _to_hash(value)
244
+ end
245
+ hash
246
+ end
247
+
248
+ # Outputs non-array value in the form of hash
249
+ # For object, use to_hash. Otherwise, just return the value
250
+ # @param [Object] value Any valid value
251
+ # @return [Hash] Returns the value in the form of hash
252
+ def _to_hash(value)
253
+ if value.is_a?(Array)
254
+ value.compact.map { |v| _to_hash(v) }
255
+ elsif value.is_a?(Hash)
256
+ {}.tap do |hash|
257
+ value.each { |k, v| hash[k] = _to_hash(v) }
258
+ end
259
+ elsif value.respond_to? :to_hash
260
+ value.to_hash
261
+ else
262
+ value
263
+ end
264
+ end
265
+ end
266
+ end
@@ -1,105 +1,255 @@
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
+
1
13
  require 'date'
2
14
 
3
15
  module Shotstack
4
- # Model for Output
16
+ # The video output format.
5
17
  class Output
18
+ # `mp4`, `webm` video or animated `gif`
6
19
  attr_accessor :format
7
20
 
21
+ # The output resolution of the video. <ul> <li>`preview` - 512px x 288px @ 15fps</li> <li>`mobile` - 640px x 360px @ 25fps</li> <li>`sd` - 1024px x 576px @ 25fps</li> <li>`hd` - 1280px x 720px @ 25fps</li> <li>`1080` - 1920px x 1080px @ 25fps</li> </ul>
8
22
  attr_accessor :resolution
9
23
 
24
+ # The aspect ratio (shape) of the video. Useful for social media sites. Options are: <ul> <li>`16:9` - regular landscape/horizontal aspect ratio (default)</li> <li>`9:16` - vertical/portrait aspect ratio.</li> <li>`1:1` - square aspect ratio.</li> </ul>
25
+ attr_accessor :aspect_ratio
26
+
27
+ # Override the resolution and scale the video to render at a different size. When using scaleTo the video should be edited at the resolution dimensions, i.e. use font sizes that look best at HD, then use scaleTo to output the video at SD and the text will be scaled to the correct size. This is useful if you want to create multiple video sizes. <ul> <li>`preview` - 512px x 288px @ 15fps</li> <li>`mobile` - 640px x 360px @ 25fps</li> <li>`sd` - 1024px x 576px @25fps</li> <li>`hd` - 1280px x 720px @25fps</li> <li>`1080` - 1920px x 1080px @25fps</li> </ul>
28
+ attr_accessor :scale_to
29
+
30
+ attr_accessor :poster
31
+
32
+ attr_accessor :thumbnail
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
10
56
  # Attribute mapping from ruby-style variable name to JSON key.
11
57
  def self.attribute_map
12
58
  {
13
-
14
59
  :'format' => :'format',
15
-
16
- :'resolution' => :'resolution'
17
-
60
+ :'resolution' => :'resolution',
61
+ :'aspect_ratio' => :'aspectRatio',
62
+ :'scale_to' => :'scaleTo',
63
+ :'poster' => :'poster',
64
+ :'thumbnail' => :'thumbnail'
18
65
  }
19
66
  end
20
67
 
21
68
  # Attribute type mapping.
22
- def self.swagger_types
69
+ def self.openapi_types
23
70
  {
24
71
  :'format' => :'String',
25
- :'resolution' => :'String'
26
-
72
+ :'resolution' => :'String',
73
+ :'aspect_ratio' => :'String',
74
+ :'scale_to' => :'String',
75
+ :'poster' => :'Poster',
76
+ :'thumbnail' => :'Thumbnail'
27
77
  }
28
78
  end
29
79
 
80
+ # List of attributes with nullable: true
81
+ def self.openapi_nullable
82
+ Set.new([
83
+ ])
84
+ end
85
+
86
+ # Initializes the object
87
+ # @param [Hash] attributes Model attributes in the form of hash
30
88
  def initialize(attributes = {})
31
- return unless attributes.is_a?(Hash)
89
+ if (!attributes.is_a?(Hash))
90
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Shotstack::Output` initialize method"
91
+ end
32
92
 
33
- # convert string to symbol for hash key
34
- attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
93
+ # check to see if the attribute exists and convert string to symbol for hash key
94
+ attributes = attributes.each_with_object({}) { |(k, v), h|
95
+ if (!self.class.attribute_map.key?(k.to_sym))
96
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Shotstack::Output`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
97
+ end
98
+ h[k.to_sym] = v
99
+ }
35
100
 
36
-
37
- if attributes[:'format']
101
+ if attributes.key?(:'format')
38
102
  self.format = attributes[:'format']
39
103
  end
40
-
41
- if attributes[:'resolution']
104
+
105
+ if attributes.key?(:'resolution')
42
106
  self.resolution = attributes[:'resolution']
43
107
  end
44
-
108
+
109
+ if attributes.key?(:'aspect_ratio')
110
+ self.aspect_ratio = attributes[:'aspect_ratio']
111
+ end
112
+
113
+ if attributes.key?(:'scale_to')
114
+ self.scale_to = attributes[:'scale_to']
115
+ end
116
+
117
+ if attributes.key?(:'poster')
118
+ self.poster = attributes[:'poster']
119
+ end
120
+
121
+ if attributes.key?(:'thumbnail')
122
+ self.thumbnail = attributes[:'thumbnail']
123
+ end
124
+ end
125
+
126
+ # Show invalid properties with the reasons. Usually used together with valid?
127
+ # @return Array for valid properties with the reasons
128
+ def list_invalid_properties
129
+ invalid_properties = Array.new
130
+ if @format.nil?
131
+ invalid_properties.push('invalid value for "format", format cannot be nil.')
132
+ end
133
+
134
+ if @resolution.nil?
135
+ invalid_properties.push('invalid value for "resolution", resolution cannot be nil.')
136
+ end
137
+
138
+ invalid_properties
139
+ end
140
+
141
+ # Check to see if the all the properties in the model are valid
142
+ # @return true if the model is valid
143
+ def valid?
144
+ return false if @format.nil?
145
+ format_validator = EnumAttributeValidator.new('String', ["mp4", "webm", "gif"])
146
+ return false unless format_validator.valid?(@format)
147
+ return false if @resolution.nil?
148
+ resolution_validator = EnumAttributeValidator.new('String', ["preview", "mobile", "sd", "hd", "1080"])
149
+ return false unless resolution_validator.valid?(@resolution)
150
+ aspect_ratio_validator = EnumAttributeValidator.new('String', ["16:9", "9:16", "1:1"])
151
+ return false unless aspect_ratio_validator.valid?(@aspect_ratio)
152
+ scale_to_validator = EnumAttributeValidator.new('String', ["preview", "mobile", "sd", "hd", "1080"])
153
+ return false unless scale_to_validator.valid?(@scale_to)
154
+ true
45
155
  end
46
156
 
47
157
  # Custom attribute writer method checking allowed values (enum).
158
+ # @param [Object] format Object to be assigned
48
159
  def format=(format)
49
- allowed_values = ["mp4", "gif"]
50
- if format && !allowed_values.include?(format)
51
- fail "invalid value for 'format', must be one of #{allowed_values}"
160
+ validator = EnumAttributeValidator.new('String', ["mp4", "webm", "gif"])
161
+ unless validator.valid?(format)
162
+ fail ArgumentError, "invalid value for \"format\", must be one of #{validator.allowable_values}."
52
163
  end
53
164
  @format = format
54
165
  end
55
166
 
56
167
  # Custom attribute writer method checking allowed values (enum).
168
+ # @param [Object] resolution Object to be assigned
57
169
  def resolution=(resolution)
58
- allowed_values = ["preview", "mobile", "sd", "hd", "1080"]
59
- if resolution && !allowed_values.include?(resolution)
60
- fail "invalid value for 'resolution', must be one of #{allowed_values}"
170
+ validator = EnumAttributeValidator.new('String', ["preview", "mobile", "sd", "hd", "1080"])
171
+ unless validator.valid?(resolution)
172
+ fail ArgumentError, "invalid value for \"resolution\", must be one of #{validator.allowable_values}."
61
173
  end
62
174
  @resolution = resolution
63
175
  end
64
176
 
65
- # Check equality by comparing each attribute.
177
+ # Custom attribute writer method checking allowed values (enum).
178
+ # @param [Object] aspect_ratio Object to be assigned
179
+ def aspect_ratio=(aspect_ratio)
180
+ validator = EnumAttributeValidator.new('String', ["16:9", "9:16", "1:1"])
181
+ unless validator.valid?(aspect_ratio)
182
+ fail ArgumentError, "invalid value for \"aspect_ratio\", must be one of #{validator.allowable_values}."
183
+ end
184
+ @aspect_ratio = aspect_ratio
185
+ end
186
+
187
+ # Custom attribute writer method checking allowed values (enum).
188
+ # @param [Object] scale_to Object to be assigned
189
+ def scale_to=(scale_to)
190
+ validator = EnumAttributeValidator.new('String', ["preview", "mobile", "sd", "hd", "1080"])
191
+ unless validator.valid?(scale_to)
192
+ fail ArgumentError, "invalid value for \"scale_to\", must be one of #{validator.allowable_values}."
193
+ end
194
+ @scale_to = scale_to
195
+ end
196
+
197
+ # Checks equality by comparing each attribute.
198
+ # @param [Object] Object to be compared
66
199
  def ==(o)
67
200
  return true if self.equal?(o)
68
201
  self.class == o.class &&
69
202
  format == o.format &&
70
- resolution == o.resolution
203
+ resolution == o.resolution &&
204
+ aspect_ratio == o.aspect_ratio &&
205
+ scale_to == o.scale_to &&
206
+ poster == o.poster &&
207
+ thumbnail == o.thumbnail
71
208
  end
72
209
 
73
210
  # @see the `==` method
211
+ # @param [Object] Object to be compared
74
212
  def eql?(o)
75
213
  self == o
76
214
  end
77
215
 
78
- # Calculate hash code according to all attributes.
216
+ # Calculates hash code according to all attributes.
217
+ # @return [Integer] Hash code
79
218
  def hash
80
- [format, resolution].hash
219
+ [format, resolution, aspect_ratio, scale_to, poster, thumbnail].hash
220
+ end
221
+
222
+ # Builds the object from hash
223
+ # @param [Hash] attributes Model attributes in the form of hash
224
+ # @return [Object] Returns the model itself
225
+ def self.build_from_hash(attributes)
226
+ new.build_from_hash(attributes)
81
227
  end
82
228
 
83
- # build the object from hash
229
+ # Builds the object from hash
230
+ # @param [Hash] attributes Model attributes in the form of hash
231
+ # @return [Object] Returns the model itself
84
232
  def build_from_hash(attributes)
85
233
  return nil unless attributes.is_a?(Hash)
86
- self.class.swagger_types.each_pair do |key, type|
87
- if type =~ /^Array<(.*)>/i
234
+ self.class.openapi_types.each_pair do |key, type|
235
+ if type =~ /\AArray<(.*)>/i
236
+ # check to ensure the input is an array given that the attribute
237
+ # is documented as an array but the input is not
88
238
  if attributes[self.class.attribute_map[key]].is_a?(Array)
89
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
90
- else
91
- #TODO show warning in debug mode
239
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
92
240
  end
93
241
  elsif !attributes[self.class.attribute_map[key]].nil?
94
242
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
95
- else
96
- # data not found in attributes(hash), not an issue as the data can be optional
97
- end
243
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
98
244
  end
99
245
 
100
246
  self
101
247
  end
102
248
 
249
+ # Deserializes the data based on type
250
+ # @param string type Data type
251
+ # @param string value Value to be deserialized
252
+ # @return [Object] Deserialized data
103
253
  def _deserialize(type, value)
104
254
  case type.to_sym
105
255
  when :DateTime
@@ -112,16 +262,19 @@ module Shotstack
112
262
  value.to_i
113
263
  when :Float
114
264
  value.to_f
115
- when :BOOLEAN
116
- if value =~ /^(true|t|yes|y|1)$/i
265
+ when :Boolean
266
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
117
267
  true
118
268
  else
119
269
  false
120
270
  end
271
+ when :Object
272
+ # generic object (usually a Hash), return directly
273
+ value
121
274
  when /\AArray<(?<inner_type>.+)>\z/
122
275
  inner_type = Regexp.last_match[:inner_type]
123
276
  value.map { |v| _deserialize(inner_type, v) }
124
- when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
277
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
125
278
  k_type = Regexp.last_match[:k_type]
126
279
  v_type = Regexp.last_match[:v_type]
127
280
  {}.tap do |hash|
@@ -130,36 +283,45 @@ module Shotstack
130
283
  end
131
284
  end
132
285
  else # model
133
- _model = Shotstack.const_get(type).new
134
- _model.build_from_hash(value)
286
+ Shotstack.const_get(type).build_from_hash(value)
135
287
  end
136
288
  end
137
289
 
290
+ # Returns the string representation of the object
291
+ # @return [String] String presentation of the object
138
292
  def to_s
139
293
  to_hash.to_s
140
294
  end
141
295
 
142
- # to_body is an alias to to_body (backward compatibility))
296
+ # to_body is an alias to to_hash (backward compatibility)
297
+ # @return [Hash] Returns the object in the form of hash
143
298
  def to_body
144
299
  to_hash
145
300
  end
146
301
 
147
- # return the object in the form of hash
302
+ # Returns the object in the form of hash
303
+ # @return [Hash] Returns the object in the form of hash
148
304
  def to_hash
149
305
  hash = {}
150
306
  self.class.attribute_map.each_pair do |attr, param|
151
307
  value = self.send(attr)
152
- next if value.nil?
308
+ if value.nil?
309
+ is_nullable = self.class.openapi_nullable.include?(attr)
310
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
311
+ end
312
+
153
313
  hash[param] = _to_hash(value)
154
314
  end
155
315
  hash
156
316
  end
157
317
 
158
- # Method to output non-array value in the form of hash
318
+ # Outputs non-array value in the form of hash
159
319
  # For object, use to_hash. Otherwise, just return the value
320
+ # @param [Object] value Any valid value
321
+ # @return [Hash] Returns the value in the form of hash
160
322
  def _to_hash(value)
161
323
  if value.is_a?(Array)
162
- value.compact.map{ |v| _to_hash(v) }
324
+ value.compact.map { |v| _to_hash(v) }
163
325
  elsif value.is_a?(Hash)
164
326
  {}.tap do |hash|
165
327
  value.each { |k, v| hash[k] = _to_hash(v) }
@@ -170,6 +332,5 @@ module Shotstack
170
332
  value
171
333
  end
172
334
  end
173
-
174
335
  end
175
336
  end