Class: AmplitudeAPI::Identification

Inherits:
Object
  • Object
show all
Defined in:
lib/amplitude_api/identification.rb

Overview

AmplitudeAPI::Identification

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id: "", device_id: nil, user_properties: {}) ⇒ Identification

Create a new Identification

Parameters:

  • user_id (String) (defaults to: "")

    a user_id to associate with the identification

  • device_id (String) (defaults to: nil)

    a device_id to associate with the identification

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

    various properties to attach to the user identification



21
22
23
24
25
# File 'lib/amplitude_api/identification.rb', line 21

def initialize(user_id: "", device_id: nil, user_properties: {})
  self.user_id = user_id
  self.device_id = device_id if device_id
  self.user_properties = user_properties
end

Instance Attribute Details

#device_idString

Returns the device_id to be sent to Amplitude.

Returns:

  • (String)

    the device_id to be sent to Amplitude



11
12
13
# File 'lib/amplitude_api/identification.rb', line 11

def device_id
  @device_id
end

#user_idObject

Returns the value of attribute user_id.



8
9
10
# File 'lib/amplitude_api/identification.rb', line 8

def user_id
  @user_id
end

#user_propertiesString

Returns the user_properties to be attached to the Amplitude Identify.

Returns:

  • (String)

    the user_properties to be attached to the Amplitude Identify



14
15
16
# File 'lib/amplitude_api/identification.rb', line 14

def user_properties
  @user_properties
end

Instance Method Details

#==(other) ⇒ true, false

Compares +to_hash+ for equality

Returns:

  • (true, false)


49
50
51
52
53
54
55
# File 'lib/amplitude_api/identification.rb', line 49

def ==(other)
  if other.respond_to?(:to_hash)
    to_hash == other.to_hash
  else
    false
  end
end

#to_hashHash

Used for serialization and comparison

Returns:

  • (Hash)

    A serialized Event



39
40
41
42
43
44
# File 'lib/amplitude_api/identification.rb', line 39

def to_hash
  {
    user_id: user_id,
    user_properties: user_properties
  }.tap { |hsh| hsh[:device_id] = device_id if device_id }
end