mparticle 1.0.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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +73 -0
  3. data/docs/ApiResponse.md +8 -0
  4. data/docs/ApiResponseErrors.md +9 -0
  5. data/docs/AppEvent.md +18 -0
  6. data/docs/ApplicationInformation.md +11 -0
  7. data/docs/ApplicationStateTransitionEvent.md +20 -0
  8. data/docs/AttributionInfo.md +10 -0
  9. data/docs/Batch.md +18 -0
  10. data/docs/BreadcrumbEvent.md +17 -0
  11. data/docs/CommerceEvent.md +22 -0
  12. data/docs/CrashReportEvent.md +26 -0
  13. data/docs/DeviceCurrentState.md +23 -0
  14. data/docs/DeviceInformation.md +41 -0
  15. data/docs/EventBase.md +9 -0
  16. data/docs/EventData.md +15 -0
  17. data/docs/EventsApi.md +124 -0
  18. data/docs/FirstRunEvent.md +15 -0
  19. data/docs/GeoLocation.md +10 -0
  20. data/docs/MediaInfo.md +15 -0
  21. data/docs/NetworkPerformanceEvent.md +22 -0
  22. data/docs/OptOutEvent.md +16 -0
  23. data/docs/Product.md +19 -0
  24. data/docs/ProductAction.md +19 -0
  25. data/docs/ProductImpression.md +9 -0
  26. data/docs/ProfileEvent.md +18 -0
  27. data/docs/Promotion.md +11 -0
  28. data/docs/PromotionAction.md +9 -0
  29. data/docs/PushMessageEvent.md +22 -0
  30. data/docs/PushRegistrationEvent.md +17 -0
  31. data/docs/ScreenViewEvent.md +17 -0
  32. data/docs/SessionEndEvent.md +16 -0
  33. data/docs/SessionStartEvent.md +15 -0
  34. data/docs/ShoppingCart.md +8 -0
  35. data/docs/SourceInformation.md +11 -0
  36. data/docs/UserIdentities.md +17 -0
  37. data/example/main.rb +32 -0
  38. data/lib/.DS_Store +0 -0
  39. data/lib/mparticle/.DS_Store +0 -0
  40. data/lib/mparticle/api/events_api.rb +129 -0
  41. data/lib/mparticle/api_client.rb +398 -0
  42. data/lib/mparticle/api_error.rb +26 -0
  43. data/lib/mparticle/configuration.rb +160 -0
  44. data/lib/mparticle/models/api_response.rb +178 -0
  45. data/lib/mparticle/models/api_response_errors.rb +185 -0
  46. data/lib/mparticle/models/app_event.rb +311 -0
  47. data/lib/mparticle/models/application_information.rb +203 -0
  48. data/lib/mparticle/models/application_state_transition_event.rb +352 -0
  49. data/lib/mparticle/models/attribution_info.rb +209 -0
  50. data/lib/mparticle/models/batch.rb +348 -0
  51. data/lib/mparticle/models/breadcrumb_event.rb +269 -0
  52. data/lib/mparticle/models/commerce_event.rb +306 -0
  53. data/lib/mparticle/models/crash_report_event.rb +362 -0
  54. data/lib/mparticle/models/device_current_state.rb +356 -0
  55. data/lib/mparticle/models/device_information.rb +506 -0
  56. data/lib/mparticle/models/event_base.rb +228 -0
  57. data/lib/mparticle/models/event_data.rb +241 -0
  58. data/lib/mparticle/models/first_run_event.rb +241 -0
  59. data/lib/mparticle/models/geo_location.rb +204 -0
  60. data/lib/mparticle/models/media_info.rb +296 -0
  61. data/lib/mparticle/models/network_performance_event.rb +334 -0
  62. data/lib/mparticle/models/opt_out_event.rb +255 -0
  63. data/lib/mparticle/models/product.rb +297 -0
  64. data/lib/mparticle/models/product_action.rb +330 -0
  65. data/lib/mparticle/models/product_impression.rb +197 -0
  66. data/lib/mparticle/models/profile_event.rb +316 -0
  67. data/lib/mparticle/models/promotion.rb +223 -0
  68. data/lib/mparticle/models/promotion_action.rb +230 -0
  69. data/lib/mparticle/models/push_message_event.rb +369 -0
  70. data/lib/mparticle/models/push_registration_event.rb +269 -0
  71. data/lib/mparticle/models/screen_view_event.rb +264 -0
  72. data/lib/mparticle/models/session_end_event.rb +255 -0
  73. data/lib/mparticle/models/session_start_event.rb +241 -0
  74. data/lib/mparticle/models/shopping_cart.rb +183 -0
  75. data/lib/mparticle/models/source_information.rb +246 -0
  76. data/lib/mparticle/models/user_identities.rb +257 -0
  77. data/lib/mparticle/version.rb +3 -0
  78. data/lib/mparticle.rb +61 -0
  79. data/mparticle.gemspec +19 -0
  80. metadata +163 -0
@@ -0,0 +1,369 @@
1
+ require 'date'
2
+
3
+ module MParticle
4
+
5
+ class PushMessageEvent
6
+ attr_accessor :timestamp_unixtime_ms
7
+
8
+ attr_accessor :event_id
9
+
10
+ attr_accessor :source_message_id
11
+
12
+ attr_accessor :session_id
13
+
14
+ attr_accessor :session_uuid
15
+
16
+ attr_accessor :custom_attributes
17
+
18
+ attr_accessor :location
19
+
20
+ attr_accessor :device_current_state
21
+
22
+ attr_accessor :push_message_token
23
+
24
+ attr_accessor :push_message_type
25
+
26
+ attr_accessor :message
27
+
28
+ attr_accessor :network
29
+
30
+ attr_accessor :push_notification_payload
31
+
32
+ attr_accessor :application_state
33
+
34
+ attr_accessor :action_identifier
35
+
36
+ class EnumAttributeValidator
37
+ attr_reader :datatype
38
+ attr_reader :allowable_values
39
+
40
+ def initialize(datatype, allowable_values)
41
+ @allowable_values = allowable_values.map do |value|
42
+ case datatype.to_s
43
+ when /Integer/i
44
+ value.to_i
45
+ when /Float/i
46
+ value.to_f
47
+ else
48
+ value
49
+ end
50
+ end
51
+ end
52
+
53
+ def valid?(value)
54
+ !value || allowable_values.include?(value)
55
+ end
56
+ end
57
+
58
+ # Attribute mapping from ruby-style variable name to JSON key.
59
+ def self.attribute_map
60
+ {
61
+ :'timestamp_unixtime_ms' => :'timestamp_unixtime_ms',
62
+ :'event_id' => :'event_id',
63
+ :'source_message_id' => :'source_message_id',
64
+ :'session_id' => :'session_id',
65
+ :'session_uuid' => :'session_uuid',
66
+ :'custom_attributes' => :'custom_attributes',
67
+ :'location' => :'location',
68
+ :'device_current_state' => :'device_current_state',
69
+ :'push_message_token' => :'push_message_token',
70
+ :'push_message_type' => :'push_message_type',
71
+ :'message' => :'message',
72
+ :'network' => :'network',
73
+ :'push_notification_payload' => :'push_notification_payload',
74
+ :'application_state' => :'application_state',
75
+ :'action_identifier' => :'action_identifier'
76
+ }
77
+ end
78
+
79
+ # Attribute type mapping.
80
+ def self.swagger_types
81
+ {
82
+ :'timestamp_unixtime_ms' => :'Integer',
83
+ :'event_id' => :'Integer',
84
+ :'source_message_id' => :'String',
85
+ :'session_id' => :'Integer',
86
+ :'session_uuid' => :'String',
87
+ :'custom_attributes' => :'Hash<String, String>',
88
+ :'location' => :'GeoLocation',
89
+ :'device_current_state' => :'DeviceCurrentState',
90
+ :'push_message_token' => :'String',
91
+ :'push_message_type' => :'String',
92
+ :'message' => :'String',
93
+ :'network' => :'String',
94
+ :'push_notification_payload' => :'String',
95
+ :'application_state' => :'String',
96
+ :'action_identifier' => :'String'
97
+ }
98
+ end
99
+
100
+ # Initializes the object
101
+ # @param [Hash] attributes Model attributes in the form of hash
102
+ def initialize(attributes = {})
103
+ return unless attributes.is_a?(Hash)
104
+
105
+ # convert string to symbol for hash key
106
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
107
+
108
+ if attributes.has_key?(:'timestamp_unixtime_ms')
109
+ self.timestamp_unixtime_ms = attributes[:'timestamp_unixtime_ms']
110
+ end
111
+
112
+ if attributes.has_key?(:'event_id')
113
+ self.event_id = attributes[:'event_id']
114
+ end
115
+
116
+ if attributes.has_key?(:'source_message_id')
117
+ self.source_message_id = attributes[:'source_message_id']
118
+ end
119
+
120
+ if attributes.has_key?(:'session_id')
121
+ self.session_id = attributes[:'session_id']
122
+ end
123
+
124
+ if attributes.has_key?(:'session_uuid')
125
+ self.session_uuid = attributes[:'session_uuid']
126
+ end
127
+
128
+ if attributes.has_key?(:'custom_attributes')
129
+ if (value = attributes[:'custom_attributes']).is_a?(Array)
130
+ self.custom_attributes = value
131
+ end
132
+ end
133
+
134
+ if attributes.has_key?(:'location')
135
+ self.location = attributes[:'location']
136
+ end
137
+
138
+ if attributes.has_key?(:'device_current_state')
139
+ self.device_current_state = attributes[:'device_current_state']
140
+ end
141
+
142
+ if attributes.has_key?(:'push_message_token')
143
+ self.push_message_token = attributes[:'push_message_token']
144
+ end
145
+
146
+ if attributes.has_key?(:'push_message_type')
147
+ self.push_message_type = attributes[:'push_message_type']
148
+ end
149
+
150
+ if attributes.has_key?(:'message')
151
+ self.message = attributes[:'message']
152
+ end
153
+
154
+ if attributes.has_key?(:'network')
155
+ self.network = attributes[:'network']
156
+ end
157
+
158
+ if attributes.has_key?(:'push_notification_payload')
159
+ self.push_notification_payload = attributes[:'push_notification_payload']
160
+ end
161
+
162
+ if attributes.has_key?(:'application_state')
163
+ self.application_state = attributes[:'application_state']
164
+ end
165
+
166
+ if attributes.has_key?(:'action_identifier')
167
+ self.action_identifier = attributes[:'action_identifier']
168
+ end
169
+
170
+ end
171
+
172
+ # Show invalid properties with the reasons. Usually used together with valid?
173
+ # @return Array for valid properies with the reasons
174
+ def list_invalid_properties
175
+ invalid_properties = Array.new
176
+ if @push_message_token.nil?
177
+ invalid_properties.push("invalid value for 'push_message_token', push_message_token cannot be nil.")
178
+ end
179
+
180
+ if @push_message_type.nil?
181
+ invalid_properties.push("invalid value for 'push_message_type', push_message_type cannot be nil.")
182
+ end
183
+
184
+ if @push_notification_payload.nil?
185
+ invalid_properties.push("invalid value for 'push_notification_payload', push_notification_payload cannot be nil.")
186
+ end
187
+
188
+ if @application_state.nil?
189
+ invalid_properties.push("invalid value for 'application_state', application_state cannot be nil.")
190
+ end
191
+
192
+ return invalid_properties
193
+ end
194
+
195
+ # Check to see if the all the properties in the model are valid
196
+ # @return true if the model is valid
197
+ def valid?
198
+ return false if @push_message_token.nil?
199
+ return false if @push_message_type.nil?
200
+ push_message_type_validator = EnumAttributeValidator.new('String', ["unknown", "sent", "received", "action"])
201
+ return false unless push_message_type_validator.valid?(@push_message_type)
202
+ return false if @push_notification_payload.nil?
203
+ return false if @application_state.nil?
204
+ application_state_validator = EnumAttributeValidator.new('String', ["unknown", "not_running", "background", "foreground"])
205
+ return false unless application_state_validator.valid?(@application_state)
206
+ return true
207
+ end
208
+
209
+ # Custom attribute writer method checking allowed values (enum).
210
+ # @param [Object] push_message_type Object to be assigned
211
+ def push_message_type=(push_message_type)
212
+ validator = EnumAttributeValidator.new('String', ["unknown", "sent", "received", "action"])
213
+ unless validator.valid?(push_message_type)
214
+ fail ArgumentError, "invalid value for 'push_message_type', must be one of #{validator.allowable_values}."
215
+ end
216
+ @push_message_type = push_message_type
217
+ end
218
+
219
+ # Custom attribute writer method checking allowed values (enum).
220
+ # @param [Object] application_state Object to be assigned
221
+ def application_state=(application_state)
222
+ validator = EnumAttributeValidator.new('String', ["unknown", "not_running", "background", "foreground"])
223
+ unless validator.valid?(application_state)
224
+ fail ArgumentError, "invalid value for 'application_state', must be one of #{validator.allowable_values}."
225
+ end
226
+ @application_state = application_state
227
+ end
228
+
229
+ # Checks equality by comparing each attribute.
230
+ # @param [Object] Object to be compared
231
+ def ==(o)
232
+ return true if self.equal?(o)
233
+ self.class == o.class &&
234
+ timestamp_unixtime_ms == o.timestamp_unixtime_ms &&
235
+ event_id == o.event_id &&
236
+ source_message_id == o.source_message_id &&
237
+ session_id == o.session_id &&
238
+ session_uuid == o.session_uuid &&
239
+ custom_attributes == o.custom_attributes &&
240
+ location == o.location &&
241
+ device_current_state == o.device_current_state &&
242
+ push_message_token == o.push_message_token &&
243
+ push_message_type == o.push_message_type &&
244
+ message == o.message &&
245
+ network == o.network &&
246
+ push_notification_payload == o.push_notification_payload &&
247
+ application_state == o.application_state &&
248
+ action_identifier == o.action_identifier
249
+ end
250
+
251
+ # @see the `==` method
252
+ # @param [Object] Object to be compared
253
+ def eql?(o)
254
+ self == o
255
+ end
256
+
257
+ # Calculates hash code according to all attributes.
258
+ # @return [Fixnum] Hash code
259
+ def hash
260
+ [timestamp_unixtime_ms, event_id, source_message_id, session_id, session_uuid, custom_attributes, location, device_current_state, push_message_token, push_message_type, message, network, push_notification_payload, application_state, action_identifier].hash
261
+ end
262
+
263
+ # Builds the object from hash
264
+ # @param [Hash] attributes Model attributes in the form of hash
265
+ # @return [Object] Returns the model itself
266
+ def build_from_hash(attributes)
267
+ return nil unless attributes.is_a?(Hash)
268
+ self.class.swagger_types.each_pair do |key, type|
269
+ if type =~ /\AArray<(.*)>/i
270
+ # check to ensure the input is an array given that the the attribute
271
+ # is documented as an array but the input is not
272
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
273
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
274
+ end
275
+ elsif !attributes[self.class.attribute_map[key]].nil?
276
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
277
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
278
+ end
279
+
280
+ self
281
+ end
282
+
283
+ # Deserializes the data based on type
284
+ # @param string type Data type
285
+ # @param string value Value to be deserialized
286
+ # @return [Object] Deserialized data
287
+ def _deserialize(type, value)
288
+ case type.to_sym
289
+ when :DateTime
290
+ DateTime.parse(value)
291
+ when :Date
292
+ Date.parse(value)
293
+ when :String
294
+ value.to_s
295
+ when :Integer
296
+ value.to_i
297
+ when :Float
298
+ value.to_f
299
+ when :BOOLEAN
300
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
301
+ true
302
+ else
303
+ false
304
+ end
305
+ when :Object
306
+ # generic object (usually a Hash), return directly
307
+ value
308
+ when /\AArray<(?<inner_type>.+)>\z/
309
+ inner_type = Regexp.last_match[:inner_type]
310
+ value.map { |v| _deserialize(inner_type, v) }
311
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
312
+ k_type = Regexp.last_match[:k_type]
313
+ v_type = Regexp.last_match[:v_type]
314
+ {}.tap do |hash|
315
+ value.each do |k, v|
316
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
317
+ end
318
+ end
319
+ else # model
320
+ temp_model = MParticle.const_get(type).new
321
+ temp_model.build_from_hash(value)
322
+ end
323
+ end
324
+
325
+ # Returns the string representation of the object
326
+ # @return [String] String presentation of the object
327
+ def to_s
328
+ to_hash.to_s
329
+ end
330
+
331
+ # to_body is an alias to to_hash (backward compatibility)
332
+ # @return [Hash] Returns the object in the form of hash
333
+ def to_body
334
+ to_hash
335
+ end
336
+
337
+ # Returns the object in the form of hash
338
+ # @return [Hash] Returns the object in the form of hash
339
+ def to_hash
340
+ hash = {}
341
+ self.class.attribute_map.each_pair do |attr, param|
342
+ value = self.send(attr)
343
+ next if value.nil?
344
+ hash[param] = _to_hash(value)
345
+ end
346
+ hash
347
+ end
348
+
349
+ # Outputs non-array value in the form of hash
350
+ # For object, use to_hash. Otherwise, just return the value
351
+ # @param [Object] value Any valid value
352
+ # @return [Hash] Returns the value in the form of hash
353
+ def _to_hash(value)
354
+ if value.is_a?(Array)
355
+ value.compact.map{ |v| _to_hash(v) }
356
+ elsif value.is_a?(Hash)
357
+ {}.tap do |hash|
358
+ value.each { |k, v| hash[k] = _to_hash(v) }
359
+ end
360
+ elsif value.respond_to? :to_hash
361
+ value.to_hash
362
+ else
363
+ value
364
+ end
365
+ end
366
+
367
+ end
368
+
369
+ end
@@ -0,0 +1,269 @@
1
+ require 'date'
2
+
3
+ module MParticle
4
+
5
+ class PushRegistrationEvent
6
+ attr_accessor :timestamp_unixtime_ms
7
+
8
+ attr_accessor :event_id
9
+
10
+ attr_accessor :source_message_id
11
+
12
+ attr_accessor :session_id
13
+
14
+ attr_accessor :session_uuid
15
+
16
+ attr_accessor :custom_attributes
17
+
18
+ attr_accessor :location
19
+
20
+ attr_accessor :device_current_state
21
+
22
+ attr_accessor :register
23
+
24
+ attr_accessor :registration_token
25
+
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'timestamp_unixtime_ms' => :'timestamp_unixtime_ms',
31
+ :'event_id' => :'event_id',
32
+ :'source_message_id' => :'source_message_id',
33
+ :'session_id' => :'session_id',
34
+ :'session_uuid' => :'session_uuid',
35
+ :'custom_attributes' => :'custom_attributes',
36
+ :'location' => :'location',
37
+ :'device_current_state' => :'device_current_state',
38
+ :'register' => :'register',
39
+ :'registration_token' => :'registration_token'
40
+ }
41
+ end
42
+
43
+ # Attribute type mapping.
44
+ def self.swagger_types
45
+ {
46
+ :'timestamp_unixtime_ms' => :'Integer',
47
+ :'event_id' => :'Integer',
48
+ :'source_message_id' => :'String',
49
+ :'session_id' => :'Integer',
50
+ :'session_uuid' => :'String',
51
+ :'custom_attributes' => :'Hash<String, String>',
52
+ :'location' => :'GeoLocation',
53
+ :'device_current_state' => :'DeviceCurrentState',
54
+ :'register' => :'BOOLEAN',
55
+ :'registration_token' => :'String'
56
+ }
57
+ end
58
+
59
+ # Initializes the object
60
+ # @param [Hash] attributes Model attributes in the form of hash
61
+ def initialize(attributes = {})
62
+ return unless attributes.is_a?(Hash)
63
+
64
+ # convert string to symbol for hash key
65
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
66
+
67
+ if attributes.has_key?(:'timestamp_unixtime_ms')
68
+ self.timestamp_unixtime_ms = attributes[:'timestamp_unixtime_ms']
69
+ end
70
+
71
+ if attributes.has_key?(:'event_id')
72
+ self.event_id = attributes[:'event_id']
73
+ end
74
+
75
+ if attributes.has_key?(:'source_message_id')
76
+ self.source_message_id = attributes[:'source_message_id']
77
+ end
78
+
79
+ if attributes.has_key?(:'session_id')
80
+ self.session_id = attributes[:'session_id']
81
+ end
82
+
83
+ if attributes.has_key?(:'session_uuid')
84
+ self.session_uuid = attributes[:'session_uuid']
85
+ end
86
+
87
+ if attributes.has_key?(:'custom_attributes')
88
+ if (value = attributes[:'custom_attributes']).is_a?(Array)
89
+ self.custom_attributes = value
90
+ end
91
+ end
92
+
93
+ if attributes.has_key?(:'location')
94
+ self.location = attributes[:'location']
95
+ end
96
+
97
+ if attributes.has_key?(:'device_current_state')
98
+ self.device_current_state = attributes[:'device_current_state']
99
+ end
100
+
101
+ if attributes.has_key?(:'register')
102
+ self.register = attributes[:'register']
103
+ end
104
+
105
+ if attributes.has_key?(:'registration_token')
106
+ self.registration_token = attributes[:'registration_token']
107
+ end
108
+
109
+ end
110
+
111
+ # Show invalid properties with the reasons. Usually used together with valid?
112
+ # @return Array for valid properies with the reasons
113
+ def list_invalid_properties
114
+ invalid_properties = Array.new
115
+ if @register.nil?
116
+ invalid_properties.push("invalid value for 'register', register cannot be nil.")
117
+ end
118
+
119
+ if @registration_token.nil?
120
+ invalid_properties.push("invalid value for 'registration_token', registration_token cannot be nil.")
121
+ end
122
+
123
+ return invalid_properties
124
+ end
125
+
126
+ # Check to see if the all the properties in the model are valid
127
+ # @return true if the model is valid
128
+ def valid?
129
+ return false if @register.nil?
130
+ return false if @registration_token.nil?
131
+ return true
132
+ end
133
+
134
+ # Checks equality by comparing each attribute.
135
+ # @param [Object] Object to be compared
136
+ def ==(o)
137
+ return true if self.equal?(o)
138
+ self.class == o.class &&
139
+ timestamp_unixtime_ms == o.timestamp_unixtime_ms &&
140
+ event_id == o.event_id &&
141
+ source_message_id == o.source_message_id &&
142
+ session_id == o.session_id &&
143
+ session_uuid == o.session_uuid &&
144
+ custom_attributes == o.custom_attributes &&
145
+ location == o.location &&
146
+ device_current_state == o.device_current_state &&
147
+ register == o.register &&
148
+ registration_token == o.registration_token
149
+ end
150
+
151
+ # @see the `==` method
152
+ # @param [Object] Object to be compared
153
+ def eql?(o)
154
+ self == o
155
+ end
156
+
157
+ # Calculates hash code according to all attributes.
158
+ # @return [Fixnum] Hash code
159
+ def hash
160
+ [timestamp_unixtime_ms, event_id, source_message_id, session_id, session_uuid, custom_attributes, location, device_current_state, register, registration_token].hash
161
+ end
162
+
163
+ # Builds the object from hash
164
+ # @param [Hash] attributes Model attributes in the form of hash
165
+ # @return [Object] Returns the model itself
166
+ def build_from_hash(attributes)
167
+ return nil unless attributes.is_a?(Hash)
168
+ self.class.swagger_types.each_pair do |key, type|
169
+ if type =~ /\AArray<(.*)>/i
170
+ # check to ensure the input is an array given that the the attribute
171
+ # is documented as an array but the input is not
172
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
173
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
174
+ end
175
+ elsif !attributes[self.class.attribute_map[key]].nil?
176
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
177
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
178
+ end
179
+
180
+ self
181
+ end
182
+
183
+ # Deserializes the data based on type
184
+ # @param string type Data type
185
+ # @param string value Value to be deserialized
186
+ # @return [Object] Deserialized data
187
+ def _deserialize(type, value)
188
+ case type.to_sym
189
+ when :DateTime
190
+ DateTime.parse(value)
191
+ when :Date
192
+ Date.parse(value)
193
+ when :String
194
+ value.to_s
195
+ when :Integer
196
+ value.to_i
197
+ when :Float
198
+ value.to_f
199
+ when :BOOLEAN
200
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
201
+ true
202
+ else
203
+ false
204
+ end
205
+ when :Object
206
+ # generic object (usually a Hash), return directly
207
+ value
208
+ when /\AArray<(?<inner_type>.+)>\z/
209
+ inner_type = Regexp.last_match[:inner_type]
210
+ value.map { |v| _deserialize(inner_type, v) }
211
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
212
+ k_type = Regexp.last_match[:k_type]
213
+ v_type = Regexp.last_match[:v_type]
214
+ {}.tap do |hash|
215
+ value.each do |k, v|
216
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
217
+ end
218
+ end
219
+ else # model
220
+ temp_model = MParticle.const_get(type).new
221
+ temp_model.build_from_hash(value)
222
+ end
223
+ end
224
+
225
+ # Returns the string representation of the object
226
+ # @return [String] String presentation of the object
227
+ def to_s
228
+ to_hash.to_s
229
+ end
230
+
231
+ # to_body is an alias to to_hash (backward compatibility)
232
+ # @return [Hash] Returns the object in the form of hash
233
+ def to_body
234
+ to_hash
235
+ end
236
+
237
+ # Returns the object in the form of hash
238
+ # @return [Hash] Returns the object in the form of hash
239
+ def to_hash
240
+ hash = {}
241
+ self.class.attribute_map.each_pair do |attr, param|
242
+ value = self.send(attr)
243
+ next if value.nil?
244
+ hash[param] = _to_hash(value)
245
+ end
246
+ hash
247
+ end
248
+
249
+ # Outputs non-array value in the form of hash
250
+ # For object, use to_hash. Otherwise, just return the value
251
+ # @param [Object] value Any valid value
252
+ # @return [Hash] Returns the value in the form of hash
253
+ def _to_hash(value)
254
+ if value.is_a?(Array)
255
+ value.compact.map{ |v| _to_hash(v) }
256
+ elsif value.is_a?(Hash)
257
+ {}.tap do |hash|
258
+ value.each { |k, v| hash[k] = _to_hash(v) }
259
+ end
260
+ elsif value.respond_to? :to_hash
261
+ value.to_hash
262
+ else
263
+ value
264
+ end
265
+ end
266
+
267
+ end
268
+
269
+ end