class Assoc < ActiveRecord::Base
  def after_initialize
    if not self.id
      @@count ||= 0
      self.handle = "{HMAC-SHA1}#{Time.now.to_i}/#{@@count+=1}"    
      self.secret = (1..20).collect {rand(256)}.pack("C*")
      self.issued = Time.now
      self.lifetime = 2.hours
    end
  end

  def expires_in
    self.issued + self.lifetime - Time.now
  end
end
