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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/statsig_user.rb', line 21

def initialize(user_hash)
  @user_id = nil
  @email = nil
  @ip = nil
  @user_agent = nil
  @country = nil
  @locale = nil
  @app_version = nil
  @custom = nil
  @private_attributes = nil
  @custom_ids = nil
  @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'] if user_hash['custom'].is_a? Hash
    @statsig_environment = user_hash['statsigEnvironment']
    @private_attributes = user_hash['privateAttributes'] if user_hash['privateAttributes'].is_a? Hash
    custom_ids = user_hash['customIDs'] || user_hash['custom_ids']
    @custom_ids = custom_ids if custom_ids.is_a? Hash
  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

#custom_idsObject

Returns the value of attribute custom_ids.



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

def custom_ids
  @custom_ids
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.



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

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



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

def custom
  @custom
end

#custom=(value) ⇒ Object



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

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

#serialize(for_logging) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/statsig_user.rb', line 50

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,
    'customIDs' => @custom_ids,
  }
  if for_logging
    hash.delete('privateAttributes')
  end
  hash.compact
end

#value_lookupObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/statsig_user.rb', line 70

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