Class: StatsigUser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_hash) ⇒ StatsigUser

Returns a new instance of StatsigUser.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/statsig_user.rb', line 20

def initialize(user_hash)
  @statsig_environment = Hash.new
  if user_hash.is_a?(Hash)
    @user_id = user_hash['userID'] || user_hash['user_id']
    @user_id = @user_id.to_s unless @user_id.nil?
    @email = user_hash['email']
    @ip = user_hash['ip']
    @user_agent = user_hash['userAgent'] || user_hash['user_agent']
    @country = user_hash['country']
    @locale = user_hash['locale']
    @app_version = user_hash['appVersion'] || user_hash['app_version']
    @custom = user_hash['custom']
    @statsig_environment = user_hash['statsigEnvironment']
    @private_attributes = user_hash['privateAttributes']
  end
end

Instance Attribute Details

#app_versionObject

Returns the value of attribute app_version.



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

def app_version
  @app_version
end

#countryObject

Returns the value of attribute country.



6
7
8
# File 'lib/statsig_user.rb', line 6

def country
  @country
end

#emailObject

Returns the value of attribute email.



3
4
5
# File 'lib/statsig_user.rb', line 3

def email
  @email
end

#ipObject

Returns the value of attribute ip.



4
5
6
# File 'lib/statsig_user.rb', line 4

def ip
  @ip
end

#localeObject

Returns the value of attribute locale.



7
8
9
# File 'lib/statsig_user.rb', line 7

def locale
  @locale
end

#private_attributesObject

Returns the value of attribute private_attributes.



10
11
12
# File 'lib/statsig_user.rb', line 10

def private_attributes
  @private_attributes
end

#statsig_environmentObject

Returns the value of attribute statsig_environment.



9
10
11
# File 'lib/statsig_user.rb', line 9

def statsig_environment
  @statsig_environment
end

#user_agentObject

Returns the value of attribute user_agent.



5
6
7
# File 'lib/statsig_user.rb', line 5

def user_agent
  @user_agent
end

#user_idObject

Returns the value of attribute user_id.



2
3
4
# File 'lib/statsig_user.rb', line 2

def user_id
  @user_id
end

Instance Method Details

#customObject



12
13
14
# File 'lib/statsig_user.rb', line 12

def custom
  @custom
end

#custom=(value) ⇒ Object



16
17
18
# File 'lib/statsig_user.rb', line 16

def custom=(value)
  @custom = value.is_a?(Hash) ? value : Hash.new
end

#serialize(for_logging) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/statsig_user.rb', line 37

def serialize(for_logging)
  hash = {
    'userID' => @user_id,
    'email' => @email,
    'ip' => @ip,
    'userAgent' => @user_agent,
    'country' => @country,
    'locale' => @locale,
    'appVersion' => @app_version,
    'custom' => @custom,
    'statsigEnvironment' => @statsig_environment,
    'privateAttributes' => @private_attributes,
  }
  if for_logging
    hash.delete('privateAttributes')
  end
  hash
end

#value_lookupObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/statsig_user.rb', line 56

def value_lookup
  {
    'userID' => @user_id,
    'userid' => @user_id,
    'user_id' => @user_id,
    'email' => @email,
    'ip' => @ip,
    'userAgent' => @user_agent,
    'useragent' => @user_agent,
    'user_agent' => @user_agent,
    'country' => @country,
    'locale' => @locale,
    'appVersion' => @app_version,
    'appversion' => @app_version,
    'app_version' => @app_version,
    'custom' => @custom,
    'privateAttributes' => @private_attributes,
  }
end