braze_api_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/LICENSE.md +9 -0
  4. data/README.md +191 -0
  5. data/Rakefile +10 -0
  6. data/braze_api_client.gemspec +38 -0
  7. data/docs/Attributes.md +58 -0
  8. data/docs/AttributesArray.md +18 -0
  9. data/docs/AttributesCurrentLocation.md +20 -0
  10. data/docs/AttributesFacebook.md +22 -0
  11. data/docs/AttributesPushTokens.md +22 -0
  12. data/docs/AttributesTwitter.md +26 -0
  13. data/docs/Event.md +26 -0
  14. data/docs/EventsArray.md +18 -0
  15. data/docs/GeneralError.md +20 -0
  16. data/docs/Identifier.md +51 -0
  17. data/docs/IdentifierOneOf.md +18 -0
  18. data/docs/IdentifierOneOf1.md +18 -0
  19. data/docs/IdentifierOneOf2.md +18 -0
  20. data/docs/RestApi.md +427 -0
  21. data/docs/UsersTrackRequest.md +18 -0
  22. data/docs/UsersTrackResponse.md +24 -0
  23. data/git_push.sh +16 -0
  24. data/lib/braze_api_client/api/rest_api.rb +400 -0
  25. data/lib/braze_api_client/api_client.rb +390 -0
  26. data/lib/braze_api_client/api_error.rb +57 -0
  27. data/lib/braze_api_client/configuration.rb +294 -0
  28. data/lib/braze_api_client/models/attributes.rb +458 -0
  29. data/lib/braze_api_client/models/attributes_array.rb +225 -0
  30. data/lib/braze_api_client/models/attributes_current_location.rb +227 -0
  31. data/lib/braze_api_client/models/attributes_facebook.rb +238 -0
  32. data/lib/braze_api_client/models/attributes_push_tokens.rb +246 -0
  33. data/lib/braze_api_client/models/attributes_twitter.rb +254 -0
  34. data/lib/braze_api_client/models/event.rb +264 -0
  35. data/lib/braze_api_client/models/events_array.rb +220 -0
  36. data/lib/braze_api_client/models/general_error.rb +227 -0
  37. data/lib/braze_api_client/models/identifier.rb +106 -0
  38. data/lib/braze_api_client/models/identifier_one_of.rb +223 -0
  39. data/lib/braze_api_client/models/identifier_one_of1.rb +223 -0
  40. data/lib/braze_api_client/models/identifier_one_of2.rb +223 -0
  41. data/lib/braze_api_client/models/users_track_request.rb +245 -0
  42. data/lib/braze_api_client/models/users_track_response.rb +245 -0
  43. data/lib/braze_api_client/version.rb +15 -0
  44. data/lib/braze_api_client.rb +55 -0
  45. data/spec/api/rest_api_spec.rb +101 -0
  46. data/spec/api_client_spec.rb +226 -0
  47. data/spec/configuration_spec.rb +42 -0
  48. data/spec/models/attributes_array_spec.rb +34 -0
  49. data/spec/models/attributes_current_location_spec.rb +40 -0
  50. data/spec/models/attributes_facebook_spec.rb +46 -0
  51. data/spec/models/attributes_push_tokens_spec.rb +46 -0
  52. data/spec/models/attributes_spec.rb +166 -0
  53. data/spec/models/attributes_twitter_spec.rb +58 -0
  54. data/spec/models/event_spec.rb +58 -0
  55. data/spec/models/events_array_spec.rb +34 -0
  56. data/spec/models/general_error_spec.rb +40 -0
  57. data/spec/models/identifier_one_of1_spec.rb +34 -0
  58. data/spec/models/identifier_one_of2_spec.rb +34 -0
  59. data/spec/models/identifier_one_of_spec.rb +34 -0
  60. data/spec/models/identifier_spec.rb +31 -0
  61. data/spec/models/users_track_request_spec.rb +34 -0
  62. data/spec/models/users_track_response_spec.rb +52 -0
  63. data/spec/spec_helper.rb +111 -0
  64. metadata +164 -0
@@ -0,0 +1,458 @@
1
+ =begin
2
+ #Braze
3
+
4
+ #Track users, send messages, export data, and more
5
+
6
+ The version of the OpenAPI document: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BrazeClient
17
+ class Attributes
18
+ attr_accessor :country
19
+
20
+ attr_accessor :current_location
21
+
22
+ attr_accessor :date_of_first_session
23
+
24
+ attr_accessor :date_of_last_session
25
+
26
+ attr_accessor :dob
27
+
28
+ attr_accessor :email
29
+
30
+ attr_accessor :email_subscribe
31
+
32
+ attr_accessor :email_open_tracking_disabled
33
+
34
+ attr_accessor :email_click_tracking_disabled
35
+
36
+ attr_accessor :facebook
37
+
38
+ attr_accessor :first_name
39
+
40
+ attr_accessor :gender
41
+
42
+ attr_accessor :home_city
43
+
44
+ attr_accessor :language
45
+
46
+ attr_accessor :last_name
47
+
48
+ attr_accessor :marked_email_as_spam_at
49
+
50
+ attr_accessor :phone
51
+
52
+ attr_accessor :push_subscribe
53
+
54
+ attr_accessor :push_tokens
55
+
56
+ attr_accessor :time_zone
57
+
58
+ attr_accessor :twitter
59
+
60
+ class EnumAttributeValidator
61
+ attr_reader :datatype
62
+ attr_reader :allowable_values
63
+
64
+ def initialize(datatype, allowable_values)
65
+ @allowable_values = allowable_values.map do |value|
66
+ case datatype.to_s
67
+ when /Integer/i
68
+ value.to_i
69
+ when /Float/i
70
+ value.to_f
71
+ else
72
+ value
73
+ end
74
+ end
75
+ end
76
+
77
+ def valid?(value)
78
+ !value || allowable_values.include?(value)
79
+ end
80
+ end
81
+
82
+ # Attribute mapping from ruby-style variable name to JSON key.
83
+ def self.attribute_map
84
+ {
85
+ :'country' => :'country',
86
+ :'current_location' => :'current_location',
87
+ :'date_of_first_session' => :'date_of_first_session',
88
+ :'date_of_last_session' => :'date_of_last_session',
89
+ :'dob' => :'dob',
90
+ :'email' => :'email',
91
+ :'email_subscribe' => :'email_subscribe',
92
+ :'email_open_tracking_disabled' => :'email_open_tracking_disabled',
93
+ :'email_click_tracking_disabled' => :'email_click_tracking_disabled',
94
+ :'facebook' => :'facebook',
95
+ :'first_name' => :'first_name',
96
+ :'gender' => :'gender',
97
+ :'home_city' => :'home_city',
98
+ :'language' => :'language',
99
+ :'last_name' => :'last_name',
100
+ :'marked_email_as_spam_at' => :'marked_email_as_spam_at',
101
+ :'phone' => :'phone',
102
+ :'push_subscribe' => :'push_subscribe',
103
+ :'push_tokens' => :'push_tokens',
104
+ :'time_zone' => :'time_zone',
105
+ :'twitter' => :'twitter'
106
+ }
107
+ end
108
+
109
+ # Returns all the JSON keys this model knows about
110
+ def self.acceptable_attributes
111
+ attribute_map.values
112
+ end
113
+
114
+ # Attribute type mapping.
115
+ def self.openapi_types
116
+ {
117
+ :'country' => :'String',
118
+ :'current_location' => :'AttributesCurrentLocation',
119
+ :'date_of_first_session' => :'Time',
120
+ :'date_of_last_session' => :'Time',
121
+ :'dob' => :'Date',
122
+ :'email' => :'String',
123
+ :'email_subscribe' => :'String',
124
+ :'email_open_tracking_disabled' => :'Boolean',
125
+ :'email_click_tracking_disabled' => :'Boolean',
126
+ :'facebook' => :'AttributesFacebook',
127
+ :'first_name' => :'String',
128
+ :'gender' => :'String',
129
+ :'home_city' => :'String',
130
+ :'language' => :'String',
131
+ :'last_name' => :'String',
132
+ :'marked_email_as_spam_at' => :'Time',
133
+ :'phone' => :'String',
134
+ :'push_subscribe' => :'String',
135
+ :'push_tokens' => :'Array<AttributesPushTokens>',
136
+ :'time_zone' => :'String',
137
+ :'twitter' => :'AttributesTwitter'
138
+ }
139
+ end
140
+
141
+ # List of attributes with nullable: true
142
+ def self.openapi_nullable
143
+ Set.new([
144
+ ])
145
+ end
146
+
147
+ # Initializes the object
148
+ # @param [Hash] attributes Model attributes in the form of hash
149
+ def initialize(attributes = {})
150
+ if (!attributes.is_a?(Hash))
151
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BrazeClient::Attributes` initialize method"
152
+ end
153
+
154
+ # check to see if the attribute exists and convert string to symbol for hash key
155
+ attributes = attributes.each_with_object({}) { |(k, v), h|
156
+ if (!self.class.attribute_map.key?(k.to_sym))
157
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BrazeClient::Attributes`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
158
+ end
159
+ h[k.to_sym] = v
160
+ }
161
+
162
+ if attributes.key?(:'country')
163
+ self.country = attributes[:'country']
164
+ end
165
+
166
+ if attributes.key?(:'current_location')
167
+ self.current_location = attributes[:'current_location']
168
+ end
169
+
170
+ if attributes.key?(:'date_of_first_session')
171
+ self.date_of_first_session = attributes[:'date_of_first_session']
172
+ end
173
+
174
+ if attributes.key?(:'date_of_last_session')
175
+ self.date_of_last_session = attributes[:'date_of_last_session']
176
+ end
177
+
178
+ if attributes.key?(:'dob')
179
+ self.dob = attributes[:'dob']
180
+ end
181
+
182
+ if attributes.key?(:'email')
183
+ self.email = attributes[:'email']
184
+ end
185
+
186
+ if attributes.key?(:'email_subscribe')
187
+ self.email_subscribe = attributes[:'email_subscribe']
188
+ end
189
+
190
+ if attributes.key?(:'email_open_tracking_disabled')
191
+ self.email_open_tracking_disabled = attributes[:'email_open_tracking_disabled']
192
+ end
193
+
194
+ if attributes.key?(:'email_click_tracking_disabled')
195
+ self.email_click_tracking_disabled = attributes[:'email_click_tracking_disabled']
196
+ end
197
+
198
+ if attributes.key?(:'facebook')
199
+ self.facebook = attributes[:'facebook']
200
+ end
201
+
202
+ if attributes.key?(:'first_name')
203
+ self.first_name = attributes[:'first_name']
204
+ end
205
+
206
+ if attributes.key?(:'gender')
207
+ self.gender = attributes[:'gender']
208
+ end
209
+
210
+ if attributes.key?(:'home_city')
211
+ self.home_city = attributes[:'home_city']
212
+ end
213
+
214
+ if attributes.key?(:'language')
215
+ self.language = attributes[:'language']
216
+ end
217
+
218
+ if attributes.key?(:'last_name')
219
+ self.last_name = attributes[:'last_name']
220
+ end
221
+
222
+ if attributes.key?(:'marked_email_as_spam_at')
223
+ self.marked_email_as_spam_at = attributes[:'marked_email_as_spam_at']
224
+ end
225
+
226
+ if attributes.key?(:'phone')
227
+ self.phone = attributes[:'phone']
228
+ end
229
+
230
+ if attributes.key?(:'push_subscribe')
231
+ self.push_subscribe = attributes[:'push_subscribe']
232
+ end
233
+
234
+ if attributes.key?(:'push_tokens')
235
+ if (value = attributes[:'push_tokens']).is_a?(Array)
236
+ self.push_tokens = value
237
+ end
238
+ end
239
+
240
+ if attributes.key?(:'time_zone')
241
+ self.time_zone = attributes[:'time_zone']
242
+ end
243
+
244
+ if attributes.key?(:'twitter')
245
+ self.twitter = attributes[:'twitter']
246
+ end
247
+ end
248
+
249
+ # Show invalid properties with the reasons. Usually used together with valid?
250
+ # @return Array for valid properties with the reasons
251
+ def list_invalid_properties
252
+ invalid_properties = Array.new
253
+ invalid_properties
254
+ end
255
+
256
+ # Check to see if the all the properties in the model are valid
257
+ # @return true if the model is valid
258
+ def valid?
259
+ email_subscribe_validator = EnumAttributeValidator.new('String', ["opted_in", "unsubscribed", "subscribed"])
260
+ return false unless email_subscribe_validator.valid?(@email_subscribe)
261
+ gender_validator = EnumAttributeValidator.new('String', ["M", "F", "O", "N", "P", "null"])
262
+ return false unless gender_validator.valid?(@gender)
263
+ push_subscribe_validator = EnumAttributeValidator.new('String', ["opted_in", "unsubscribed", "subscribed"])
264
+ return false unless push_subscribe_validator.valid?(@push_subscribe)
265
+ true
266
+ end
267
+
268
+ # Custom attribute writer method checking allowed values (enum).
269
+ # @param [Object] email_subscribe Object to be assigned
270
+ def email_subscribe=(email_subscribe)
271
+ validator = EnumAttributeValidator.new('String', ["opted_in", "unsubscribed", "subscribed"])
272
+ unless validator.valid?(email_subscribe)
273
+ fail ArgumentError, "invalid value for \"email_subscribe\", must be one of #{validator.allowable_values}."
274
+ end
275
+ @email_subscribe = email_subscribe
276
+ end
277
+
278
+ # Custom attribute writer method checking allowed values (enum).
279
+ # @param [Object] gender Object to be assigned
280
+ def gender=(gender)
281
+ validator = EnumAttributeValidator.new('String', ["M", "F", "O", "N", "P", "null"])
282
+ unless validator.valid?(gender)
283
+ fail ArgumentError, "invalid value for \"gender\", must be one of #{validator.allowable_values}."
284
+ end
285
+ @gender = gender
286
+ end
287
+
288
+ # Custom attribute writer method checking allowed values (enum).
289
+ # @param [Object] push_subscribe Object to be assigned
290
+ def push_subscribe=(push_subscribe)
291
+ validator = EnumAttributeValidator.new('String', ["opted_in", "unsubscribed", "subscribed"])
292
+ unless validator.valid?(push_subscribe)
293
+ fail ArgumentError, "invalid value for \"push_subscribe\", must be one of #{validator.allowable_values}."
294
+ end
295
+ @push_subscribe = push_subscribe
296
+ end
297
+
298
+ # Checks equality by comparing each attribute.
299
+ # @param [Object] Object to be compared
300
+ def ==(o)
301
+ return true if self.equal?(o)
302
+ self.class == o.class &&
303
+ country == o.country &&
304
+ current_location == o.current_location &&
305
+ date_of_first_session == o.date_of_first_session &&
306
+ date_of_last_session == o.date_of_last_session &&
307
+ dob == o.dob &&
308
+ email == o.email &&
309
+ email_subscribe == o.email_subscribe &&
310
+ email_open_tracking_disabled == o.email_open_tracking_disabled &&
311
+ email_click_tracking_disabled == o.email_click_tracking_disabled &&
312
+ facebook == o.facebook &&
313
+ first_name == o.first_name &&
314
+ gender == o.gender &&
315
+ home_city == o.home_city &&
316
+ language == o.language &&
317
+ last_name == o.last_name &&
318
+ marked_email_as_spam_at == o.marked_email_as_spam_at &&
319
+ phone == o.phone &&
320
+ push_subscribe == o.push_subscribe &&
321
+ push_tokens == o.push_tokens &&
322
+ time_zone == o.time_zone &&
323
+ twitter == o.twitter
324
+ end
325
+
326
+ # @see the `==` method
327
+ # @param [Object] Object to be compared
328
+ def eql?(o)
329
+ self == o
330
+ end
331
+
332
+ # Calculates hash code according to all attributes.
333
+ # @return [Integer] Hash code
334
+ def hash
335
+ [country, current_location, date_of_first_session, date_of_last_session, dob, email, email_subscribe, email_open_tracking_disabled, email_click_tracking_disabled, facebook, first_name, gender, home_city, language, last_name, marked_email_as_spam_at, phone, push_subscribe, push_tokens, time_zone, twitter].hash
336
+ end
337
+
338
+ # Builds the object from hash
339
+ # @param [Hash] attributes Model attributes in the form of hash
340
+ # @return [Object] Returns the model itself
341
+ def self.build_from_hash(attributes)
342
+ new.build_from_hash(attributes)
343
+ end
344
+
345
+ # Builds the object from hash
346
+ # @param [Hash] attributes Model attributes in the form of hash
347
+ # @return [Object] Returns the model itself
348
+ def build_from_hash(attributes)
349
+ return nil unless attributes.is_a?(Hash)
350
+ self.class.openapi_types.each_pair do |key, type|
351
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
352
+ self.send("#{key}=", nil)
353
+ elsif type =~ /\AArray<(.*)>/i
354
+ # check to ensure the input is an array given that the attribute
355
+ # is documented as an array but the input is not
356
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
357
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
358
+ end
359
+ elsif !attributes[self.class.attribute_map[key]].nil?
360
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
361
+ end
362
+ end
363
+
364
+ self
365
+ end
366
+
367
+ # Deserializes the data based on type
368
+ # @param string type Data type
369
+ # @param string value Value to be deserialized
370
+ # @return [Object] Deserialized data
371
+ def _deserialize(type, value)
372
+ case type.to_sym
373
+ when :Time
374
+ Time.parse(value)
375
+ when :Date
376
+ Date.parse(value)
377
+ when :String
378
+ value.to_s
379
+ when :Integer
380
+ value.to_i
381
+ when :Float
382
+ value.to_f
383
+ when :Boolean
384
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
385
+ true
386
+ else
387
+ false
388
+ end
389
+ when :Object
390
+ # generic object (usually a Hash), return directly
391
+ value
392
+ when /\AArray<(?<inner_type>.+)>\z/
393
+ inner_type = Regexp.last_match[:inner_type]
394
+ value.map { |v| _deserialize(inner_type, v) }
395
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
396
+ k_type = Regexp.last_match[:k_type]
397
+ v_type = Regexp.last_match[:v_type]
398
+ {}.tap do |hash|
399
+ value.each do |k, v|
400
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
401
+ end
402
+ end
403
+ else # model
404
+ # models (e.g. Pet) or oneOf
405
+ klass = BrazeClient.const_get(type)
406
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
407
+ end
408
+ end
409
+
410
+ # Returns the string representation of the object
411
+ # @return [String] String presentation of the object
412
+ def to_s
413
+ to_hash.to_s
414
+ end
415
+
416
+ # to_body is an alias to to_hash (backward compatibility)
417
+ # @return [Hash] Returns the object in the form of hash
418
+ def to_body
419
+ to_hash
420
+ end
421
+
422
+ # Returns the object in the form of hash
423
+ # @return [Hash] Returns the object in the form of hash
424
+ def to_hash
425
+ hash = {}
426
+ self.class.attribute_map.each_pair do |attr, param|
427
+ value = self.send(attr)
428
+ if value.nil?
429
+ is_nullable = self.class.openapi_nullable.include?(attr)
430
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
431
+ end
432
+
433
+ hash[param] = _to_hash(value)
434
+ end
435
+ hash
436
+ end
437
+
438
+ # Outputs non-array value in the form of hash
439
+ # For object, use to_hash. Otherwise, just return the value
440
+ # @param [Object] value Any valid value
441
+ # @return [Hash] Returns the value in the form of hash
442
+ def _to_hash(value)
443
+ if value.is_a?(Array)
444
+ value.compact.map { |v| _to_hash(v) }
445
+ elsif value.is_a?(Hash)
446
+ {}.tap do |hash|
447
+ value.each { |k, v| hash[k] = _to_hash(v) }
448
+ end
449
+ elsif value.respond_to? :to_hash
450
+ value.to_hash
451
+ else
452
+ value
453
+ end
454
+ end
455
+
456
+ end
457
+
458
+ end
@@ -0,0 +1,225 @@
1
+ =begin
2
+ #Braze
3
+
4
+ #Track users, send messages, export data, and more
5
+
6
+ The version of the OpenAPI document: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module BrazeClient
17
+ class AttributesArray
18
+ attr_accessor :attributes
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'attributes' => :'attributes'
24
+ }
25
+ end
26
+
27
+ # Returns all the JSON keys this model knows about
28
+ def self.acceptable_attributes
29
+ attribute_map.values
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'attributes' => :'Array<Attributes>'
36
+ }
37
+ end
38
+
39
+ # List of attributes with nullable: true
40
+ def self.openapi_nullable
41
+ Set.new([
42
+ ])
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ if (!attributes.is_a?(Hash))
49
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BrazeClient::AttributesArray` initialize method"
50
+ end
51
+
52
+ # check to see if the attribute exists and convert string to symbol for hash key
53
+ attributes = attributes.each_with_object({}) { |(k, v), h|
54
+ if (!self.class.attribute_map.key?(k.to_sym))
55
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BrazeClient::AttributesArray`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
56
+ end
57
+ h[k.to_sym] = v
58
+ }
59
+
60
+ if attributes.key?(:'attributes')
61
+ if (value = attributes[:'attributes']).is_a?(Array)
62
+ self.attributes = value
63
+ end
64
+ end
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ invalid_properties = Array.new
71
+ if @attributes.nil?
72
+ invalid_properties.push('invalid value for "attributes", attributes cannot be nil.')
73
+ end
74
+
75
+ invalid_properties
76
+ end
77
+
78
+ # Check to see if the all the properties in the model are valid
79
+ # @return true if the model is valid
80
+ def valid?
81
+ return false if @attributes.nil?
82
+ true
83
+ end
84
+
85
+ # Checks equality by comparing each attribute.
86
+ # @param [Object] Object to be compared
87
+ def ==(o)
88
+ return true if self.equal?(o)
89
+ self.class == o.class &&
90
+ attributes == o.attributes
91
+ end
92
+
93
+ # @see the `==` method
94
+ # @param [Object] Object to be compared
95
+ def eql?(o)
96
+ self == o
97
+ end
98
+
99
+ # Calculates hash code according to all attributes.
100
+ # @return [Integer] Hash code
101
+ def hash
102
+ [attributes].hash
103
+ end
104
+
105
+ # Builds the object from hash
106
+ # @param [Hash] attributes Model attributes in the form of hash
107
+ # @return [Object] Returns the model itself
108
+ def self.build_from_hash(attributes)
109
+ new.build_from_hash(attributes)
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def build_from_hash(attributes)
116
+ return nil unless attributes.is_a?(Hash)
117
+ self.class.openapi_types.each_pair do |key, type|
118
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
119
+ self.send("#{key}=", nil)
120
+ elsif type =~ /\AArray<(.*)>/i
121
+ # check to ensure the input is an array given that the attribute
122
+ # is documented as an array but the input is not
123
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
124
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
125
+ end
126
+ elsif !attributes[self.class.attribute_map[key]].nil?
127
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
128
+ end
129
+ end
130
+
131
+ self
132
+ end
133
+
134
+ # Deserializes the data based on type
135
+ # @param string type Data type
136
+ # @param string value Value to be deserialized
137
+ # @return [Object] Deserialized data
138
+ def _deserialize(type, value)
139
+ case type.to_sym
140
+ when :Time
141
+ Time.parse(value)
142
+ when :Date
143
+ Date.parse(value)
144
+ when :String
145
+ value.to_s
146
+ when :Integer
147
+ value.to_i
148
+ when :Float
149
+ value.to_f
150
+ when :Boolean
151
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
152
+ true
153
+ else
154
+ false
155
+ end
156
+ when :Object
157
+ # generic object (usually a Hash), return directly
158
+ value
159
+ when /\AArray<(?<inner_type>.+)>\z/
160
+ inner_type = Regexp.last_match[:inner_type]
161
+ value.map { |v| _deserialize(inner_type, v) }
162
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
163
+ k_type = Regexp.last_match[:k_type]
164
+ v_type = Regexp.last_match[:v_type]
165
+ {}.tap do |hash|
166
+ value.each do |k, v|
167
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
168
+ end
169
+ end
170
+ else # model
171
+ # models (e.g. Pet) or oneOf
172
+ klass = BrazeClient.const_get(type)
173
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
174
+ end
175
+ end
176
+
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ if value.nil?
196
+ is_nullable = self.class.openapi_nullable.include?(attr)
197
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
198
+ end
199
+
200
+ hash[param] = _to_hash(value)
201
+ end
202
+ hash
203
+ end
204
+
205
+ # Outputs non-array value in the form of hash
206
+ # For object, use to_hash. Otherwise, just return the value
207
+ # @param [Object] value Any valid value
208
+ # @return [Hash] Returns the value in the form of hash
209
+ def _to_hash(value)
210
+ if value.is_a?(Array)
211
+ value.compact.map { |v| _to_hash(v) }
212
+ elsif value.is_a?(Hash)
213
+ {}.tap do |hash|
214
+ value.each { |k, v| hash[k] = _to_hash(v) }
215
+ end
216
+ elsif value.respond_to? :to_hash
217
+ value.to_hash
218
+ else
219
+ value
220
+ end
221
+ end
222
+
223
+ end
224
+
225
+ end