klaviyo_sdk 1.0.0.20220329

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 (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +1121 -0
  4. data/klaviyo_sdk.gemspec +35 -0
  5. data/lib/klaviyo_sdk/api/campaigns_api.rb +717 -0
  6. data/lib/klaviyo_sdk/api/data_privacy_api.rb +86 -0
  7. data/lib/klaviyo_sdk/api/lists_segments_api.rb +1101 -0
  8. data/lib/klaviyo_sdk/api/metrics_api.rb +343 -0
  9. data/lib/klaviyo_sdk/api/profiles_api.rb +381 -0
  10. data/lib/klaviyo_sdk/api/templates_api.rb +555 -0
  11. data/lib/klaviyo_sdk/api/track_identify_api.rb +288 -0
  12. data/lib/klaviyo_sdk/api_client.rb +389 -0
  13. data/lib/klaviyo_sdk/api_error.rb +57 -0
  14. data/lib/klaviyo_sdk/configuration.rb +278 -0
  15. data/lib/klaviyo_sdk/models/campaign.rb +310 -0
  16. data/lib/klaviyo_sdk/models/check_membership_request.rb +244 -0
  17. data/lib/klaviyo_sdk/models/delete_email.rb +218 -0
  18. data/lib/klaviyo_sdk/models/delete_person.rb +218 -0
  19. data/lib/klaviyo_sdk/models/delete_phone.rb +219 -0
  20. data/lib/klaviyo_sdk/models/deprecated_get_list_response.rb +298 -0
  21. data/lib/klaviyo_sdk/models/deprecated_get_list_response_data.rb +263 -0
  22. data/lib/klaviyo_sdk/models/global_exclusion_response_data.rb +274 -0
  23. data/lib/klaviyo_sdk/models/identify_payload.rb +237 -0
  24. data/lib/klaviyo_sdk/models/identify_payload_properties.rb +327 -0
  25. data/lib/klaviyo_sdk/models/inline_object.rb +220 -0
  26. data/lib/klaviyo_sdk/models/inline_object3.rb +226 -0
  27. data/lib/klaviyo_sdk/models/inline_object4.rb +254 -0
  28. data/lib/klaviyo_sdk/models/inline_object5.rb +288 -0
  29. data/lib/klaviyo_sdk/models/metric.rb +265 -0
  30. data/lib/klaviyo_sdk/models/metric_export.rb +285 -0
  31. data/lib/klaviyo_sdk/models/metric_timeline.rb +271 -0
  32. data/lib/klaviyo_sdk/models/metric_timeline_data.rb +294 -0
  33. data/lib/klaviyo_sdk/models/person.rb +389 -0
  34. data/lib/klaviyo_sdk/models/person.rb.bak +389 -0
  35. data/lib/klaviyo_sdk/models/privacy_email.rb +218 -0
  36. data/lib/klaviyo_sdk/models/privacy_id.rb +218 -0
  37. data/lib/klaviyo_sdk/models/privacy_phone.rb +218 -0
  38. data/lib/klaviyo_sdk/models/rendered_template.rb +247 -0
  39. data/lib/klaviyo_sdk/models/template.rb +272 -0
  40. data/lib/klaviyo_sdk/models/track_payload.rb +261 -0
  41. data/lib/klaviyo_sdk/models/track_payload_customer_properties.rb +227 -0
  42. data/lib/klaviyo_sdk/models/track_payload_properties.rb +237 -0
  43. data/lib/klaviyo_sdk/version.rb +15 -0
  44. data/lib/klaviyo_sdk.rb +124 -0
  45. metadata +120 -0
@@ -0,0 +1,294 @@
1
+ =begin
2
+ #Klaviyo API
3
+
4
+ #Empowering creators to own their destiny
5
+
6
+ The version of the OpenAPI document: 2022.03.29
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Client
17
+ class MetricTimelineData
18
+ attr_accessor :object
19
+
20
+ attr_accessor :id
21
+
22
+ attr_accessor :statistic_id
23
+
24
+ attr_accessor :timestamp
25
+
26
+ attr_accessor :event_name
27
+
28
+ attr_accessor :event_properties
29
+
30
+ attr_accessor :datetime
31
+
32
+ attr_accessor :uuid
33
+
34
+ attr_accessor :person
35
+
36
+ # Attribute mapping from ruby-style variable name to JSON key.
37
+ def self.attribute_map
38
+ {
39
+ :'object' => :'object',
40
+ :'id' => :'id',
41
+ :'statistic_id' => :'statistic_id',
42
+ :'timestamp' => :'timestamp',
43
+ :'event_name' => :'event_name',
44
+ :'event_properties' => :'event_properties',
45
+ :'datetime' => :'datetime',
46
+ :'uuid' => :'uuid',
47
+ :'person' => :'person'
48
+ }
49
+ end
50
+
51
+ # Returns all the JSON keys this model knows about
52
+ def self.acceptable_attributes
53
+ attribute_map.values
54
+ end
55
+
56
+ # Attribute type mapping.
57
+ def self.openapi_types
58
+ {
59
+ :'object' => :'String',
60
+ :'id' => :'String',
61
+ :'statistic_id' => :'String',
62
+ :'timestamp' => :'Integer',
63
+ :'event_name' => :'String',
64
+ :'event_properties' => :'Hash<String, Object>',
65
+ :'datetime' => :'String',
66
+ :'uuid' => :'String',
67
+ :'person' => :'Hash<String, Object>'
68
+ }
69
+ end
70
+
71
+ # List of attributes with nullable: true
72
+ def self.openapi_nullable
73
+ Set.new([
74
+ ])
75
+ end
76
+
77
+ # Initializes the object
78
+ # @param [Hash] attributes Model attributes in the form of hash
79
+ def initialize(attributes = {})
80
+ if (!attributes.is_a?(Hash))
81
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Client::MetricTimelineData` initialize method"
82
+ end
83
+
84
+ # check to see if the attribute exists and convert string to symbol for hash key
85
+ attributes = attributes.each_with_object({}) { |(k, v), h|
86
+ if (!self.class.attribute_map.key?(k.to_sym))
87
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Client::MetricTimelineData`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
88
+ end
89
+ h[k.to_sym] = v
90
+ }
91
+
92
+ if attributes.key?(:'object')
93
+ self.object = attributes[:'object']
94
+ end
95
+
96
+ if attributes.key?(:'id')
97
+ self.id = attributes[:'id']
98
+ end
99
+
100
+ if attributes.key?(:'statistic_id')
101
+ self.statistic_id = attributes[:'statistic_id']
102
+ end
103
+
104
+ if attributes.key?(:'timestamp')
105
+ self.timestamp = attributes[:'timestamp']
106
+ end
107
+
108
+ if attributes.key?(:'event_name')
109
+ self.event_name = attributes[:'event_name']
110
+ end
111
+
112
+ if attributes.key?(:'event_properties')
113
+ if (value = attributes[:'event_properties']).is_a?(Hash)
114
+ self.event_properties = value
115
+ end
116
+ end
117
+
118
+ if attributes.key?(:'datetime')
119
+ self.datetime = attributes[:'datetime']
120
+ end
121
+
122
+ if attributes.key?(:'uuid')
123
+ self.uuid = attributes[:'uuid']
124
+ end
125
+
126
+ if attributes.key?(:'person')
127
+ if (value = attributes[:'person']).is_a?(Hash)
128
+ self.person = value
129
+ end
130
+ end
131
+ end
132
+
133
+ # Show invalid properties with the reasons. Usually used together with valid?
134
+ # @return Array for valid properties with the reasons
135
+ def list_invalid_properties
136
+ invalid_properties = Array.new
137
+ invalid_properties
138
+ end
139
+
140
+ # Check to see if the all the properties in the model are valid
141
+ # @return true if the model is valid
142
+ def valid?
143
+ true
144
+ end
145
+
146
+ # Checks equality by comparing each attribute.
147
+ # @param [Object] Object to be compared
148
+ def ==(o)
149
+ return true if self.equal?(o)
150
+ self.class == o.class &&
151
+ object == o.object &&
152
+ id == o.id &&
153
+ statistic_id == o.statistic_id &&
154
+ timestamp == o.timestamp &&
155
+ event_name == o.event_name &&
156
+ event_properties == o.event_properties &&
157
+ datetime == o.datetime &&
158
+ uuid == o.uuid &&
159
+ person == o.person
160
+ end
161
+
162
+ # @see the `==` method
163
+ # @param [Object] Object to be compared
164
+ def eql?(o)
165
+ self == o
166
+ end
167
+
168
+ # Calculates hash code according to all attributes.
169
+ # @return [Integer] Hash code
170
+ def hash
171
+ [object, id, statistic_id, timestamp, event_name, event_properties, datetime, uuid, person].hash
172
+ end
173
+
174
+ # Builds the object from hash
175
+ # @param [Hash] attributes Model attributes in the form of hash
176
+ # @return [Object] Returns the model itself
177
+ def self.build_from_hash(attributes)
178
+ new.build_from_hash(attributes)
179
+ end
180
+
181
+ # Builds the object from hash
182
+ # @param [Hash] attributes Model attributes in the form of hash
183
+ # @return [Object] Returns the model itself
184
+ def build_from_hash(attributes)
185
+ return nil unless attributes.is_a?(Hash)
186
+ self.class.openapi_types.each_pair do |key, type|
187
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
188
+ self.send("#{key}=", nil)
189
+ elsif type =~ /\AArray<(.*)>/i
190
+ # check to ensure the input is an array given that the attribute
191
+ # is documented as an array but the input is not
192
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
193
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
194
+ end
195
+ elsif !attributes[self.class.attribute_map[key]].nil?
196
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
197
+ end
198
+ end
199
+
200
+ self
201
+ end
202
+
203
+ # Deserializes the data based on type
204
+ # @param string type Data type
205
+ # @param string value Value to be deserialized
206
+ # @return [Object] Deserialized data
207
+ def _deserialize(type, value)
208
+ case type.to_sym
209
+ when :Time
210
+ Time.parse(value)
211
+ when :Date
212
+ Date.parse(value)
213
+ when :String
214
+ value.to_s
215
+ when :Integer
216
+ value.to_i
217
+ when :Float
218
+ value.to_f
219
+ when :Boolean
220
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
221
+ true
222
+ else
223
+ false
224
+ end
225
+ when :Object
226
+ # generic object (usually a Hash), return directly
227
+ value
228
+ when /\AArray<(?<inner_type>.+)>\z/
229
+ inner_type = Regexp.last_match[:inner_type]
230
+ value.map { |v| _deserialize(inner_type, v) }
231
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
232
+ k_type = Regexp.last_match[:k_type]
233
+ v_type = Regexp.last_match[:v_type]
234
+ {}.tap do |hash|
235
+ value.each do |k, v|
236
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
237
+ end
238
+ end
239
+ else # model
240
+ # models (e.g. Pet) or oneOf
241
+ klass = Client.const_get(type)
242
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
243
+ end
244
+ end
245
+
246
+ # Returns the string representation of the object
247
+ # @return [String] String presentation of the object
248
+ def to_s
249
+ to_hash.to_s
250
+ end
251
+
252
+ # to_body is an alias to to_hash (backward compatibility)
253
+ # @return [Hash] Returns the object in the form of hash
254
+ def to_body
255
+ to_hash
256
+ end
257
+
258
+ # Returns the object in the form of hash
259
+ # @return [Hash] Returns the object in the form of hash
260
+ def to_hash
261
+ hash = {}
262
+ self.class.attribute_map.each_pair do |attr, param|
263
+ value = self.send(attr)
264
+ if value.nil?
265
+ is_nullable = self.class.openapi_nullable.include?(attr)
266
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
267
+ end
268
+
269
+ hash[param] = _to_hash(value)
270
+ end
271
+ hash
272
+ end
273
+
274
+ # Outputs non-array value in the form of hash
275
+ # For object, use to_hash. Otherwise, just return the value
276
+ # @param [Object] value Any valid value
277
+ # @return [Hash] Returns the value in the form of hash
278
+ def _to_hash(value)
279
+ if value.is_a?(Array)
280
+ value.compact.map { |v| _to_hash(v) }
281
+ elsif value.is_a?(Hash)
282
+ {}.tap do |hash|
283
+ value.each { |k, v| hash[k] = _to_hash(v) }
284
+ end
285
+ elsif value.respond_to? :to_hash
286
+ value.to_hash
287
+ else
288
+ value
289
+ end
290
+ end
291
+
292
+ end
293
+
294
+ end
@@ -0,0 +1,389 @@
1
+ =begin
2
+ #Klaviyo API
3
+
4
+ #Empowering creators to own their destiny
5
+
6
+ The version of the OpenAPI document: 2022.03.29
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Client
17
+ class Person
18
+ attr_accessor :object
19
+
20
+ attr_accessor :id
21
+
22
+ attr_accessor :_address1
23
+
24
+ attr_accessor :_address2
25
+
26
+ attr_accessor :_city
27
+
28
+ attr_accessor :_country
29
+
30
+ attr_accessor :_latitude
31
+
32
+ attr_accessor :_longitude
33
+
34
+ attr_accessor :_region
35
+
36
+ attr_accessor :_zip
37
+
38
+ attr_accessor :_email
39
+
40
+ attr_accessor :_title
41
+
42
+ attr_accessor :_phone_number
43
+
44
+ attr_accessor :_organization
45
+
46
+ attr_accessor :_first_name
47
+
48
+ attr_accessor :_last_name
49
+
50
+ attr_accessor :_timezone
51
+
52
+ attr_accessor :_id
53
+
54
+ attr_accessor :created
55
+
56
+ attr_accessor :updated
57
+
58
+ # Attribute mapping from ruby-style variable name to JSON key.
59
+ def self.attribute_map
60
+ {
61
+ :'object' => :'object',
62
+ :'id' => :'id',
63
+ :'_address1' => :'$address1',
64
+ :'_address2' => :'$address2',
65
+ :'_city' => :'$city',
66
+ :'_country' => :'$country',
67
+ :'_latitude' => :'$latitude',
68
+ :'_longitude' => :'$longitude',
69
+ :'_region' => :'$region',
70
+ :'_zip' => :'$zip',
71
+ :'_email' => :'$email',
72
+ :'_title' => :'$title',
73
+ :'_phone_number' => :'$phone_number',
74
+ :'_organization' => :'$organization',
75
+ :'_first_name' => :'$first_name',
76
+ :'_last_name' => :'$last_name',
77
+ :'_timezone' => :'$timezone',
78
+ :'_id' => :'$id',
79
+ :'created' => :'created',
80
+ :'updated' => :'updated'
81
+ }
82
+ end
83
+
84
+ # Returns all the JSON keys this model knows about
85
+ def self.acceptable_attributes
86
+ attribute_map.values
87
+ end
88
+
89
+ # Attribute type mapping.
90
+ def self.openapi_types
91
+ {
92
+ :'object' => :'String',
93
+ :'id' => :'String',
94
+ :'_address1' => :'String',
95
+ :'_address2' => :'String',
96
+ :'_city' => :'String',
97
+ :'_country' => :'String',
98
+ :'_latitude' => :'String',
99
+ :'_longitude' => :'String',
100
+ :'_region' => :'String',
101
+ :'_zip' => :'String',
102
+ :'_email' => :'String',
103
+ :'_title' => :'String',
104
+ :'_phone_number' => :'String',
105
+ :'_organization' => :'String',
106
+ :'_first_name' => :'String',
107
+ :'_last_name' => :'String',
108
+ :'_timezone' => :'String',
109
+ :'_id' => :'String',
110
+ :'created' => :'String',
111
+ :'updated' => :'String'
112
+ }
113
+ end
114
+
115
+ # List of attributes with nullable: true
116
+ def self.openapi_nullable
117
+ Set.new([
118
+ ])
119
+ end
120
+
121
+ # Initializes the object
122
+ # @param [Hash] attributes Model attributes in the form of hash
123
+ def initialize(attributes = {})
124
+ if (!attributes.is_a?(Hash))
125
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Client::Person` initialize method"
126
+ end
127
+
128
+ # check to see if the attribute exists and convert string to symbol for hash key
129
+ attributes = attributes.each_with_object({}) { |(k, v), h|
130
+ if (!self.class.attribute_map.key?(k.to_sym))
131
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Client::Person`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
132
+ end
133
+ h[k.to_sym] = v
134
+ }
135
+
136
+ if attributes.key?(:'object')
137
+ self.object = attributes[:'object']
138
+ end
139
+
140
+ if attributes.key?(:'id')
141
+ self.id = attributes[:'id']
142
+ end
143
+
144
+ if attributes.key?(:'_address1')
145
+ self._address1 = attributes[:'_address1']
146
+ end
147
+
148
+ if attributes.key?(:'_address2')
149
+ self._address2 = attributes[:'_address2']
150
+ end
151
+
152
+ if attributes.key?(:'_city')
153
+ self._city = attributes[:'_city']
154
+ end
155
+
156
+ if attributes.key?(:'_country')
157
+ self._country = attributes[:'_country']
158
+ end
159
+
160
+ if attributes.key?(:'_latitude')
161
+ self._latitude = attributes[:'_latitude']
162
+ end
163
+
164
+ if attributes.key?(:'_longitude')
165
+ self._longitude = attributes[:'_longitude']
166
+ end
167
+
168
+ if attributes.key?(:'_region')
169
+ self._region = attributes[:'_region']
170
+ end
171
+
172
+ if attributes.key?(:'_zip')
173
+ self._zip = attributes[:'_zip']
174
+ end
175
+
176
+ if attributes.key?(:'_email')
177
+ self._email = attributes[:'_email']
178
+ end
179
+
180
+ if attributes.key?(:'_title')
181
+ self._title = attributes[:'_title']
182
+ end
183
+
184
+ if attributes.key?(:'_phone_number')
185
+ self._phone_number = attributes[:'_phone_number']
186
+ end
187
+
188
+ if attributes.key?(:'_organization')
189
+ self._organization = attributes[:'_organization']
190
+ end
191
+
192
+ if attributes.key?(:'_first_name')
193
+ self._first_name = attributes[:'_first_name']
194
+ end
195
+
196
+ if attributes.key?(:'_last_name')
197
+ self._last_name = attributes[:'_last_name']
198
+ end
199
+
200
+ if attributes.key?(:'_timezone')
201
+ self._timezone = attributes[:'_timezone']
202
+ end
203
+
204
+ if attributes.key?(:'_id')
205
+ self._id = attributes[:'_id']
206
+ end
207
+
208
+ if attributes.key?(:'created')
209
+ self.created = attributes[:'created']
210
+ end
211
+
212
+ if attributes.key?(:'updated')
213
+ self.updated = attributes[:'updated']
214
+ end
215
+ end
216
+
217
+ # Show invalid properties with the reasons. Usually used together with valid?
218
+ # @return Array for valid properties with the reasons
219
+ def list_invalid_properties
220
+ invalid_properties = Array.new
221
+ invalid_properties
222
+ end
223
+
224
+ # Check to see if the all the properties in the model are valid
225
+ # @return true if the model is valid
226
+ def valid?
227
+ true
228
+ end
229
+
230
+ # Checks equality by comparing each attribute.
231
+ # @param [Object] Object to be compared
232
+ def ==(o)
233
+ return true if self.equal?(o)
234
+ self.class == o.class &&
235
+ object == o.object &&
236
+ id == o.id &&
237
+ _address1 == o._address1 &&
238
+ _address2 == o._address2 &&
239
+ _city == o._city &&
240
+ _country == o._country &&
241
+ _latitude == o._latitude &&
242
+ _longitude == o._longitude &&
243
+ _region == o._region &&
244
+ _zip == o._zip &&
245
+ _email == o._email &&
246
+ _title == o._title &&
247
+ _phone_number == o._phone_number &&
248
+ _organization == o._organization &&
249
+ _first_name == o._first_name &&
250
+ _last_name == o._last_name &&
251
+ _timezone == o._timezone &&
252
+ _id == o._id &&
253
+ created == o.created &&
254
+ updated == o.updated
255
+ end
256
+
257
+ # @see the `==` method
258
+ # @param [Object] Object to be compared
259
+ def eql?(o)
260
+ self == o
261
+ end
262
+
263
+ # Calculates hash code according to all attributes.
264
+ # @return [Integer] Hash code
265
+ def hash
266
+ [object, id, _address1, _address2, _city, _country, _latitude, _longitude, _region, _zip, _email, _title, _phone_number, _organization, _first_name, _last_name, _timezone, _id, created, updated].hash
267
+ end
268
+
269
+ # Builds the object from hash
270
+ # @param [Hash] attributes Model attributes in the form of hash
271
+ # @return [Object] Returns the model itself
272
+ def self.build_from_hash(attributes)
273
+ new.build_from_hash(attributes)
274
+ end
275
+
276
+ # Builds the object from hash
277
+ # @param [Hash] attributes Model attributes in the form of hash
278
+ # @return [Object] Returns the model itself
279
+ def build_from_hash(attributes)
280
+ return nil unless attributes.is_a?(Hash)
281
+ self.class.openapi_types.each_pair do |key, type|
282
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
283
+ self.send("#{key}=", nil)
284
+ elsif type =~ /\AArray<(.*)>/i
285
+ # check to ensure the input is an array given that the attribute
286
+ # is documented as an array but the input is not
287
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
288
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
289
+ end
290
+ elsif !attributes[self.class.attribute_map[key]].nil?
291
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
292
+ end
293
+ end
294
+
295
+ self
296
+ end
297
+
298
+ # Deserializes the data based on type
299
+ # @param string type Data type
300
+ # @param string value Value to be deserialized
301
+ # @return [Object] Deserialized data
302
+ def _deserialize(type, value)
303
+ case type.to_sym
304
+ when :Time
305
+ Time.parse(value)
306
+ when :Date
307
+ Date.parse(value)
308
+ when :String
309
+ value.to_s
310
+ when :Integer
311
+ value.to_i
312
+ when :Float
313
+ value.to_f
314
+ when :Boolean
315
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
316
+ true
317
+ else
318
+ false
319
+ end
320
+ when :Object
321
+ # generic object (usually a Hash), return directly
322
+ value
323
+ when /\AArray<(?<inner_type>.+)>\z/
324
+ inner_type = Regexp.last_match[:inner_type]
325
+ value.map { |v| _deserialize(inner_type, v) }
326
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
327
+ k_type = Regexp.last_match[:k_type]
328
+ v_type = Regexp.last_match[:v_type]
329
+ {}.tap do |hash|
330
+ value.each do |k, v|
331
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
332
+ end
333
+ end
334
+ else # model
335
+ # models (e.g. Pet) or oneOf
336
+ klass = Client.const_get(type)
337
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
338
+ end
339
+ end
340
+
341
+ # Returns the string representation of the object
342
+ # @return [String] String presentation of the object
343
+ def to_s
344
+ to_hash.to_s
345
+ end
346
+
347
+ # to_body is an alias to to_hash (backward compatibility)
348
+ # @return [Hash] Returns the object in the form of hash
349
+ def to_body
350
+ to_hash
351
+ end
352
+
353
+ # Returns the object in the form of hash
354
+ # @return [Hash] Returns the object in the form of hash
355
+ def to_hash
356
+ hash = {}
357
+ self.class.attribute_map.each_pair do |attr, param|
358
+ value = self.send(attr)
359
+ if value.nil?
360
+ is_nullable = self.class.openapi_nullable.include?(attr)
361
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
362
+ end
363
+
364
+ hash[param] = _to_hash(value)
365
+ end
366
+ hash
367
+ end
368
+
369
+ # Outputs non-array value in the form of hash
370
+ # For object, use to_hash. Otherwise, just return the value
371
+ # @param [Object] value Any valid value
372
+ # @return [Hash] Returns the value in the form of hash
373
+ def _to_hash(value)
374
+ if value.is_a?(Array)
375
+ value.compact.map { |v| _to_hash(v) }
376
+ elsif value.is_a?(Hash)
377
+ {}.tap do |hash|
378
+ value.each { |k, v| hash[k] = _to_hash(v) }
379
+ end
380
+ elsif value.respond_to? :to_hash
381
+ value.to_hash
382
+ else
383
+ value
384
+ end
385
+ end
386
+
387
+ end
388
+
389
+ end