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

#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.



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

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.values.sort.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



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

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