Module: Octo::OctoHooks::ClassMethods

Defined in:
lib/octocore/callbacks.rb

Overview

Add all the post-hook-call methods here. Also, extend the module

from here.

Instance Method Summary collapse

Instance Method Details

#add_session(opts) ⇒ Object

Adds user session for page_view and product_page_view to redis. It self expires in n seconds from last hit



72
73
74
75
76
77
78
79
80
# File 'lib/octocore/callbacks.rb', line 72

def add_session(opts)
  if Octo.is_not_flagged?(Octo::Funnel)
    if opts.has_key?(:type)
      createRedisShadowKey(opts[:enterprise].id.to_s + '_' + opts[:user].id.to_s,
                           opts[:type].to_s,
                           Octo.get_config(:session_length))
    end
  end
end

#createRedisShadowKey(keyname, value, duration) ⇒ Object

Method was created because when a redis key

expires you can just catch the key name,
and not its value. So what we do is
create a shadow key for the given key name
and make it expire in the given amt of
time (seconds).

This helps us in catching the event

when the (shadow) key expires, after which we
read the value of the main key and later
delete the main key

You can change it from rpush to lpush, or set

whichever you want to use.


94
95
96
97
# File 'lib/octocore/callbacks.rb', line 94

def createRedisShadowKey(keyname, value, duration)
  Cequel::Record.redis.setex("shadow:" + keyname,duration,"")
  Cequel::Record.redis.rpush(keyname, value)
end

#update_counters(opts) ⇒ Object

Updates the counters of various types depending

on the event.

Parameters:

  • opts (Hash)

    The options hash



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/octocore/callbacks.rb', line 51

def update_counters(opts)
  if opts.has_key?(:product)
    Octo::ProductHit.increment_for(opts[:product])
  end
  if opts.has_key?(:categories)
    opts[:categories].each do |cat|
      Octo::CategoryHit.increment_for(cat)
    end
  end
  if opts.has_key?(:tags)
    opts[:tags].each do |tag|
      Octo::TagHit.increment_for(tag)
    end
  end
  if opts.has_key?(:event)
    Octo::ApiHit.increment_for(opts[:event])
  end
end