Class: SnowplowRubyDuid::Cookie

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

Overview

Responsible for generating a cookie that emulates the Snowplow cookie as closely as possible Leverages the method used by ActionDispatch::Cookies::CookieJar to determine the top-level domain

Constant Summary collapse

'/'
24
DOMAIN_REGEXP =
/[^.]*\.([^.]*|..\...|...\...)$/

Instance Method Summary collapse

Constructor Details

#initialize(host, domain_userid, request_created_at) ⇒ Cookie

Returns a new instance of Cookie.



13
14
15
16
17
# File 'lib/snowplow_ruby_duid/cookie.rb', line 13

def initialize host, domain_userid, request_created_at
  @host               = host
  @domain_userid      = domain_userid
  @request_created_at = request_created_at
end

Instance Method Details

#keyObject



21
22
23
24
# File 'lib/snowplow_ruby_duid/cookie.rb', line 21

def key
  domain = top_level_domain || @host
  KEY_PREFIX + '.' + (Digest::SHA1.hexdigest (domain + COOKIE_PATH))[0..3]
end

#valueObject



26
27
28
29
30
31
32
33
34
# File 'lib/snowplow_ruby_duid/cookie.rb', line 26

def value
  cookie_domain = ".#{top_level_domain}" unless top_level_domain.nil?
  {
    value:   cookie_value,
    expires: cookie_expiration,
    domain:  cookie_domain,
    path:    COOKIE_PATH,
  }
end