Class: Rack::TradeTracker::Cookie
- Inherits:
-
Object
- Object
- Rack::TradeTracker::Cookie
- Defined in:
- lib/rack/trade_tracker/cookie.rb
Constant Summary collapse
- NAME =
'TT2_%{campaign_id}'.freeze
- DIGEST_PARAMS =
[:campaign_id, :material_id, :affiliate_id, :reference].freeze
- VALUE_PARAMS =
[:material_id, :affiliate_id, :reference].freeze
- PATH =
'/'.freeze
Instance Method Summary collapse
- #as_hash ⇒ Object
- #checksum ⇒ Object
-
#initialize(domain, parameters) ⇒ Cookie
constructor
A new instance of Cookie.
- #name ⇒ Object
- #timestamp ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(domain, parameters) ⇒ Cookie
Returns a new instance of Cookie.
10 11 12 |
# File 'lib/rack/trade_tracker/cookie.rb', line 10 def initialize(domain, parameters) @domain, @parameters = domain, parameters end |
Instance Method Details
#as_hash ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rack/trade_tracker/cookie.rb', line 33 def as_hash { value: value, domain: ".#{domain}", path: PATH, expires: 1.year.from_now } end |
#checksum ⇒ Object
18 19 20 21 |
# File 'lib/rack/trade_tracker/cookie.rb', line 18 def checksum source = "CHK_#{DIGEST_PARAMS.map { |param| params_hash[param] }.join('::')}" Digest::MD5.hexdigest(source) end |
#name ⇒ Object
14 15 16 |
# File 'lib/rack/trade_tracker/cookie.rb', line 14 def name NAME % params_hash end |
#timestamp ⇒ Object
23 24 25 |
# File 'lib/rack/trade_tracker/cookie.rb', line 23 def Time.now.to_i end |
#value ⇒ Object
27 28 29 30 31 |
# File 'lib/rack/trade_tracker/cookie.rb', line 27 def value VALUE_PARAMS.map { |param| params_hash[param] }.tap do |attributes| attributes << checksum << end.join('::') end |