Sha256: c1e6fafec100f6c983122e0fa98d02823fee4e72a9e96148bfe03f4c32a05a6a

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module TreasureData
module Logger

  module Event
    def self.use(mod)
      send(:include, mod)
    end
  end

  module EventPreset
    def action(name, record, uid=TD.event.attribute[:uid])
      unless uid
        raise ArgumentError, "wrong number of arguments (2 for 3): :uid attribute is required"
      end
      post(name, record.merge({:uid=>uid}))
    end

    def register(uid=TD.event.attribute[:uid])
      unless uid
        raise ArgumentError, "wrong number of arguments (0 for 1): :uid attribute is required"
      end
      action(:register, {}, uid)
    end

    def login(uid=TD.event.attribute[:uid])
      unless uid
        raise ArgumentError, "wrong number of arguments (0 for 1): :uid attribute is required"
      end
      action(:login, {}, uid)
    end

    def pay(category, sub_category, name, price, count, uid=TD.event.attribute[:uid])
      unless uid
        raise ArgumentError, "wrong number of arguments (3 for 4): :uid attribute is required"
      end
      action(:pay, {:category=>category, :sub_category=>sub_category, :name=>name, :price=>price, :count=>count}, uid)
    end
  end

  Event.use EventPreset

  class EventCollector
    def initialize
      @attribute = {}
    end

    attr_accessor :attribute

    def post(action, record, time=nil)
      TreasureData::Logger.post(action, @attribute.merge(record), time)
    end

    include Event
  end

  def self.event
    Thread.current[:td_event_collector] ||= EventCollector.new
  end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
td-logger-0.3.0 lib/td/logger/event.rb