Class: ContextModel

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/models/user/context_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, user_agent = nil, ip_address = nil, custom_variables = {}, variation_targeting_variables = {}, post_segmentation_variables = {}, platform_variables = {}, vwo = nil, session_id = nil, uuid = nil, bucketing_seed = nil) ⇒ ContextModel

Returns a new instance of ContextModel.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wingify/models/user/context_model.rb', line 22

def initialize(id = nil, user_agent = nil, ip_address = nil, custom_variables = {}, variation_targeting_variables = {}, post_segmentation_variables = {}, platform_variables = {}, vwo = nil, session_id = nil, uuid = nil, bucketing_seed = nil)
  @id = id
  @user_agent = user_agent
  @ip_address = ip_address
  @custom_variables = custom_variables || {}
  @variation_targeting_variables = variation_targeting_variables || {}
  @post_segmentation_variables = post_segmentation_variables || {}
  @platform_variables = platform_variables || {}
  @vwo = vwo
  @session_id = session_id
  @uuid = uuid
  @bucketing_seed = bucketing_seed
end

Instance Attribute Details

#bucketing_seedObject

Returns the value of attribute bucketing_seed.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def bucketing_seed
  @bucketing_seed
end

#custom_variablesObject

Returns the value of attribute custom_variables.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def custom_variables
  @custom_variables
end

#idObject

Returns the value of attribute id.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def id
  @id
end

#ip_addressObject

Returns the value of attribute ip_address.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def ip_address
  @ip_address
end

#platform_variablesObject

Returns the value of attribute platform_variables.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def platform_variables
  @platform_variables
end

#post_segmentation_variablesObject

Returns the value of attribute post_segmentation_variables.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def post_segmentation_variables
  @post_segmentation_variables
end

#session_idObject

Returns the value of attribute session_id.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def session_id
  @session_id
end

#user_agentObject

Returns the value of attribute user_agent.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def user_agent
  @user_agent
end

#uuidObject

Returns the value of attribute uuid.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def uuid
  @uuid
end

#variation_targeting_variablesObject

Returns the value of attribute variation_targeting_variables.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def variation_targeting_variables
  @variation_targeting_variables
end

#vwoObject

Returns the value of attribute vwo.



20
21
22
# File 'lib/wingify/models/user/context_model.rb', line 20

def vwo
  @vwo
end

Instance Method Details

#get_bucketing_seedObject



157
158
159
# File 'lib/wingify/models/user/context_model.rb', line 157

def get_bucketing_seed
  @bucketing_seed
end

#get_custom_variablesObject



101
102
103
# File 'lib/wingify/models/user/context_model.rb', line 101

def get_custom_variables
  @custom_variables
end

#get_idObject



77
78
79
# File 'lib/wingify/models/user/context_model.rb', line 77

def get_id
  @id
end

#get_ip_addressObject



93
94
95
# File 'lib/wingify/models/user/context_model.rb', line 93

def get_ip_address
  @ip_address
end

#get_platform_variablesObject



125
126
127
# File 'lib/wingify/models/user/context_model.rb', line 125

def get_platform_variables
  @platform_variables
end

#get_post_segmentation_variablesObject



117
118
119
# File 'lib/wingify/models/user/context_model.rb', line 117

def get_post_segmentation_variables
  @post_segmentation_variables
end

#get_session_idObject



141
142
143
# File 'lib/wingify/models/user/context_model.rb', line 141

def get_session_id
  @session_id
end

#get_user_agentObject



85
86
87
# File 'lib/wingify/models/user/context_model.rb', line 85

def get_user_agent
  @user_agent
end

#get_uuidObject



149
150
151
# File 'lib/wingify/models/user/context_model.rb', line 149

def get_uuid
  @uuid
end

#get_variation_targeting_variablesObject



109
110
111
# File 'lib/wingify/models/user/context_model.rb', line 109

def get_variation_targeting_variables
  @variation_targeting_variables
end

#get_vwoObject



133
134
135
# File 'lib/wingify/models/user/context_model.rb', line 133

def get_vwo
  @vwo
end

#model_from_dictionary(context) ⇒ Object

Creates a model instance from a hash (dictionary)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wingify/models/user/context_model.rb', line 37

def model_from_dictionary(context)
  if context.key?(:customVariables) && !context[:customVariables].is_a?(Hash)
    raise TypeError, 'Invalid context, customVariables should be a hash'
  end

  if context.key?(:userAgent) && !context[:userAgent].is_a?(String)
    raise TypeError, 'Invalid context, userAgent should be a string'
  end

  if context.key?(:ipAddress) && !context[:ipAddress].is_a?(String)
    raise TypeError, 'Invalid context, ipAddress should be a string'
  end

  @id = context[:id]
  @user_agent = context[:userAgent]
  @ip_address = context[:ipAddress]
  @custom_variables = context[:customVariables] if context.key?(:customVariables)
  @variation_targeting_variables = context[:variationTargetingVariables] if context.key?(:variationTargetingVariables)
  @post_segmentation_variables = context[:postSegmentationVariables] if context.key?(:postSegmentationVariables)
  @platform_variables = context[:platformVariables] if context.key?(:platformVariables)
  @vwo = ContextVWOModel.new.model_from_dictionary(context[:_vwo]) if context.key?(:_vwo)
  @bucketing_seed = context[:bucketingSeed].to_s if context.key?(:bucketingSeed)

  # check if sessionId is present in context and should be non null and non empty
  if context.key?(:sessionId) && !context[:sessionId].nil? && !context[:sessionId].to_s.empty?
    @session_id = context[:sessionId].to_i
  else
    @session_id = Time.now.to_i
  end

  # check if uuid is present in context and should be non null and non empty string
  if context.key?(:uuid) && context[:uuid].is_a?(String) && !context[:uuid].empty?
    @uuid = context[:uuid]
  else
    @uuid = UUIDUtil.get_uuid(id.to_s, SettingsService.instance..to_s)
  end

  self
end

#set_bucketing_seed(bucketing_seed) ⇒ Object



161
162
163
# File 'lib/wingify/models/user/context_model.rb', line 161

def set_bucketing_seed(bucketing_seed)
  @bucketing_seed = bucketing_seed
end

#set_custom_variables(custom_variables) ⇒ Object



105
106
107
# File 'lib/wingify/models/user/context_model.rb', line 105

def set_custom_variables(custom_variables)
  @custom_variables = custom_variables
end

#set_id(id) ⇒ Object



81
82
83
# File 'lib/wingify/models/user/context_model.rb', line 81

def set_id(id)
  @id = id
end

#set_ip_address(ip_address) ⇒ Object



97
98
99
# File 'lib/wingify/models/user/context_model.rb', line 97

def set_ip_address(ip_address)
  @ip_address = ip_address
end

#set_platform_variables(platform_variables) ⇒ Object



129
130
131
# File 'lib/wingify/models/user/context_model.rb', line 129

def set_platform_variables(platform_variables)
  @platform_variables = platform_variables
end

#set_post_segmentation_variables(post_segmentation_variables) ⇒ Object



121
122
123
# File 'lib/wingify/models/user/context_model.rb', line 121

def set_post_segmentation_variables(post_segmentation_variables)
  @post_segmentation_variables = post_segmentation_variables
end

#set_session_id(session_id) ⇒ Object



145
146
147
# File 'lib/wingify/models/user/context_model.rb', line 145

def set_session_id(session_id)
  @session_id = session_id
end

#set_user_agent(user_agent) ⇒ Object



89
90
91
# File 'lib/wingify/models/user/context_model.rb', line 89

def set_user_agent(user_agent)
  @user_agent = user_agent
end

#set_uuid(uuid) ⇒ Object



153
154
155
# File 'lib/wingify/models/user/context_model.rb', line 153

def set_uuid(uuid)
  @uuid = uuid
end

#set_variation_targeting_variables(variation_targeting_variables) ⇒ Object



113
114
115
# File 'lib/wingify/models/user/context_model.rb', line 113

def set_variation_targeting_variables(variation_targeting_variables)
  @variation_targeting_variables = variation_targeting_variables
end

#set_vwo(vwo) ⇒ Object



137
138
139
# File 'lib/wingify/models/user/context_model.rb', line 137

def set_vwo(vwo)
  @vwo = vwo
end