Sha256: c9d81e013b3a3a43c9fc04e2e29db349a859684f7cf40db9559a50dd76f91a5a

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module Highrise
  class Person < Subject
    DATE_OCCASIONS = ["Birthday", "Anniversary", "First met", "Hired", "Fired"]
    
    include Pagination
    include Taggable
    
    def self.search_by_name(name)                                               
      find(:first, :from => "/people/search.xml", :params => {:term => name})
    end
    
    def self.find_all_by_tag(tag_name)
      tag = Tag.find_by_name(tag_name)
      find(:all, :from => "/tags/#{tag.id}.xml")
    end
    
    def self.find_all_across_pages_since(time)
      find_all_across_pages(:params => { :since => time.utc.to_s(:db).gsub(/[^\d]/, '') })
    end
  
    def company
      Company.find(company_id) if company_id
    end
  
    def name
      "#{first_name rescue ''} #{last_name rescue ''}".strip
    end
    

    def add_date!(description, date, task_owner_id=nil)
      description_key = DATE_OCCASIONS.include?(description) ? :description : :custom_description
      custom_date = { description_key => description, :month => date.month, :day => date.day, :year => date.year }
      if task_owner_id
        custom_date[:assign_task]   = true
        custom_date[:task_owner_id] = task_owner_id 
      end
      # TODO: use different way to add date (current throws 406 from Highrise, but works anyways)
      self.post(:contact_dates, :contact_date => custom_date) rescue nil
    end
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soleone-highrise-0.13.3 lib/highrise/person.rb