mparticle 1.0.4 → 1.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9bac3ffb5b4f05c631d5c2beecbacfdc02420027
4
- data.tar.gz: 0cf6073c991daaf5db99d34cfd3cf4eae3444bb6
2
+ SHA256:
3
+ metadata.gz: 8308b885dc052724e0e33e9c81c48b66962eaba058d4dbee48b23aa910c59409
4
+ data.tar.gz: 4ec2ce62682cc068114983cc33841cb589cc67d9c272c99ec41757c3d6397f7a
5
5
  SHA512:
6
- metadata.gz: 6dd990e982b42a19a25804c8885485944cce2b04023a4c85b4d661724ee7938fa684a5b0830c904bcf596a57d568700f7eb0c41ad1abd0e2118a349d9a8b824b
7
- data.tar.gz: 4721215db4f61185e90889cacf8b9553d00364c1392c00bca8b9c3f721d6a684096add75d015ecaf9b5be90f1cd740c3eee7e5e032ada2503b8cca388dada868
6
+ metadata.gz: aef4d8bfb6b787652096f7648d8e9d1e34f496143fc9ebda570dfb3980d2decec02b69b3ff883d187078e98904ecaeddb373bba2e5c1139097736297de8d1756
7
+ data.tar.gz: d59b4c4c687d46fa906629e7bca7bc420278356dec3f6bab162d480207bb9b8d073b82e068b3993bbea0317db581bf23de53eae2617c68e235d8bd1a069674d2
data/README.md CHANGED
@@ -41,6 +41,11 @@ api_instance = MParticle::EventsApi.new(config)
41
41
 
42
42
  batch = MParticle::Batch.new
43
43
  batch.environment = 'development'
44
+ batch.context = MParticle::BatchContext.new
45
+
46
+ batch.context.data_plan = MParticle::DataPlanContext.new
47
+ batch.context.data_plan.plan_id = 'my_plan_id'
48
+ batch.context.data_plan.plan_version = 1
44
49
 
45
50
  user_identities = MParticle::UserIdentities.new
46
51
  user_identities.customerid = '12345'
@@ -1,18 +1,18 @@
1
1
  # MParticle::AppEvent
2
2
 
3
3
  ## Properties
4
- Name | Type | Description | Notes
5
- ------------ | ------------- | ------------- | -------------
6
- **timestamp_unixtime_ms** | **Integer** | | [optional]
7
- **event_id** | **Integer** | | [optional]
8
- **source_message_id** | **String** | | [optional]
9
- **session_id** | **Integer** | | [optional]
10
- **session_uuid** | **String** | | [optional]
11
- **custom_attributes** | **Hash<String, String>** | | [optional]
12
- **location** | [**GeoLocation**](GeoLocation.md) | | [optional]
13
- **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional]
14
- **custom_event_type** | **String** | |
15
- **event_name** | **String** | |
16
- **media_info** | [**MediaInfo**](MediaInfo.md) | | [optional]
17
-
18
4
 
5
+ | Name | Type | Description | Notes |
6
+ | ------------------------- | ----------------------------------------------- | ----------- | ---------- |
7
+ | **timestamp_unixtime_ms** | **Integer** | | [optional] |
8
+ | **event_id** | **Integer** | | [optional] |
9
+ | **source_message_id** | **String** | | [optional] |
10
+ | **session_id** | **Integer** | | [optional] |
11
+ | **session_uuid** | **String** | | [optional] |
12
+ | **custom_attributes** | **Hash<String, String>** | | [optional] |
13
+ | **location** | [**GeoLocation**](GeoLocation.md) | | [optional] |
14
+ | **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional] |
15
+ | **custom_event_type** | **String** | |
16
+ | **event_name** | **String** | |
17
+ | **media_info** | [**MediaInfo**](MediaInfo.md) | | [optional] |
18
+ | **custom_flags** | **Hash<String, String>** | | [optional] |
@@ -18,3 +18,4 @@
18
18
  | **api_key** | **String** | | [optional] |
19
19
  | **mpid** | **Integer** | | [optional] |
20
20
  | **mp_deviceid** | **String** | | [optional] |
21
+ | **timestamp_unixtime_ms** | **Integer** | | [optional] |
@@ -0,0 +1,10 @@
1
+ # mParticle.CCPAConsentState
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ------------------------- | ----------- | ----------- | ----- |
7
+ | **consented** | **Boolean** | | |
8
+ | **timestamp_unixtime_ms** | **Number** | | |
9
+ | **location** | **String** | | |
10
+ | **hardware_id** | **String** | | |
@@ -1,22 +1,22 @@
1
1
  # MParticle::CommerceEvent
2
2
 
3
3
  ## Properties
4
- Name | Type | Description | Notes
5
- ------------ | ------------- | ------------- | -------------
6
- **timestamp_unixtime_ms** | **Integer** | | [optional]
7
- **event_id** | **Integer** | | [optional]
8
- **source_message_id** | **String** | | [optional]
9
- **session_id** | **Integer** | | [optional]
10
- **session_uuid** | **String** | | [optional]
11
- **custom_attributes** | **Hash<String, String>** | | [optional]
12
- **location** | [**GeoLocation**](GeoLocation.md) | | [optional]
13
- **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional]
14
- **product_action** | [**ProductAction**](ProductAction.md) | | [optional]
15
- **promotion_action** | [**PromotionAction**](PromotionAction.md) | | [optional]
16
- **product_impressions** | [**Array<ProductImpression>**](ProductImpression.md) | | [optional]
17
- **shopping_cart** | [**ShoppingCart**](ShoppingCart.md) | | [optional]
18
- **currency_code** | **String** | | [optional]
19
- **screen_name** | **String** | | [optional]
20
- **is_non_interactive** | **BOOLEAN** | | [optional]
21
-
22
4
 
5
+ | Name | Type | Description | Notes |
6
+ | ------------------------- | ---------------------------------------------------------- | ----------- | ---------- |
7
+ | **timestamp_unixtime_ms** | **Integer** | | [optional] |
8
+ | **event_id** | **Integer** | | [optional] |
9
+ | **source_message_id** | **String** | | [optional] |
10
+ | **session_id** | **Integer** | | [optional] |
11
+ | **session_uuid** | **String** | | [optional] |
12
+ | **custom_attributes** | **Hash<String, String>** | | [optional] |
13
+ | **location** | [**GeoLocation**](GeoLocation.md) | | [optional] |
14
+ | **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional] |
15
+ | **product_action** | [**ProductAction**](ProductAction.md) | | [optional] |
16
+ | **promotion_action** | [**PromotionAction**](PromotionAction.md) | | [optional] |
17
+ | **product_impressions** | [**Array<ProductImpression>**](ProductImpression.md) | | [optional] |
18
+ | **shopping_cart** | [**ShoppingCart**](ShoppingCart.md) | | [optional] |
19
+ | **currency_code** | **String** | | [optional] |
20
+ | **screen_name** | **String** | | [optional] |
21
+ | **is_non_interactive** | **BOOLEAN** | | [optional] |
22
+ | **custom_flags** | **Hash<String, String>** | | [optional] |
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Properties
4
4
 
5
- | Name | Type | Description | Notes |
6
- | ---- | ---- | ----------- | ----- |
7
-
5
+ | Name | Type | Description | Notes |
6
+ | --------- | -------- | ----------- | ----- |
7
+ | **gdpr ** | **Hash** | | |
8
+ | **ccpa ** | **Hash** | | |
@@ -1,17 +1,17 @@
1
1
  # MParticle::ScreenViewEvent
2
2
 
3
3
  ## Properties
4
- Name | Type | Description | Notes
5
- ------------ | ------------- | ------------- | -------------
6
- **timestamp_unixtime_ms** | **Integer** | | [optional]
7
- **event_id** | **Integer** | | [optional]
8
- **source_message_id** | **String** | | [optional]
9
- **session_id** | **Integer** | | [optional]
10
- **session_uuid** | **String** | | [optional]
11
- **custom_attributes** | **Hash<String, String>** | | [optional]
12
- **location** | [**GeoLocation**](GeoLocation.md) | | [optional]
13
- **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional]
14
- **screen_name** | **String** | |
15
- **activity_type** | **String** | | [optional]
16
-
17
4
 
5
+ | Name | Type | Description | Notes |
6
+ | ------------------------- | ----------------------------------------------- | ----------- | ---------- |
7
+ | **timestamp_unixtime_ms** | **Integer** | | [optional] |
8
+ | **event_id** | **Integer** | | [optional] |
9
+ | **source_message_id** | **String** | | [optional] |
10
+ | **session_id** | **Integer** | | [optional] |
11
+ | **session_uuid** | **String** | | [optional] |
12
+ | **custom_attributes** | **Hash<String, String>** | | [optional] |
13
+ | **location** | [**GeoLocation**](GeoLocation.md) | | [optional] |
14
+ | **device_current_state** | [**DeviceCurrentState**](DeviceCurrentState.md) | | [optional] |
15
+ | **screen_name** | **String** | |
16
+ | **activity_type** | **String** | | [optional] |
17
+ | **custom_flags** | **Hash<String, String>** | | [optional] |
@@ -13,5 +13,17 @@ Name | Type | Description | Notes
13
13
  **email** | **String** | | [optional]
14
14
  **_alias** | **String** | | [optional]
15
15
  **facebook_custom_audience_id** | **String** | | [optional]
16
+ **other_id_2** | **String** | | [optional]
17
+ **other_id_3** | **String** | | [optional]
18
+ **other_id_4** | **String** | | [optional]
19
+ **other_id_5** | **String** | | [optional]
20
+ **other_id_6** | **String** | | [optional]
21
+ **other_id_7** | **String** | | [optional]
22
+ **other_id_8** | **String** | | [optional]
23
+ **other_id_9** | **String** | | [optional]
24
+ **other_id_10** | **String** | | [optional]
25
+ **mobile_number** | **String** | | [optional]
26
+ **phone_number_2** | **String** | | [optional]
27
+ **phone_number_3** | **String** | | [optional]
16
28
 
17
29
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  # load the gem
4
4
  require 'mparticle'
5
+ require 'date'
5
6
  config = MParticle::Configuration.new
6
7
  config.api_key = 'REPLACE WITH API KEY'
7
8
  config.api_secret = 'REPLACE WITH API SECRET'
@@ -10,6 +11,7 @@ config.api_secret = 'REPLACE WITH API SECRET'
10
11
  api_instance = MParticle::EventsApi.new(config)
11
12
 
12
13
  batch = MParticle::Batch.new
14
+ batch.timestamp_unixtime_ms = DateTime.now.strftime('%Q').to_i
13
15
  batch.environment = 'development'
14
16
 
15
17
  user_identities = MParticle::UserIdentities.new
@@ -19,10 +21,45 @@ app_event = MParticle::AppEvent.new
19
21
  app_event.event_name = 'Test event'
20
22
  app_event.custom_event_type = 'navigation'
21
23
  app_event.custom_attributes = { 'Test key' => 'Test value' }
24
+ app_event.custom_flags = {
25
+ 'answer': 42,
26
+ 'question': 'What is the answer to life, the universe, and everything?',
27
+ 'dolphins': [
28
+ 'So long',
29
+ 'Thanks for all the fish'
30
+ ]
31
+ }
32
+
33
+ screen_view_event = MParticle::ScreenViewEvent.new
34
+ screen_view_event.custom_flags = {
35
+ 'answer': 42,
36
+ 'question': 'What is the answer to life, the universe, and everything?',
37
+ 'dolphins': [
38
+ 'So long',
39
+ 'Thanks for all the fish'
40
+ ]
41
+ }
42
+
43
+ commerce_event = MParticle::CommerceEvent.new
44
+ commerce_event = {
45
+ 'answer': 42,
46
+ 'question': 'What is the answer to life, the universe, and everything?',
47
+ 'dolphins': [
48
+ 'So long',
49
+ 'Thanks for all the fish'
50
+ ]
51
+ }
22
52
 
23
53
  batch.events = [MParticle::SessionStartEvent.new, app_event, MParticle::SessionEndEvent.new]
24
54
  batch.user_identities = user_identities
25
55
 
56
+ ccpa_consent_state = MParticle::CCPAConsentState.new
57
+ ccpa_consent_state.document = 'document.agreement.v3'
58
+ ccpa_consent_state.consented = true
59
+ ccpa_consent_state.timestamp_unixtime_ms = Time.now.to_i
60
+ ccpa_consent_state.location = 'mparticle.test/signup'
61
+ ccpa_consent_state.hardware_id = 'IDFA:a5d96n32-224a-3b11-1088-a202695bc710'
62
+
26
63
  gdpr_consent_state = MParticle::GDPRConsentState.new
27
64
  gdpr_consent_state.document = 'document_agreement.v2'
28
65
  gdpr_consent_state.consented = true
@@ -32,8 +69,9 @@ gdpr_consent_state.hardware_id = 'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'
32
69
 
33
70
  consent_state = MParticle::ConsentState.new
34
71
  # Make sure this purpose matches your consent purpose in
35
- # Setup > GDPR Settings
36
- # https://docs.mparticle.com/guides/consent-management/#enabling-gdpr-consent-management
72
+ # Workspace Settings > Workspace > Regulations
73
+ # https://docs.mparticle.com/guides/consent-management/
74
+ consent_state.ccpa = { 'data_sale_opt_out' => ccpa_consent_state }
37
75
  consent_state.gdpr = { 'document_agreement' => gdpr_consent_state }
38
76
  batch.consent_state = consent_state
39
77
 
@@ -50,5 +88,5 @@ begin
50
88
  # wait for the thread, otherwise process may exit too early
51
89
  thread.join
52
90
  rescue MParticle::ApiError => e
53
- puts "Exception when calling mParticle: #{e}"
91
+ puts "Exception when calling mParticle: #{e.response_body}"
54
92
  end
@@ -13,6 +13,7 @@ require 'mparticle/models/application_state_transition_event'
13
13
  require 'mparticle/models/attribution_info'
14
14
  require 'mparticle/models/batch'
15
15
  require 'mparticle/models/breadcrumb_event'
16
+ require 'mparticle/models/ccpa_consent_state'
16
17
  require 'mparticle/models/commerce_event'
17
18
  require 'mparticle/models/consent_state'
18
19
  require 'mparticle/models/crash_report_event'
@@ -40,6 +41,8 @@ require 'mparticle/models/session_start_event'
40
41
  require 'mparticle/models/shopping_cart'
41
42
  require 'mparticle/models/source_information'
42
43
  require 'mparticle/models/user_identities'
44
+ require 'mparticle/models/batch_context'
45
+ require 'mparticle/models/data_plan_context'
43
46
 
44
47
  # APIs
45
48
  require 'mparticle/api/events_api'
@@ -19,7 +19,7 @@ module MParticle
19
19
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
20
20
  def initialize(config)
21
21
  @config = config
22
- @user_agent = "mParticle Ruby client/1.0.3"
22
+ @user_agent = "mParticle Ruby client/1.0.9"
23
23
  @default_headers = {
24
24
  'Content-Type' => "application/json",
25
25
  'User-Agent' => @user_agent
@@ -25,6 +25,8 @@ module MParticle
25
25
 
26
26
  attr_accessor :media_info
27
27
 
28
+ attr_accessor :custom_flags
29
+
28
30
  class EnumAttributeValidator
29
31
  attr_reader :datatype
30
32
  attr_reader :allowable_values
@@ -60,7 +62,8 @@ module MParticle
60
62
  :'device_current_state' => :'device_current_state',
61
63
  :'custom_event_type' => :'custom_event_type',
62
64
  :'event_name' => :'event_name',
63
- :'media_info' => :'media_info'
65
+ :'media_info' => :'media_info',
66
+ :'custom_flags' => :'custom_flags',
64
67
  }
65
68
  end
66
69
 
@@ -77,7 +80,8 @@ module MParticle
77
80
  :'device_current_state' => :'DeviceCurrentState',
78
81
  :'custom_event_type' => :'String',
79
82
  :'event_name' => :'String',
80
- :'media_info' => :'MediaInfo'
83
+ :'media_info' => :'MediaInfo',
84
+ :'custom_flags' => :'Hash<String, String>',
81
85
  }
82
86
  end
83
87
 
@@ -135,6 +139,10 @@ module MParticle
135
139
  self.media_info = attributes[:'media_info']
136
140
  end
137
141
 
142
+ if attributes.has_key?(:'custom_flags')
143
+ self.custom_flags = attributes[:'custom_flags']
144
+ end
145
+
138
146
  end
139
147
 
140
148
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -187,7 +195,8 @@ module MParticle
187
195
  device_current_state == o.device_current_state &&
188
196
  custom_event_type == o.custom_event_type &&
189
197
  event_name == o.event_name &&
190
- media_info == o.media_info
198
+ media_info == o.media_info &&
199
+ custom_flags == o.custom_flags
191
200
  end
192
201
 
193
202
  # @see the `==` method
@@ -199,7 +208,7 @@ module MParticle
199
208
  # Calculates hash code according to all attributes.
200
209
  # @return [Fixnum] Hash code
201
210
  def hash
202
- [timestamp_unixtime_ms, event_id, source_message_id, session_id, session_uuid, custom_attributes, location, device_current_state, custom_event_type, event_name, media_info].hash
211
+ [timestamp_unixtime_ms, event_id, source_message_id, session_id, session_uuid, custom_attributes, location, device_current_state, custom_event_type, event_name, media_info, custom_flags].hash
203
212
  end
204
213
 
205
214
  # Builds the object from hash
@@ -31,6 +31,10 @@ module MParticle
31
31
 
32
32
  attr_accessor :mp_deviceid
33
33
 
34
+ attr_accessor :timestamp_unixtime_ms
35
+
36
+ attr_accessor :context
37
+
34
38
  class EnumAttributeValidator
35
39
  attr_reader :datatype
36
40
  attr_reader :allowable_values
@@ -109,7 +113,9 @@ module MParticle
109
113
  :'user_identities' => :'user_identities',
110
114
  :'api_key' => :'api_key',
111
115
  :'mpid' => :'mpid',
112
- :'mp_deviceid' => :'mp_deviceid'
116
+ :'mp_deviceid' => :'mp_deviceid',
117
+ :'timestamp_unixtime_ms' => :'timestamp_unixtime_ms',
118
+ :'context' => :'context'
113
119
  }
114
120
  end
115
121
 
@@ -128,7 +134,10 @@ module MParticle
128
134
  :'user_identities' => :'UserIdentities',
129
135
  :'api_key' => :'String',
130
136
  :'mpid' => :'Integer',
131
- :'mp_deviceid' => :'String'
137
+ :'mp_deviceid' => :'String',
138
+ :'timestamp_unixtime_ms' => :'Integer',
139
+ :'consent_state' => :'ConsentState',
140
+ :'context' => :'BatchContext'
132
141
  }
133
142
  end
134
143
 
@@ -196,6 +205,18 @@ module MParticle
196
205
  self.mp_deviceid = attributes[:'mp_deviceid']
197
206
  end
198
207
 
208
+ if attributes.has_key?(:'timestamp_unixtime_ms')
209
+ self.timestamp_unixtime_ms = attributes[:'timestamp_unixtime_ms']
210
+ end
211
+
212
+ if attributes.has_key?(:'consent_state')
213
+ self.consent_state = attributes[:'consent_state']
214
+ end
215
+
216
+ if attributes.has_key?(:'context')
217
+ self.context = attributes[:'context']
218
+ end
219
+
199
220
  end
200
221
 
201
222
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -245,7 +266,8 @@ module MParticle
245
266
  user_identities == o.user_identities &&
246
267
  api_key == o.api_key &&
247
268
  mpid == o.mpid &&
248
- mp_deviceid == o.mp_deviceid
269
+ mp_deviceid == o.mp_deviceid &&
270
+ timestamp_unixtime_ms == o.timestamp_unixtime_ms
249
271
  end
250
272
 
251
273
  # @see the `==` method
@@ -257,7 +279,7 @@ module MParticle
257
279
  # Calculates hash code according to all attributes.
258
280
  # @return [Fixnum] Hash code
259
281
  def hash
260
- [events, source_request_id, environment, ip, schema_version, device_info, application_info, user_attributes, deleted_user_attributes, user_identities, api_key, mpid, mp_deviceid].hash
282
+ [events, source_request_id, environment, ip, schema_version, device_info, application_info, user_attributes, deleted_user_attributes, user_identities, api_key, mpid, mp_deviceid, timestamp_unixtime_ms].hash
261
283
  end
262
284
 
263
285
  # Builds the object from hash
@@ -0,0 +1,177 @@
1
+ require 'date'
2
+
3
+ module MParticle
4
+
5
+ class BatchContext
6
+ attr_accessor :data_plan
7
+
8
+
9
+ # Attribute mapping from ruby-style variable name to JSON key.
10
+ def self.attribute_map
11
+ {
12
+ :'data_plan' => :'data_plan'
13
+ }
14
+ end
15
+
16
+ # Attribute type mapping.
17
+ def self.swagger_types
18
+ {
19
+ :'data_plan' => :'DataPlanContext'
20
+ }
21
+ end
22
+
23
+ # Initializes the object
24
+ # @param [Hash] attributes Model attributes in the form of hash
25
+ def initialize(attributes = {})
26
+ return unless attributes.is_a?(Hash)
27
+
28
+ # convert string to symbol for hash key
29
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
30
+
31
+ if attributes.has_key?(:'data_plan')
32
+ self.data_plan = attributes[:'data_plan']
33
+ end
34
+
35
+ end
36
+
37
+ # Show invalid properties with the reasons. Usually used together with valid?
38
+ # @return Array for valid properies with the reasons
39
+ def list_invalid_properties
40
+ invalid_properties = Array.new
41
+ return invalid_properties
42
+ end
43
+
44
+ # Check to see if the all the properties in the model are valid
45
+ # @return true if the model is valid
46
+ def valid?
47
+ return true
48
+ end
49
+
50
+ # Checks equality by comparing each attribute.
51
+ # @param [Object] Object to be compared
52
+ def ==(o)
53
+ return true if self.equal?(o)
54
+ self.class == o.class &&
55
+ data_plan == o.data_plan
56
+
57
+ end
58
+
59
+ # @see the `==` method
60
+ # @param [Object] Object to be compared
61
+ def eql?(o)
62
+ self == o
63
+ end
64
+
65
+ # Calculates hash code according to all attributes.
66
+ # @return [Fixnum] Hash code
67
+ def hash
68
+ [data_plan].hash
69
+ end
70
+
71
+ # Builds the object from hash
72
+ # @param [Hash] attributes Model attributes in the form of hash
73
+ # @return [Object] Returns the model itself
74
+ def build_from_hash(attributes)
75
+ return nil unless attributes.is_a?(Hash)
76
+ self.class.swagger_types.each_pair do |key, type|
77
+ if type =~ /\AArray<(.*)>/i
78
+ # check to ensure the input is an array given that the the attribute
79
+ # is documented as an array but the input is not
80
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
81
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
82
+ end
83
+ elsif !attributes[self.class.attribute_map[key]].nil?
84
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
85
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
86
+ end
87
+
88
+ self
89
+ end
90
+
91
+ # Deserializes the data based on type
92
+ # @param string type Data type
93
+ # @param string value Value to be deserialized
94
+ # @return [Object] Deserialized data
95
+ def _deserialize(type, value)
96
+ case type.to_sym
97
+ when :DateTime
98
+ DateTime.parse(value)
99
+ when :Date
100
+ Date.parse(value)
101
+ when :String
102
+ value.to_s
103
+ when :Integer
104
+ value.to_i
105
+ when :Float
106
+ value.to_f
107
+ when :BOOLEAN
108
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
109
+ true
110
+ else
111
+ false
112
+ end
113
+ when :Object
114
+ # generic object (usually a Hash), return directly
115
+ value
116
+ when /\AArray<(?<inner_type>.+)>\z/
117
+ inner_type = Regexp.last_match[:inner_type]
118
+ value.map { |v| _deserialize(inner_type, v) }
119
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
120
+ k_type = Regexp.last_match[:k_type]
121
+ v_type = Regexp.last_match[:v_type]
122
+ {}.tap do |hash|
123
+ value.each do |k, v|
124
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
125
+ end
126
+ end
127
+ else # model
128
+ temp_model = MParticle.const_get(type).new
129
+ temp_model.build_from_hash(value)
130
+ end
131
+ end
132
+
133
+ # Returns the string representation of the object
134
+ # @return [String] String presentation of the object
135
+ def to_s
136
+ to_hash.to_s
137
+ end
138
+
139
+ # to_body is an alias to to_hash (backward compatibility)
140
+ # @return [Hash] Returns the object in the form of hash
141
+ def to_body
142
+ to_hash
143
+ end
144
+
145
+ # Returns the object in the form of hash
146
+ # @return [Hash] Returns the object in the form of hash
147
+ def to_hash
148
+ hash = {}
149
+ self.class.attribute_map.each_pair do |attr, param|
150
+ value = self.send(attr)
151
+ next if value.nil?
152
+ hash[param] = _to_hash(value)
153
+ end
154
+ hash
155
+ end
156
+
157
+ # Outputs non-array value in the form of hash
158
+ # For object, use to_hash. Otherwise, just return the value
159
+ # @param [Object] value Any valid value
160
+ # @return [Hash] Returns the value in the form of hash
161
+ def _to_hash(value)
162
+ if value.is_a?(Array)
163
+ value.compact.map{ |v| _to_hash(v) }
164
+ elsif value.is_a?(Hash)
165
+ {}.tap do |hash|
166
+ value.each { |k, v| hash[k] = _to_hash(v) }
167
+ end
168
+ elsif value.respond_to? :to_hash
169
+ value.to_hash
170
+ else
171
+ value
172
+ end
173
+ end
174
+
175
+ end
176
+
177
+ end