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