Class: OneSignal::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/onesignal/models/player.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Player

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/onesignal/models/player.rb', line 187

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `OneSignal::Player` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `OneSignal::Player`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'invalid_identifier')
    self.invalid_identifier = attributes[:'invalid_identifier']
  end

  if attributes.key?(:'app_id')
    self.app_id = attributes[:'app_id']
  end

  if attributes.key?(:'device_type')
    self.device_type = attributes[:'device_type']
  end

  if attributes.key?(:'external_user_id')
    self.external_user_id = attributes[:'external_user_id']
  end

  if attributes.key?(:'external_user_id_auth_hash')
    self.external_user_id_auth_hash = attributes[:'external_user_id_auth_hash']
  end

  if attributes.key?(:'email_auth_hash')
    self.email_auth_hash = attributes[:'email_auth_hash']
  end

  if attributes.key?(:'identifier')
    self.identifier = attributes[:'identifier']
  end

  if attributes.key?(:'language')
    self.language = attributes[:'language']
  end

  if attributes.key?(:'timezone')
    self.timezone = attributes[:'timezone']
  end

  if attributes.key?(:'game_version')
    self.game_version = attributes[:'game_version']
  end

  if attributes.key?(:'device_model')
    self.device_model = attributes[:'device_model']
  end

  if attributes.key?(:'device_os')
    self.device_os = attributes[:'device_os']
  end

  if attributes.key?(:'ad_id')
    self.ad_id = attributes[:'ad_id']
  end

  if attributes.key?(:'sdk')
    self.sdk = attributes[:'sdk']
  end

  if attributes.key?(:'session_count')
    self.session_count = attributes[:'session_count']
  end

  if attributes.key?(:'tags')
    self.tags = attributes[:'tags']
  end

  if attributes.key?(:'amount_spent')
    self.amount_spent = attributes[:'amount_spent']
  end

  if attributes.key?(:'created_at')
    self.created_at = attributes[:'created_at']
  end

  if attributes.key?(:'playtime')
    self.playtime = attributes[:'playtime']
  end

  if attributes.key?(:'badge_count')
    self.badge_count = attributes[:'badge_count']
  end

  if attributes.key?(:'last_active')
    self.last_active = attributes[:'last_active']
  end

  if attributes.key?(:'notification_types')
    self.notification_types = attributes[:'notification_types']
  end

  if attributes.key?(:'test_type')
    self.test_type = attributes[:'test_type']
  end

  if attributes.key?(:'long')
    self.long = attributes[:'long']
  end

  if attributes.key?(:'lat')
    self.lat = attributes[:'lat']
  end

  if attributes.key?(:'country')
    self.country = attributes[:'country']
  end
end

Instance Attribute Details

#ad_idObject

The ad id for the device’s platform: Android = Advertising Id iOS = identifierForVendor WP8.0 = DeviceUniqueId WP8.1 = AdvertisingId



57
58
59
# File 'lib/onesignal/models/player.rb', line 57

def ad_id
  @ad_id
end

#amount_spentObject

Amount the user has spent in USD, up to two decimal places



69
70
71
# File 'lib/onesignal/models/player.rb', line 69

def amount_spent
  @amount_spent
end

#app_idObject

Returns the value of attribute app_id.



24
25
26
# File 'lib/onesignal/models/player.rb', line 24

def app_id
  @app_id
end

#badge_countObject

Current iOS badge count displayed on the app icon NOTE: Not supported for apps created after June 2018, since badge count for apps created after this date are handled on the client.



78
79
80
# File 'lib/onesignal/models/player.rb', line 78

def badge_count
  @badge_count
end

#countryObject

Country code in the ISO 3166-1 Alpha 2 format



96
97
98
# File 'lib/onesignal/models/player.rb', line 96

def country
  @country
end

#created_atObject

Unixtime when the player joined the game



72
73
74
# File 'lib/onesignal/models/player.rb', line 72

def created_at
  @created_at
end

#device_modelObject

Device make and model. Example: iPhone5,1



51
52
53
# File 'lib/onesignal/models/player.rb', line 51

def device_model
  @device_model
end

#device_osObject

Device operating system version. Example: 7.0.4



54
55
56
# File 'lib/onesignal/models/player.rb', line 54

def device_os
  @device_os
end

#device_typeObject

Required The device’s platform: 0 = iOS 1 = Android 2 = Amazon 3 = WindowsPhone (MPNS) 4 = Chrome Apps / Extensions 5 = Chrome Web Push 6 = Windows (WNS) 7 = Safari 8 = Firefox 9 = MacOS 10 = Alexa 11 = Email 13 = For Huawei App Gallery Builds SDK Setup. Not for Huawei Devices using FCM 14 = SMS



27
28
29
# File 'lib/onesignal/models/player.rb', line 27

def device_type
  @device_type
end

#email_auth_hashObject

Email - Only required if you have enabled Identity Verification and device_type is email (11).



36
37
38
# File 'lib/onesignal/models/player.rb', line 36

def email_auth_hash
  @email_auth_hash
end

#external_user_idObject

a custom user ID



30
31
32
# File 'lib/onesignal/models/player.rb', line 30

def external_user_id
  @external_user_id
end

#external_user_id_auth_hashObject

Only required if you have enabled Identity Verification and device_type is NOT 11 email.



33
34
35
# File 'lib/onesignal/models/player.rb', line 33

def external_user_id_auth_hash
  @external_user_id_auth_hash
end

#game_versionObject

Version of your app. Example: 1.1



48
49
50
# File 'lib/onesignal/models/player.rb', line 48

def game_version
  @game_version
end

#idObject

The device’s OneSignal ID



19
20
21
# File 'lib/onesignal/models/player.rb', line 19

def id
  @id
end

#identifierObject

Recommended: For Push Notifications, this is the Push Token Identifier from Google or Apple. For Apple Push identifiers, you must strip all non alphanumeric characters. Examples: iOS: 7abcd558f29d0b1f048083e2834ad8ea4b3d87d8ad9c088b33c132706ff445f0 Android: APA91bHbYHk7aq-Uam_2pyJ2qbZvqllyyh2wjfPRaw5gLEX2SUlQBRvOc6sck1sa7H7nGeLNlDco8lXj83HWWwzV… For Email Addresses, set the full email address [email protected] and make sure to set device_type to 11.



39
40
41
# File 'lib/onesignal/models/player.rb', line 39

def identifier
  @identifier
end

#invalid_identifierObject

If true, this is the equivalent of a user being Unsubscribed



22
23
24
# File 'lib/onesignal/models/player.rb', line 22

def invalid_identifier
  @invalid_identifier
end

#languageObject

Language code. Typically lower case two letters, except for Chinese where it must be one of zh-Hans or zh-Hant. Example: en



42
43
44
# File 'lib/onesignal/models/player.rb', line 42

def language
  @language
end

#last_activeObject

Unixtime when the player was last active



81
82
83
# File 'lib/onesignal/models/player.rb', line 81

def last_active
  @last_active
end

#latObject

Latitude of the device, used for geotagging to segment on.



93
94
95
# File 'lib/onesignal/models/player.rb', line 93

def lat
  @lat
end

#longObject

Longitude of the device, used for geotagging to segment on.



90
91
92
# File 'lib/onesignal/models/player.rb', line 90

def long
  @long
end

#notification_typesObject

1 = subscribed -2 = unsubscribed iOS - These values are set each time the user opens the app from the SDK. Use the SDK function set Subscription instead. Android - You may set this but you can no longer use the SDK method setSubscription later in your app as it will create synchronization issues.



84
85
86
# File 'lib/onesignal/models/player.rb', line 84

def notification_types
  @notification_types
end

#playtimeObject

Seconds player was running your app.



75
76
77
# File 'lib/onesignal/models/player.rb', line 75

def playtime
  @playtime
end

#sdkObject

Name and version of the sdk/plugin that’s calling this API method (if any)



60
61
62
# File 'lib/onesignal/models/player.rb', line 60

def sdk
  @sdk
end

#session_countObject

Number of times the user has played the game, defaults to 1



63
64
65
# File 'lib/onesignal/models/player.rb', line 63

def session_count
  @session_count
end

#tagsObject

Custom tags for the player. Only support string and integer key value pairs. Does not support arrays or other nested objects. Setting a tag value to null or an empty string will remove the tag. Example: "foo":"bar","this":"that" Limitations: - 100 tags per call - Android SDK users: tags cannot be removed or changed via API if set through SDK sendTag methods. Recommended to only tag devices with 1 kilobyte of data Please consider using your own Database to save more than 1 kilobyte of data. See: Internal Database & CRM



66
67
68
# File 'lib/onesignal/models/player.rb', line 66

def tags
  @tags
end

#test_typeObject

This is used in deciding whether to use your iOS Sandbox or Production push certificate when sending a push when both have been uploaded. Set to the iOS provisioning profile that was used to build your app. 1 = Development 2 = Ad-Hoc Omit this field for App Store builds.



87
88
89
# File 'lib/onesignal/models/player.rb', line 87

def test_type
  @test_type
end

#timezoneObject

Number of seconds away from UTC. Example: -28800



45
46
47
# File 'lib/onesignal/models/player.rb', line 45

def timezone
  @timezone
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



132
133
134
# File 'lib/onesignal/models/player.rb', line 132

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/onesignal/models/player.rb', line 99

def self.attribute_map
  {
    :'id' => :'id',
    :'invalid_identifier' => :'invalid_identifier',
    :'app_id' => :'app_id',
    :'device_type' => :'device_type',
    :'external_user_id' => :'external_user_id',
    :'external_user_id_auth_hash' => :'external_user_id_auth_hash',
    :'email_auth_hash' => :'email_auth_hash',
    :'identifier' => :'identifier',
    :'language' => :'language',
    :'timezone' => :'timezone',
    :'game_version' => :'game_version',
    :'device_model' => :'device_model',
    :'device_os' => :'device_os',
    :'ad_id' => :'ad_id',
    :'sdk' => :'sdk',
    :'session_count' => :'session_count',
    :'tags' => :'tags',
    :'amount_spent' => :'amount_spent',
    :'created_at' => :'created_at',
    :'playtime' => :'playtime',
    :'badge_count' => :'badge_count',
    :'last_active' => :'last_active',
    :'notification_types' => :'notification_types',
    :'test_type' => :'test_type',
    :'long' => :'long',
    :'lat' => :'lat',
    :'country' => :'country'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



376
377
378
# File 'lib/onesignal/models/player.rb', line 376

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/onesignal/models/player.rb', line 170

def self.openapi_nullable
  Set.new([
    :'external_user_id',
    :'identifier',
    :'timezone',
    :'game_version',
    :'device_model',
    :'device_os',
    :'ad_id',
    :'sdk',
    :'tags',
    :'test_type',
  ])
end

.openapi_typesObject

Attribute type mapping.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/onesignal/models/player.rb', line 137

def self.openapi_types
  {
    :'id' => :'String',
    :'invalid_identifier' => :'Boolean',
    :'app_id' => :'String',
    :'device_type' => :'Integer',
    :'external_user_id' => :'String',
    :'external_user_id_auth_hash' => :'String',
    :'email_auth_hash' => :'String',
    :'identifier' => :'String',
    :'language' => :'String',
    :'timezone' => :'Integer',
    :'game_version' => :'String',
    :'device_model' => :'String',
    :'device_os' => :'String',
    :'ad_id' => :'String',
    :'sdk' => :'String',
    :'session_count' => :'Integer',
    :'tags' => :'Object',
    :'amount_spent' => :'Float',
    :'created_at' => :'Integer',
    :'playtime' => :'Integer',
    :'badge_count' => :'Integer',
    :'last_active' => :'Integer',
    :'notification_types' => :'Integer',
    :'test_type' => :'Integer',
    :'long' => :'Float',
    :'lat' => :'Float',
    :'country' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/onesignal/models/player.rb', line 329

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      invalid_identifier == o.invalid_identifier &&
      app_id == o.app_id &&
      device_type == o.device_type &&
      external_user_id == o.external_user_id &&
      external_user_id_auth_hash == o.external_user_id_auth_hash &&
      email_auth_hash == o.email_auth_hash &&
      identifier == o.identifier &&
      language == o.language &&
      timezone == o.timezone &&
      game_version == o.game_version &&
      device_model == o.device_model &&
      device_os == o.device_os &&
      ad_id == o.ad_id &&
      sdk == o.sdk &&
      session_count == o.session_count &&
      tags == o.tags &&
      amount_spent == o.amount_spent &&
      created_at == o.created_at &&
      playtime == o.playtime &&
      badge_count == o.badge_count &&
      last_active == o.last_active &&
      notification_types == o.notification_types &&
      test_type == o.test_type &&
      long == o.long &&
      lat == o.lat &&
      country == o.country
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/onesignal/models/player.rb', line 407

def _deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = OneSignal.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/onesignal/models/player.rb', line 478

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/onesignal/models/player.rb', line 383

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{key}=", nil)
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


363
364
365
# File 'lib/onesignal/models/player.rb', line 363

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



369
370
371
# File 'lib/onesignal/models/player.rb', line 369

def hash
  [id, invalid_identifier, app_id, device_type, external_user_id, external_user_id_auth_hash, email_auth_hash, identifier, language, timezone, game_version, device_model, device_os, ad_id, sdk, session_count, tags, amount_spent, created_at, playtime, badge_count, last_active, notification_types, test_type, long, lat, country].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



311
312
313
314
315
316
317
318
# File 'lib/onesignal/models/player.rb', line 311

def list_invalid_properties
  invalid_properties = Array.new
  if @device_type.nil?
    invalid_properties.push('invalid value for "device_type", device_type cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



454
455
456
# File 'lib/onesignal/models/player.rb', line 454

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/onesignal/models/player.rb', line 460

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



448
449
450
# File 'lib/onesignal/models/player.rb', line 448

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



322
323
324
325
# File 'lib/onesignal/models/player.rb', line 322

def valid?
  return false if @device_type.nil?
  true
end