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,297 @@
1
+ require 'date'
2
+
3
+ module MParticle
4
+
5
+ class Product
6
+ attr_accessor :id
7
+
8
+ attr_accessor :name
9
+
10
+ attr_accessor :brand
11
+
12
+ attr_accessor :category
13
+
14
+ attr_accessor :variant
15
+
16
+ attr_accessor :position
17
+
18
+ attr_accessor :price
19
+
20
+ attr_accessor :quantity
21
+
22
+ attr_accessor :coupon_code
23
+
24
+ attr_accessor :added_to_cart_time_ms
25
+
26
+ attr_accessor :total_product_amount
27
+
28
+ attr_accessor :custom_attributes
29
+
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'id' => :'id',
35
+ :'name' => :'name',
36
+ :'brand' => :'brand',
37
+ :'category' => :'category',
38
+ :'variant' => :'variant',
39
+ :'position' => :'position',
40
+ :'price' => :'price',
41
+ :'quantity' => :'quantity',
42
+ :'coupon_code' => :'coupon_code',
43
+ :'added_to_cart_time_ms' => :'added_to_cart_time_ms',
44
+ :'total_product_amount' => :'total_product_amount',
45
+ :'custom_attributes' => :'custom_attributes'
46
+ }
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.swagger_types
51
+ {
52
+ :'id' => :'String',
53
+ :'name' => :'String',
54
+ :'brand' => :'String',
55
+ :'category' => :'String',
56
+ :'variant' => :'String',
57
+ :'position' => :'Integer',
58
+ :'price' => :'Float',
59
+ :'quantity' => :'Float',
60
+ :'coupon_code' => :'String',
61
+ :'added_to_cart_time_ms' => :'Integer',
62
+ :'total_product_amount' => :'Float',
63
+ :'custom_attributes' => :'Hash<String, String>'
64
+ }
65
+ end
66
+
67
+ # Initializes the object
68
+ # @param [Hash] attributes Model attributes in the form of hash
69
+ def initialize(attributes = {})
70
+ return unless attributes.is_a?(Hash)
71
+
72
+ # convert string to symbol for hash key
73
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
74
+
75
+ if attributes.has_key?(:'id')
76
+ self.id = attributes[:'id']
77
+ end
78
+
79
+ if attributes.has_key?(:'name')
80
+ self.name = attributes[:'name']
81
+ end
82
+
83
+ if attributes.has_key?(:'brand')
84
+ self.brand = attributes[:'brand']
85
+ end
86
+
87
+ if attributes.has_key?(:'category')
88
+ self.category = attributes[:'category']
89
+ end
90
+
91
+ if attributes.has_key?(:'variant')
92
+ self.variant = attributes[:'variant']
93
+ end
94
+
95
+ if attributes.has_key?(:'position')
96
+ self.position = attributes[:'position']
97
+ end
98
+
99
+ if attributes.has_key?(:'price')
100
+ self.price = attributes[:'price']
101
+ end
102
+
103
+ if attributes.has_key?(:'quantity')
104
+ self.quantity = attributes[:'quantity']
105
+ end
106
+
107
+ if attributes.has_key?(:'coupon_code')
108
+ self.coupon_code = attributes[:'coupon_code']
109
+ end
110
+
111
+ if attributes.has_key?(:'added_to_cart_time_ms')
112
+ self.added_to_cart_time_ms = attributes[:'added_to_cart_time_ms']
113
+ end
114
+
115
+ if attributes.has_key?(:'total_product_amount')
116
+ self.total_product_amount = attributes[:'total_product_amount']
117
+ end
118
+
119
+ if attributes.has_key?(:'custom_attributes')
120
+ if (value = attributes[:'custom_attributes']).is_a?(Array)
121
+ self.custom_attributes = value
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ # Show invalid properties with the reasons. Usually used together with valid?
128
+ # @return Array for valid properies with the reasons
129
+ def list_invalid_properties
130
+ invalid_properties = Array.new
131
+ if @id.nil?
132
+ invalid_properties.push("invalid value for 'id', id cannot be nil.")
133
+ end
134
+
135
+ if @name.nil?
136
+ invalid_properties.push("invalid value for 'name', name cannot be nil.")
137
+ end
138
+
139
+ if @price.nil?
140
+ invalid_properties.push("invalid value for 'price', price cannot be nil.")
141
+ end
142
+
143
+ if @total_product_amount.nil?
144
+ invalid_properties.push("invalid value for 'total_product_amount', total_product_amount cannot be nil.")
145
+ end
146
+
147
+ return invalid_properties
148
+ end
149
+
150
+ # Check to see if the all the properties in the model are valid
151
+ # @return true if the model is valid
152
+ def valid?
153
+ return false if @id.nil?
154
+ return false if @name.nil?
155
+ return false if @price.nil?
156
+ return false if @total_product_amount.nil?
157
+ return true
158
+ end
159
+
160
+ # Checks equality by comparing each attribute.
161
+ # @param [Object] Object to be compared
162
+ def ==(o)
163
+ return true if self.equal?(o)
164
+ self.class == o.class &&
165
+ id == o.id &&
166
+ name == o.name &&
167
+ brand == o.brand &&
168
+ category == o.category &&
169
+ variant == o.variant &&
170
+ position == o.position &&
171
+ price == o.price &&
172
+ quantity == o.quantity &&
173
+ coupon_code == o.coupon_code &&
174
+ added_to_cart_time_ms == o.added_to_cart_time_ms &&
175
+ total_product_amount == o.total_product_amount &&
176
+ custom_attributes == o.custom_attributes
177
+ end
178
+
179
+ # @see the `==` method
180
+ # @param [Object] Object to be compared
181
+ def eql?(o)
182
+ self == o
183
+ end
184
+
185
+ # Calculates hash code according to all attributes.
186
+ # @return [Fixnum] Hash code
187
+ def hash
188
+ [id, name, brand, category, variant, position, price, quantity, coupon_code, added_to_cart_time_ms, total_product_amount, custom_attributes].hash
189
+ end
190
+
191
+ # Builds the object from hash
192
+ # @param [Hash] attributes Model attributes in the form of hash
193
+ # @return [Object] Returns the model itself
194
+ def build_from_hash(attributes)
195
+ return nil unless attributes.is_a?(Hash)
196
+ self.class.swagger_types.each_pair do |key, type|
197
+ if type =~ /\AArray<(.*)>/i
198
+ # check to ensure the input is an array given that the the attribute
199
+ # is documented as an array but the input is not
200
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
201
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
202
+ end
203
+ elsif !attributes[self.class.attribute_map[key]].nil?
204
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
205
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
206
+ end
207
+
208
+ self
209
+ end
210
+
211
+ # Deserializes the data based on type
212
+ # @param string type Data type
213
+ # @param string value Value to be deserialized
214
+ # @return [Object] Deserialized data
215
+ def _deserialize(type, value)
216
+ case type.to_sym
217
+ when :DateTime
218
+ DateTime.parse(value)
219
+ when :Date
220
+ Date.parse(value)
221
+ when :String
222
+ value.to_s
223
+ when :Integer
224
+ value.to_i
225
+ when :Float
226
+ value.to_f
227
+ when :BOOLEAN
228
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
229
+ true
230
+ else
231
+ false
232
+ end
233
+ when :Object
234
+ # generic object (usually a Hash), return directly
235
+ value
236
+ when /\AArray<(?<inner_type>.+)>\z/
237
+ inner_type = Regexp.last_match[:inner_type]
238
+ value.map { |v| _deserialize(inner_type, v) }
239
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
240
+ k_type = Regexp.last_match[:k_type]
241
+ v_type = Regexp.last_match[:v_type]
242
+ {}.tap do |hash|
243
+ value.each do |k, v|
244
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
245
+ end
246
+ end
247
+ else # model
248
+ temp_model = MParticle.const_get(type).new
249
+ temp_model.build_from_hash(value)
250
+ end
251
+ end
252
+
253
+ # Returns the string representation of the object
254
+ # @return [String] String presentation of the object
255
+ def to_s
256
+ to_hash.to_s
257
+ end
258
+
259
+ # to_body is an alias to to_hash (backward compatibility)
260
+ # @return [Hash] Returns the object in the form of hash
261
+ def to_body
262
+ to_hash
263
+ end
264
+
265
+ # Returns the object in the form of hash
266
+ # @return [Hash] Returns the object in the form of hash
267
+ def to_hash
268
+ hash = {}
269
+ self.class.attribute_map.each_pair do |attr, param|
270
+ value = self.send(attr)
271
+ next if value.nil?
272
+ hash[param] = _to_hash(value)
273
+ end
274
+ hash
275
+ end
276
+
277
+ # Outputs non-array value in the form of hash
278
+ # For object, use to_hash. Otherwise, just return the value
279
+ # @param [Object] value Any valid value
280
+ # @return [Hash] Returns the value in the form of hash
281
+ def _to_hash(value)
282
+ if value.is_a?(Array)
283
+ value.compact.map{ |v| _to_hash(v) }
284
+ elsif value.is_a?(Hash)
285
+ {}.tap do |hash|
286
+ value.each { |k, v| hash[k] = _to_hash(v) }
287
+ end
288
+ elsif value.respond_to? :to_hash
289
+ value.to_hash
290
+ else
291
+ value
292
+ end
293
+ end
294
+
295
+ end
296
+
297
+ end
@@ -0,0 +1,330 @@
1
+ require 'date'
2
+
3
+ module MParticle
4
+
5
+ class ProductAction
6
+ attr_accessor :action
7
+
8
+ attr_accessor :checkout_step
9
+
10
+ attr_accessor :checkout_options
11
+
12
+ attr_accessor :product_action_list
13
+
14
+ attr_accessor :product_list_source
15
+
16
+ attr_accessor :transaction_id
17
+
18
+ attr_accessor :affiliation
19
+
20
+ attr_accessor :total_amount
21
+
22
+ attr_accessor :tax_amount
23
+
24
+ attr_accessor :shipping_amount
25
+
26
+ attr_accessor :coupon_code
27
+
28
+ attr_accessor :products
29
+
30
+ class EnumAttributeValidator
31
+ attr_reader :datatype
32
+ attr_reader :allowable_values
33
+
34
+ def initialize(datatype, allowable_values)
35
+ @allowable_values = allowable_values.map do |value|
36
+ case datatype.to_s
37
+ when /Integer/i
38
+ value.to_i
39
+ when /Float/i
40
+ value.to_f
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+
47
+ def valid?(value)
48
+ !value || allowable_values.include?(value)
49
+ end
50
+ end
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+ :'action' => :'action',
56
+ :'checkout_step' => :'checkout_step',
57
+ :'checkout_options' => :'checkout_options',
58
+ :'product_action_list' => :'product_action_list',
59
+ :'product_list_source' => :'product_list_source',
60
+ :'transaction_id' => :'transaction_id',
61
+ :'affiliation' => :'affiliation',
62
+ :'total_amount' => :'total_amount',
63
+ :'tax_amount' => :'tax_amount',
64
+ :'shipping_amount' => :'shipping_amount',
65
+ :'coupon_code' => :'coupon_code',
66
+ :'products' => :'products'
67
+ }
68
+ end
69
+
70
+ # Attribute type mapping.
71
+ def self.swagger_types
72
+ {
73
+ :'action' => :'String',
74
+ :'checkout_step' => :'Integer',
75
+ :'checkout_options' => :'String',
76
+ :'product_action_list' => :'String',
77
+ :'product_list_source' => :'String',
78
+ :'transaction_id' => :'String',
79
+ :'affiliation' => :'String',
80
+ :'total_amount' => :'Float',
81
+ :'tax_amount' => :'Float',
82
+ :'shipping_amount' => :'Float',
83
+ :'coupon_code' => :'String',
84
+ :'products' => :'Array<Product>'
85
+ }
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ return unless attributes.is_a?(Hash)
92
+
93
+ # convert string to symbol for hash key
94
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
95
+
96
+ if attributes.has_key?(:'action')
97
+ self.action = attributes[:'action']
98
+ end
99
+
100
+ if attributes.has_key?(:'checkout_step')
101
+ self.checkout_step = attributes[:'checkout_step']
102
+ end
103
+
104
+ if attributes.has_key?(:'checkout_options')
105
+ self.checkout_options = attributes[:'checkout_options']
106
+ end
107
+
108
+ if attributes.has_key?(:'product_action_list')
109
+ self.product_action_list = attributes[:'product_action_list']
110
+ end
111
+
112
+ if attributes.has_key?(:'product_list_source')
113
+ self.product_list_source = attributes[:'product_list_source']
114
+ end
115
+
116
+ if attributes.has_key?(:'transaction_id')
117
+ self.transaction_id = attributes[:'transaction_id']
118
+ end
119
+
120
+ if attributes.has_key?(:'affiliation')
121
+ self.affiliation = attributes[:'affiliation']
122
+ end
123
+
124
+ if attributes.has_key?(:'total_amount')
125
+ self.total_amount = attributes[:'total_amount']
126
+ end
127
+
128
+ if attributes.has_key?(:'tax_amount')
129
+ self.tax_amount = attributes[:'tax_amount']
130
+ end
131
+
132
+ if attributes.has_key?(:'shipping_amount')
133
+ self.shipping_amount = attributes[:'shipping_amount']
134
+ end
135
+
136
+ if attributes.has_key?(:'coupon_code')
137
+ self.coupon_code = attributes[:'coupon_code']
138
+ end
139
+
140
+ if attributes.has_key?(:'products')
141
+ if (value = attributes[:'products']).is_a?(Array)
142
+ self.products = value
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ # Show invalid properties with the reasons. Usually used together with valid?
149
+ # @return Array for valid properies with the reasons
150
+ def list_invalid_properties
151
+ invalid_properties = Array.new
152
+ if @action.nil?
153
+ invalid_properties.push("invalid value for 'action', action cannot be nil.")
154
+ end
155
+
156
+ if @transaction_id.nil?
157
+ invalid_properties.push("invalid value for 'transaction_id', transaction_id cannot be nil.")
158
+ end
159
+
160
+ if @total_amount.nil?
161
+ invalid_properties.push("invalid value for 'total_amount', total_amount cannot be nil.")
162
+ end
163
+
164
+ if @products.nil?
165
+ invalid_properties.push("invalid value for 'products', products cannot be nil.")
166
+ end
167
+
168
+ return invalid_properties
169
+ end
170
+
171
+ # Check to see if the all the properties in the model are valid
172
+ # @return true if the model is valid
173
+ def valid?
174
+ return false if @action.nil?
175
+ action_validator = EnumAttributeValidator.new('String', ["unknown", "add_to_cart", "remove_from_cart", "checkout", "checkout_option", "click", "view_detail", "purchase", "refund", "add_to_wishlist", "remove_from_wish_list"])
176
+ return false unless action_validator.valid?(@action)
177
+ return false if @transaction_id.nil?
178
+ return false if @total_amount.nil?
179
+ return false if @products.nil?
180
+ return true
181
+ end
182
+
183
+ # Custom attribute writer method checking allowed values (enum).
184
+ # @param [Object] action Object to be assigned
185
+ def action=(action)
186
+ validator = EnumAttributeValidator.new('String', ["unknown", "add_to_cart", "remove_from_cart", "checkout", "checkout_option", "click", "view_detail", "purchase", "refund", "add_to_wishlist", "remove_from_wish_list"])
187
+ unless validator.valid?(action)
188
+ fail ArgumentError, "invalid value for 'action', must be one of #{validator.allowable_values}."
189
+ end
190
+ @action = action
191
+ end
192
+
193
+ # Checks equality by comparing each attribute.
194
+ # @param [Object] Object to be compared
195
+ def ==(o)
196
+ return true if self.equal?(o)
197
+ self.class == o.class &&
198
+ action == o.action &&
199
+ checkout_step == o.checkout_step &&
200
+ checkout_options == o.checkout_options &&
201
+ product_action_list == o.product_action_list &&
202
+ product_list_source == o.product_list_source &&
203
+ transaction_id == o.transaction_id &&
204
+ affiliation == o.affiliation &&
205
+ total_amount == o.total_amount &&
206
+ tax_amount == o.tax_amount &&
207
+ shipping_amount == o.shipping_amount &&
208
+ coupon_code == o.coupon_code &&
209
+ products == o.products
210
+ end
211
+
212
+ # @see the `==` method
213
+ # @param [Object] Object to be compared
214
+ def eql?(o)
215
+ self == o
216
+ end
217
+
218
+ # Calculates hash code according to all attributes.
219
+ # @return [Fixnum] Hash code
220
+ def hash
221
+ [action, checkout_step, checkout_options, product_action_list, product_list_source, transaction_id, affiliation, total_amount, tax_amount, shipping_amount, coupon_code, products].hash
222
+ end
223
+
224
+ # Builds the object from hash
225
+ # @param [Hash] attributes Model attributes in the form of hash
226
+ # @return [Object] Returns the model itself
227
+ def build_from_hash(attributes)
228
+ return nil unless attributes.is_a?(Hash)
229
+ self.class.swagger_types.each_pair do |key, type|
230
+ if type =~ /\AArray<(.*)>/i
231
+ # check to ensure the input is an array given that the the attribute
232
+ # is documented as an array but the input is not
233
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
234
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
235
+ end
236
+ elsif !attributes[self.class.attribute_map[key]].nil?
237
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
238
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
239
+ end
240
+
241
+ self
242
+ end
243
+
244
+ # Deserializes the data based on type
245
+ # @param string type Data type
246
+ # @param string value Value to be deserialized
247
+ # @return [Object] Deserialized data
248
+ def _deserialize(type, value)
249
+ case type.to_sym
250
+ when :DateTime
251
+ DateTime.parse(value)
252
+ when :Date
253
+ Date.parse(value)
254
+ when :String
255
+ value.to_s
256
+ when :Integer
257
+ value.to_i
258
+ when :Float
259
+ value.to_f
260
+ when :BOOLEAN
261
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
262
+ true
263
+ else
264
+ false
265
+ end
266
+ when :Object
267
+ # generic object (usually a Hash), return directly
268
+ value
269
+ when /\AArray<(?<inner_type>.+)>\z/
270
+ inner_type = Regexp.last_match[:inner_type]
271
+ value.map { |v| _deserialize(inner_type, v) }
272
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
273
+ k_type = Regexp.last_match[:k_type]
274
+ v_type = Regexp.last_match[:v_type]
275
+ {}.tap do |hash|
276
+ value.each do |k, v|
277
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
278
+ end
279
+ end
280
+ else # model
281
+ temp_model = MParticle.const_get(type).new
282
+ temp_model.build_from_hash(value)
283
+ end
284
+ end
285
+
286
+ # Returns the string representation of the object
287
+ # @return [String] String presentation of the object
288
+ def to_s
289
+ to_hash.to_s
290
+ end
291
+
292
+ # to_body is an alias to to_hash (backward compatibility)
293
+ # @return [Hash] Returns the object in the form of hash
294
+ def to_body
295
+ to_hash
296
+ end
297
+
298
+ # Returns the object in the form of hash
299
+ # @return [Hash] Returns the object in the form of hash
300
+ def to_hash
301
+ hash = {}
302
+ self.class.attribute_map.each_pair do |attr, param|
303
+ value = self.send(attr)
304
+ next if value.nil?
305
+ hash[param] = _to_hash(value)
306
+ end
307
+ hash
308
+ end
309
+
310
+ # Outputs non-array value in the form of hash
311
+ # For object, use to_hash. Otherwise, just return the value
312
+ # @param [Object] value Any valid value
313
+ # @return [Hash] Returns the value in the form of hash
314
+ def _to_hash(value)
315
+ if value.is_a?(Array)
316
+ value.compact.map{ |v| _to_hash(v) }
317
+ elsif value.is_a?(Hash)
318
+ {}.tap do |hash|
319
+ value.each { |k, v| hash[k] = _to_hash(v) }
320
+ end
321
+ elsif value.respond_to? :to_hash
322
+ value.to_hash
323
+ else
324
+ value
325
+ end
326
+ end
327
+
328
+ end
329
+
330
+ end