Module: Kameleoon::Cookie Private

Included in:
Client
Defined in:
lib/kameleoon/cookie.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#check_visitor_code(visitor_code) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
40
# File 'lib/kameleoon/cookie.rb', line 34

def check_visitor_code(visitor_code) 
  if visitor_code.nil?
    check_default_visitor_code('')
  elsif
    check_default_visitor_code(visitor_code)
  end
end

#obtain_hash_double(visitor_code, respool_times = {}, container_id = '') ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
# File 'lib/kameleoon/cookie.rb', line 25

def obtain_hash_double(visitor_code, respool_times = {}, container_id = '')
  identifier = visitor_code.to_s
  identifier += container_id.to_s
  if !respool_times.nil? && !respool_times.empty?
    identifier += respool_times.sort.to_h.values.join.to_s
  end
  (Digest::SHA256.hexdigest(identifier.encode('UTF-8')).to_i(16) / (BigDecimal("2") ** BigDecimal("256"))).round(16)
end

#read_and_write(request_cookies, top_level_domain, response_cookies, default_visitor_code = nil) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns visitor code.

Returns:

  • (String)

    visitor code



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kameleoon/cookie.rb', line 12

def read_and_write(request_cookies, top_level_domain, response_cookies, default_visitor_code = nil)
  kameleoon_visitor_code = read(request_cookies)
  if kameleoon_visitor_code.nil?
    kameleoon_visitor_code = check_default_visitor_code(default_visitor_code) || Kameleoon::Utils.generate_random_string(KAMELEOON_COOKIE_VALUE_LENGTH)
  end
  cookie = { :value => kameleoon_visitor_code, :expires => Time.now + Kameleoon::Utils.in_seconds(EXPIRE_DAYS), :path => '/' }
  unless top_level_domain.nil?
    cookie[:domain] = top_level_domain
  end
  response_cookies[KAMELEOON_COOKIE_NAME] = cookie
  kameleoon_visitor_code
end