<commit_before>class Partner < ActiveRecord::Base
  
  class CredentialStore
    def [](access_key_id)
      p = Partner.find_by_slug(access_key_id)
      p.api_key if p
    end
  end
  
  acts_as_authentic do |c|
    c.maintain_sessions = false
  end
  
  include RFC822
  validates_presence_of :phone_number, :name, :organization, :email
  validates_presence_of :api_key, :on => :update
  validates_format_of :email, :with => EmailAddressRegularExpression
  validates_uniqueness_of :api_key
  validates_uniqueness_of :slug
  
  before_create :create_api_key, :create_slug
  
  MAX_RESPONSE_CACHE_TIME = 1.hour
  
  def self.credential_store
    @cr ||= CredentialStore.new
  end
  
  def max_response_cache_time
    MAX_RESPONSE_CACHE_TIME
  end
  
  def phone_number
    (self.attributes["phone_number"] || "").to_phone(:area_code => true)
  end
  
  def phone_number=(_phone_number)
    @attributes["phone_number"] = _phone_number.to_s.gsub(/[^0-9]+/, '')
  end
  
  def cache_key
    cache_timestamp = 1.hour.until(Time.at(max_requests_reset_time)).strftime("%m%d%y_%H")
    "#{Time.now.strftime("#{api_key}_#{cache_timestamp}")}"
  end
  
  def self.find_and_authenticate(api_key)
    p = Partner.find_by_api_key(api_key)
    auth = authenticate(p).authorized
    {:partner => p, :authorized => auth, :may_cache => p.max_requests.blank?}<commit_msg>made unique validations on slug and api_key actually work<commit_after>class Partner < ActiveRecord::Base
  
  class CredentialStore
    def [](access_key_id)
      p = Partner.find_by_slug(access_key_id)
      p.api_key if p
    end
  end
  
  acts_as_authentic do |c|
    c.maintain_sessions = false
  end
  
  before_validation :create_api_key, :create_slug
  
  include RFC822
  validates_presence_of :phone_number, :name, :organization, :email
  validates_presence_of :api_key, :on => :update
  validates_format_of :email, :with => EmailAddressRegularExpression
  validates_uniqueness_of :api_key
  validates_uniqueness_of :slug
  
  MAX_RESPONSE_CACHE_TIME = 1.hour
  
  def self.credential_store
    @cr ||= CredentialStore.new
  end
  
  def max_response_cache_time
    MAX_RESPONSE_CACHE_TIME
  end
  
  def phone_number
    (self.attributes["phone_number"] || "").to_phone(:area_code => true)
  end
  
  def phone_number=(_phone_number)
    @attributes["phone_number"] = _phone_number.to_s.gsub(/[^0-9]+/, '')
  end
  
  def cache_key
    cache_timestamp = 1.hour.until(Time.at(max_requests_reset_time)).strftime("%m%d%y_%H")
    "#{Time.now.strftime("#{api_key}_#{cache_timestamp}")}"
  end
  
  def self.find_and_authenticate(api_key)
    p = Partner.find_by_api_key(api_key)
    auth = authenticate(p).authorized
    {:partner => p, :authorized => auth, :may_cache => p.max_requests.blank?}
{'fraction_non_alphanumeric': 0.10949963741841914, 'fraction_numerical': 0.005076142131979695, 'mean_word_length': 4.195856873822976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2090962', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1020, 'n_words': 171}