activitysmith 1.0.0 → 1.1.0

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.
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- # Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
17
+ # Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
18
18
  class ContentStateUpdate
19
19
  attr_accessor :title
20
20
 
@@ -35,6 +35,9 @@ module OpenapiClient
35
35
  # Maximum progress value. Use with value for type=progress.
36
36
  attr_accessor :upper_limit
37
37
 
38
+ # Use for type=metrics.
39
+ attr_accessor :metrics
40
+
38
41
  # Optional. When omitted, the API uses the existing Live Activity type.
39
42
  attr_accessor :type
40
43
 
@@ -44,6 +47,9 @@ module OpenapiClient
44
47
  # Optional. Overrides color for the current step. Only applies to type=segmented_progress.
45
48
  attr_accessor :step_color
46
49
 
50
+ # Optional. Colors for completed steps. When used with segmented_progress, the array length should match current_step.
51
+ attr_accessor :step_colors
52
+
47
53
  class EnumAttributeValidator
48
54
  attr_reader :datatype
49
55
  attr_reader :allowable_values
@@ -76,9 +82,11 @@ module OpenapiClient
76
82
  :'percentage' => :'percentage',
77
83
  :'value' => :'value',
78
84
  :'upper_limit' => :'upper_limit',
85
+ :'metrics' => :'metrics',
79
86
  :'type' => :'type',
80
87
  :'color' => :'color',
81
- :'step_color' => :'step_color'
88
+ :'step_color' => :'step_color',
89
+ :'step_colors' => :'step_colors'
82
90
  }
83
91
  end
84
92
 
@@ -97,9 +105,11 @@ module OpenapiClient
97
105
  :'percentage' => :'Float',
98
106
  :'value' => :'Float',
99
107
  :'upper_limit' => :'Float',
108
+ :'metrics' => :'Array<ActivityMetric>',
100
109
  :'type' => :'String',
101
110
  :'color' => :'String',
102
- :'step_color' => :'String'
111
+ :'step_color' => :'String',
112
+ :'step_colors' => :'Array<String>'
103
113
  }
104
114
  end
105
115
 
@@ -154,6 +164,12 @@ module OpenapiClient
154
164
  self.upper_limit = attributes[:'upper_limit']
155
165
  end
156
166
 
167
+ if attributes.key?(:'metrics')
168
+ if (value = attributes[:'metrics']).is_a?(Array)
169
+ self.metrics = value
170
+ end
171
+ end
172
+
157
173
  if attributes.key?(:'type')
158
174
  self.type = attributes[:'type']
159
175
  end
@@ -167,6 +183,12 @@ module OpenapiClient
167
183
  if attributes.key?(:'step_color')
168
184
  self.step_color = attributes[:'step_color']
169
185
  end
186
+
187
+ if attributes.key?(:'step_colors')
188
+ if (value = attributes[:'step_colors']).is_a?(Array)
189
+ self.step_colors = value
190
+ end
191
+ end
170
192
  end
171
193
 
172
194
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -194,6 +216,10 @@ module OpenapiClient
194
216
  invalid_properties.push('invalid value for "percentage", must be greater than or equal to 0.')
195
217
  end
196
218
 
219
+ if !@metrics.nil? && @metrics.length < 1
220
+ invalid_properties.push('invalid value for "metrics", number of items must be greater than or equal to 1.')
221
+ end
222
+
197
223
  invalid_properties
198
224
  end
199
225
 
@@ -206,7 +232,8 @@ module OpenapiClient
206
232
  return false if !@current_step.nil? && @current_step < 1
207
233
  return false if !@percentage.nil? && @percentage > 100
208
234
  return false if !@percentage.nil? && @percentage < 0
209
- type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"])
235
+ return false if !@metrics.nil? && @metrics.length < 1
236
+ type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"])
210
237
  return false unless type_validator.valid?(@type)
211
238
  color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
212
239
  return false unless color_validator.valid?(@color)
@@ -261,10 +288,24 @@ module OpenapiClient
261
288
  @percentage = percentage
262
289
  end
263
290
 
291
+ # Custom attribute writer method with validation
292
+ # @param [Object] metrics Value to be assigned
293
+ def metrics=(metrics)
294
+ if metrics.nil?
295
+ fail ArgumentError, 'metrics cannot be nil'
296
+ end
297
+
298
+ if metrics.length < 1
299
+ fail ArgumentError, 'invalid value for "metrics", number of items must be greater than or equal to 1.'
300
+ end
301
+
302
+ @metrics = metrics
303
+ end
304
+
264
305
  # Custom attribute writer method checking allowed values (enum).
265
306
  # @param [Object] type Object to be assigned
266
307
  def type=(type)
267
- validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"])
308
+ validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"])
268
309
  unless validator.valid?(type)
269
310
  fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
270
311
  end
@@ -303,9 +344,11 @@ module OpenapiClient
303
344
  percentage == o.percentage &&
304
345
  value == o.value &&
305
346
  upper_limit == o.upper_limit &&
347
+ metrics == o.metrics &&
306
348
  type == o.type &&
307
349
  color == o.color &&
308
- step_color == o.step_color
350
+ step_color == o.step_color &&
351
+ step_colors == o.step_colors
309
352
  end
310
353
 
311
354
  # @see the `==` method
@@ -317,7 +360,7 @@ module OpenapiClient
317
360
  # Calculates hash code according to all attributes.
318
361
  # @return [Integer] Hash code
319
362
  def hash
320
- [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, type, color, step_color].hash
363
+ [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, metrics, type, color, step_color, step_colors].hash
321
364
  end
322
365
 
323
366
  # Builds the object from hash
@@ -0,0 +1,233 @@
1
+ =begin
2
+ #ActivitySmith API
3
+
4
+ #Send push notifications and Live Activities to your own devices via a single API key.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenapiClient
17
+ # Optional payload for ending a managed stream. When omitted, ActivitySmith ends the stream using the latest known state when possible.
18
+ class LiveActivityStreamDeleteRequest
19
+ attr_accessor :content_state
20
+
21
+ attr_accessor :action
22
+
23
+ attr_accessor :alert
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'content_state' => :'content_state',
29
+ :'action' => :'action',
30
+ :'alert' => :'alert'
31
+ }
32
+ end
33
+
34
+ # Returns all the JSON keys this model knows about
35
+ def self.acceptable_attributes
36
+ attribute_map.values
37
+ end
38
+
39
+ # Attribute type mapping.
40
+ def self.openapi_types
41
+ {
42
+ :'content_state' => :'StreamContentState',
43
+ :'action' => :'LiveActivityAction',
44
+ :'alert' => :'AlertPayload'
45
+ }
46
+ end
47
+
48
+ # List of attributes with nullable: true
49
+ def self.openapi_nullable
50
+ Set.new([
51
+ ])
52
+ end
53
+
54
+ # Initializes the object
55
+ # @param [Hash] attributes Model attributes in the form of hash
56
+ def initialize(attributes = {})
57
+ if (!attributes.is_a?(Hash))
58
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::LiveActivityStreamDeleteRequest` initialize method"
59
+ end
60
+
61
+ # check to see if the attribute exists and convert string to symbol for hash key
62
+ attributes = attributes.each_with_object({}) { |(k, v), h|
63
+ if (!self.class.attribute_map.key?(k.to_sym))
64
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::LiveActivityStreamDeleteRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
65
+ end
66
+ h[k.to_sym] = v
67
+ }
68
+
69
+ if attributes.key?(:'content_state')
70
+ self.content_state = attributes[:'content_state']
71
+ end
72
+
73
+ if attributes.key?(:'action')
74
+ self.action = attributes[:'action']
75
+ end
76
+
77
+ if attributes.key?(:'alert')
78
+ self.alert = attributes[:'alert']
79
+ end
80
+ end
81
+
82
+ # Show invalid properties with the reasons. Usually used together with valid?
83
+ # @return Array for valid properties with the reasons
84
+ def list_invalid_properties
85
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
86
+ invalid_properties = Array.new
87
+ invalid_properties
88
+ end
89
+
90
+ # Check to see if the all the properties in the model are valid
91
+ # @return true if the model is valid
92
+ def valid?
93
+ warn '[DEPRECATED] the `valid?` method is obsolete'
94
+ true
95
+ end
96
+
97
+ # Checks equality by comparing each attribute.
98
+ # @param [Object] Object to be compared
99
+ def ==(o)
100
+ return true if self.equal?(o)
101
+ self.class == o.class &&
102
+ content_state == o.content_state &&
103
+ action == o.action &&
104
+ alert == o.alert
105
+ end
106
+
107
+ # @see the `==` method
108
+ # @param [Object] Object to be compared
109
+ def eql?(o)
110
+ self == o
111
+ end
112
+
113
+ # Calculates hash code according to all attributes.
114
+ # @return [Integer] Hash code
115
+ def hash
116
+ [content_state, action, alert].hash
117
+ end
118
+
119
+ # Builds the object from hash
120
+ # @param [Hash] attributes Model attributes in the form of hash
121
+ # @return [Object] Returns the model itself
122
+ def self.build_from_hash(attributes)
123
+ return nil unless attributes.is_a?(Hash)
124
+ attributes = attributes.transform_keys(&:to_sym)
125
+ transformed_hash = {}
126
+ openapi_types.each_pair do |key, type|
127
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
128
+ transformed_hash["#{key}"] = nil
129
+ elsif type =~ /\AArray<(.*)>/i
130
+ # check to ensure the input is an array given that the attribute
131
+ # is documented as an array but the input is not
132
+ if attributes[attribute_map[key]].is_a?(Array)
133
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
134
+ end
135
+ elsif !attributes[attribute_map[key]].nil?
136
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
137
+ end
138
+ end
139
+ new(transformed_hash)
140
+ end
141
+
142
+ # Deserializes the data based on type
143
+ # @param string type Data type
144
+ # @param string value Value to be deserialized
145
+ # @return [Object] Deserialized data
146
+ def self._deserialize(type, value)
147
+ case type.to_sym
148
+ when :Time
149
+ Time.parse(value)
150
+ when :Date
151
+ Date.parse(value)
152
+ when :String
153
+ value.to_s
154
+ when :Integer
155
+ value.to_i
156
+ when :Float
157
+ value.to_f
158
+ when :Boolean
159
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
160
+ true
161
+ else
162
+ false
163
+ end
164
+ when :Object
165
+ # generic object (usually a Hash), return directly
166
+ value
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ # models (e.g. Pet) or oneOf
180
+ klass = OpenapiClient.const_get(type)
181
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
182
+ end
183
+ end
184
+
185
+ # Returns the string representation of the object
186
+ # @return [String] String presentation of the object
187
+ def to_s
188
+ to_hash.to_s
189
+ end
190
+
191
+ # to_body is an alias to to_hash (backward compatibility)
192
+ # @return [Hash] Returns the object in the form of hash
193
+ def to_body
194
+ to_hash
195
+ end
196
+
197
+ # Returns the object in the form of hash
198
+ # @return [Hash] Returns the object in the form of hash
199
+ def to_hash
200
+ hash = {}
201
+ self.class.attribute_map.each_pair do |attr, param|
202
+ value = self.send(attr)
203
+ if value.nil?
204
+ is_nullable = self.class.openapi_nullable.include?(attr)
205
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
206
+ end
207
+
208
+ hash[param] = _to_hash(value)
209
+ end
210
+ hash
211
+ end
212
+
213
+ # Outputs non-array value in the form of hash
214
+ # For object, use to_hash. Otherwise, just return the value
215
+ # @param [Object] value Any valid value
216
+ # @return [Hash] Returns the value in the form of hash
217
+ def _to_hash(value)
218
+ if value.is_a?(Array)
219
+ value.compact.map { |v| _to_hash(v) }
220
+ elsif value.is_a?(Hash)
221
+ {}.tap do |hash|
222
+ value.each { |k, v| hash[k] = _to_hash(v) }
223
+ end
224
+ elsif value.respond_to? :to_hash
225
+ value.to_hash
226
+ else
227
+ value
228
+ end
229
+ end
230
+
231
+ end
232
+
233
+ end
@@ -0,0 +1,332 @@
1
+ =begin
2
+ #ActivitySmith API
3
+
4
+ #Send push notifications and Live Activities to your own devices via a single API key.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenapiClient
17
+ # Returned after a managed stream is ended and removed.
18
+ class LiveActivityStreamDeleteResponse
19
+ attr_accessor :success
20
+
21
+ attr_accessor :operation
22
+
23
+ attr_accessor :stream_key
24
+
25
+ attr_accessor :activity_id
26
+
27
+ attr_accessor :devices_queued
28
+
29
+ attr_accessor :devices_notified
30
+
31
+ attr_accessor :timestamp
32
+
33
+ class EnumAttributeValidator
34
+ attr_reader :datatype
35
+ attr_reader :allowable_values
36
+
37
+ def initialize(datatype, allowable_values)
38
+ @allowable_values = allowable_values.map do |value|
39
+ case datatype.to_s
40
+ when /Integer/i
41
+ value.to_i
42
+ when /Float/i
43
+ value.to_f
44
+ else
45
+ value
46
+ end
47
+ end
48
+ end
49
+
50
+ def valid?(value)
51
+ !value || allowable_values.include?(value)
52
+ end
53
+ end
54
+
55
+ # Attribute mapping from ruby-style variable name to JSON key.
56
+ def self.attribute_map
57
+ {
58
+ :'success' => :'success',
59
+ :'operation' => :'operation',
60
+ :'stream_key' => :'stream_key',
61
+ :'activity_id' => :'activity_id',
62
+ :'devices_queued' => :'devices_queued',
63
+ :'devices_notified' => :'devices_notified',
64
+ :'timestamp' => :'timestamp'
65
+ }
66
+ end
67
+
68
+ # Returns all the JSON keys this model knows about
69
+ def self.acceptable_attributes
70
+ attribute_map.values
71
+ end
72
+
73
+ # Attribute type mapping.
74
+ def self.openapi_types
75
+ {
76
+ :'success' => :'Boolean',
77
+ :'operation' => :'String',
78
+ :'stream_key' => :'String',
79
+ :'activity_id' => :'String',
80
+ :'devices_queued' => :'Integer',
81
+ :'devices_notified' => :'Integer',
82
+ :'timestamp' => :'Time'
83
+ }
84
+ end
85
+
86
+ # List of attributes with nullable: true
87
+ def self.openapi_nullable
88
+ Set.new([
89
+ :'activity_id',
90
+ ])
91
+ end
92
+
93
+ # Initializes the object
94
+ # @param [Hash] attributes Model attributes in the form of hash
95
+ def initialize(attributes = {})
96
+ if (!attributes.is_a?(Hash))
97
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::LiveActivityStreamDeleteResponse` initialize method"
98
+ end
99
+
100
+ # check to see if the attribute exists and convert string to symbol for hash key
101
+ attributes = attributes.each_with_object({}) { |(k, v), h|
102
+ if (!self.class.attribute_map.key?(k.to_sym))
103
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::LiveActivityStreamDeleteResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
104
+ end
105
+ h[k.to_sym] = v
106
+ }
107
+
108
+ if attributes.key?(:'success')
109
+ self.success = attributes[:'success']
110
+ else
111
+ self.success = nil
112
+ end
113
+
114
+ if attributes.key?(:'operation')
115
+ self.operation = attributes[:'operation']
116
+ else
117
+ self.operation = nil
118
+ end
119
+
120
+ if attributes.key?(:'stream_key')
121
+ self.stream_key = attributes[:'stream_key']
122
+ else
123
+ self.stream_key = nil
124
+ end
125
+
126
+ if attributes.key?(:'activity_id')
127
+ self.activity_id = attributes[:'activity_id']
128
+ end
129
+
130
+ if attributes.key?(:'devices_queued')
131
+ self.devices_queued = attributes[:'devices_queued']
132
+ end
133
+
134
+ if attributes.key?(:'devices_notified')
135
+ self.devices_notified = attributes[:'devices_notified']
136
+ end
137
+
138
+ if attributes.key?(:'timestamp')
139
+ self.timestamp = attributes[:'timestamp']
140
+ else
141
+ self.timestamp = nil
142
+ end
143
+ end
144
+
145
+ # Show invalid properties with the reasons. Usually used together with valid?
146
+ # @return Array for valid properties with the reasons
147
+ def list_invalid_properties
148
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
149
+ invalid_properties = Array.new
150
+ if @success.nil?
151
+ invalid_properties.push('invalid value for "success", success cannot be nil.')
152
+ end
153
+
154
+ if @operation.nil?
155
+ invalid_properties.push('invalid value for "operation", operation cannot be nil.')
156
+ end
157
+
158
+ if @stream_key.nil?
159
+ invalid_properties.push('invalid value for "stream_key", stream_key cannot be nil.')
160
+ end
161
+
162
+ if @timestamp.nil?
163
+ invalid_properties.push('invalid value for "timestamp", timestamp cannot be nil.')
164
+ end
165
+
166
+ invalid_properties
167
+ end
168
+
169
+ # Check to see if the all the properties in the model are valid
170
+ # @return true if the model is valid
171
+ def valid?
172
+ warn '[DEPRECATED] the `valid?` method is obsolete'
173
+ return false if @success.nil?
174
+ return false if @operation.nil?
175
+ operation_validator = EnumAttributeValidator.new('String', ["ended"])
176
+ return false unless operation_validator.valid?(@operation)
177
+ return false if @stream_key.nil?
178
+ return false if @timestamp.nil?
179
+ true
180
+ end
181
+
182
+ # Custom attribute writer method checking allowed values (enum).
183
+ # @param [Object] operation Object to be assigned
184
+ def operation=(operation)
185
+ validator = EnumAttributeValidator.new('String', ["ended"])
186
+ unless validator.valid?(operation)
187
+ fail ArgumentError, "invalid value for \"operation\", must be one of #{validator.allowable_values}."
188
+ end
189
+ @operation = operation
190
+ end
191
+
192
+ # Checks equality by comparing each attribute.
193
+ # @param [Object] Object to be compared
194
+ def ==(o)
195
+ return true if self.equal?(o)
196
+ self.class == o.class &&
197
+ success == o.success &&
198
+ operation == o.operation &&
199
+ stream_key == o.stream_key &&
200
+ activity_id == o.activity_id &&
201
+ devices_queued == o.devices_queued &&
202
+ devices_notified == o.devices_notified &&
203
+ timestamp == o.timestamp
204
+ end
205
+
206
+ # @see the `==` method
207
+ # @param [Object] Object to be compared
208
+ def eql?(o)
209
+ self == o
210
+ end
211
+
212
+ # Calculates hash code according to all attributes.
213
+ # @return [Integer] Hash code
214
+ def hash
215
+ [success, operation, stream_key, activity_id, devices_queued, devices_notified, timestamp].hash
216
+ end
217
+
218
+ # Builds the object from hash
219
+ # @param [Hash] attributes Model attributes in the form of hash
220
+ # @return [Object] Returns the model itself
221
+ def self.build_from_hash(attributes)
222
+ return nil unless attributes.is_a?(Hash)
223
+ attributes = attributes.transform_keys(&:to_sym)
224
+ transformed_hash = {}
225
+ openapi_types.each_pair do |key, type|
226
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
227
+ transformed_hash["#{key}"] = nil
228
+ elsif type =~ /\AArray<(.*)>/i
229
+ # check to ensure the input is an array given that the attribute
230
+ # is documented as an array but the input is not
231
+ if attributes[attribute_map[key]].is_a?(Array)
232
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
233
+ end
234
+ elsif !attributes[attribute_map[key]].nil?
235
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
236
+ end
237
+ end
238
+ new(transformed_hash)
239
+ end
240
+
241
+ # Deserializes the data based on type
242
+ # @param string type Data type
243
+ # @param string value Value to be deserialized
244
+ # @return [Object] Deserialized data
245
+ def self._deserialize(type, value)
246
+ case type.to_sym
247
+ when :Time
248
+ Time.parse(value)
249
+ when :Date
250
+ Date.parse(value)
251
+ when :String
252
+ value.to_s
253
+ when :Integer
254
+ value.to_i
255
+ when :Float
256
+ value.to_f
257
+ when :Boolean
258
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
259
+ true
260
+ else
261
+ false
262
+ end
263
+ when :Object
264
+ # generic object (usually a Hash), return directly
265
+ value
266
+ when /\AArray<(?<inner_type>.+)>\z/
267
+ inner_type = Regexp.last_match[:inner_type]
268
+ value.map { |v| _deserialize(inner_type, v) }
269
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
270
+ k_type = Regexp.last_match[:k_type]
271
+ v_type = Regexp.last_match[:v_type]
272
+ {}.tap do |hash|
273
+ value.each do |k, v|
274
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
275
+ end
276
+ end
277
+ else # model
278
+ # models (e.g. Pet) or oneOf
279
+ klass = OpenapiClient.const_get(type)
280
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
281
+ end
282
+ end
283
+
284
+ # Returns the string representation of the object
285
+ # @return [String] String presentation of the object
286
+ def to_s
287
+ to_hash.to_s
288
+ end
289
+
290
+ # to_body is an alias to to_hash (backward compatibility)
291
+ # @return [Hash] Returns the object in the form of hash
292
+ def to_body
293
+ to_hash
294
+ end
295
+
296
+ # Returns the object in the form of hash
297
+ # @return [Hash] Returns the object in the form of hash
298
+ def to_hash
299
+ hash = {}
300
+ self.class.attribute_map.each_pair do |attr, param|
301
+ value = self.send(attr)
302
+ if value.nil?
303
+ is_nullable = self.class.openapi_nullable.include?(attr)
304
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
305
+ end
306
+
307
+ hash[param] = _to_hash(value)
308
+ end
309
+ hash
310
+ end
311
+
312
+ # Outputs non-array value in the form of hash
313
+ # For object, use to_hash. Otherwise, just return the value
314
+ # @param [Object] value Any valid value
315
+ # @return [Hash] Returns the value in the form of hash
316
+ def _to_hash(value)
317
+ if value.is_a?(Array)
318
+ value.compact.map { |v| _to_hash(v) }
319
+ elsif value.is_a?(Hash)
320
+ {}.tap do |hash|
321
+ value.each { |k, v| hash[k] = _to_hash(v) }
322
+ end
323
+ elsif value.respond_to? :to_hash
324
+ value.to_hash
325
+ else
326
+ value
327
+ end
328
+ end
329
+
330
+ end
331
+
332
+ end