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