Class: AlchemyCrm::Recipient

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/alchemy_crm/recipient.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_from_contact(contact) ⇒ Object



33
34
35
36
37
38
# File 'app/models/alchemy_crm/recipient.rb', line 33

def self.new_from_contact(contact)
  raise "No contact given!" if contact.nil?
  recipient = new(:contact => contact, :email => contact.email, :sha1 => Digest::SHA1.hexdigest(Time.now.to_i.to_s))
  recipient.readonly!
  recipient
end

Instance Method Details

#mail_toObject



13
14
15
# File 'app/models/alchemy_crm/recipient.rb', line 13

def mail_to
  contact.nil? ? email : "#{contact.name_with_title} <#{email}>"
end

#reacts!(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/alchemy_crm/recipient.rb', line 21

def reacts!(options={})
  update_attributes(
    :reacted => true,
    :reacted_at => Time.now
  )
  reactions.create(
    :element_id => options[:element_id],
    :page_id => options[:page_id],
    :url => options[:url]
  )
end

#reads!Object



17
18
19
# File 'app/models/alchemy_crm/recipient.rb', line 17

def reads!
  update_attributes(:read => true, :read_at => Time.now)
end