Class: MailManager::TestMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
StatusHistory
Defined in:
app/models/mail_manager/test_message.rb

Defined Under Namespace

Classes: Contact, Subscription

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StatusHistory

#change_status, included, #set_default_status, #status, #status=, #status_changed_at=

Constructor Details

#initialize(*args) ⇒ TestMessage

Returns a new instance of TestMessage.



15
16
17
18
# File 'app/models/mail_manager/test_message.rb', line 15

def initialize(*args)
  super
  set_type
end

Class Method Details

.valid_statusesObject



101
102
103
# File 'app/models/mail_manager/test_message.rb', line 101

def self.valid_statuses
  ['pending','processing','sent','failed','ready']
end

Instance Method Details

#contactableObject



78
79
80
# File 'app/models/mail_manager/test_message.rb', line 78

def contactable
  contact.try(:contactable)
end

#default_statusObject



115
116
117
# File 'app/models/mail_manager/test_message.rb', line 115

def default_status
  'pending'
end

#deliverObject

sends the message through Mailer



50
51
52
53
# File 'app/models/mail_manager/test_message.rb', line 50

def deliver
  MailManager::Mailer.deliver_message(self)
  change_status(:sent)
end

#email_addressObject



59
60
61
# File 'app/models/mail_manager/test_message.rb', line 59

def email_address
  contact.email_address
end

#email_address_with_nameObject



44
45
46
47
# File 'app/models/mail_manager/test_message.rb', line 44

def email_address_with_name
  return %Q|"#{full_name}" <#{email_address}>|.gsub(/\s+/,' ') unless full_name.eql?('')
  email_address
end

#from_email_addressObject



67
68
69
70
71
# File 'app/models/mail_manager/test_message.rb', line 67

def from_email_address
  return self[:from_email_address] if self[:from_email_address].present?
  self.update_attribute(:from_email_address,mailing.from_email_address)
  self[:from_email_address]
end

#full_nameObject



55
56
57
# File 'app/models/mail_manager/test_message.rb', line 55

def full_name
  contact.full_name
end

#generate_guidObject

generated the guid for which the message is identified by in transit



110
111
112
113
# File 'app/models/mail_manager/test_message.rb', line 110

def generate_guid
  update_attribute(:guid,       
    "#{contact.id}-#{subscription.try(:id)}-#{self.id}-#{Digest::SHA1.hexdigest("#{contact.id}-#{subscription.try(:id)}-#{self.id}-#{MailManager.secret}")}")
end

#partsObject

returns the separate mime parts of the message’s Mailable



74
75
76
# File 'app/models/mail_manager/test_message.rb', line 74

def parts
  @parts ||= mailing.parts(substitutions)
end

#subjectObject



63
64
65
# File 'app/models/mail_manager/test_message.rb', line 63

def subject
  mailing.subject
end

#subscriptionObject



138
139
140
# File 'app/models/mail_manager/test_message.rb', line 138

def subscription
  Subscription.new(self)
end

#substitutionsObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/mail_manager/test_message.rb', line 82

def substitutions
  substitutions_hash = {}
  MailManager::ContactableRegistry.registered_methods.each do |method|
    method_key = method.to_s.upcase
    if contact.respond_to?(method)
      substitutions_hash[method_key] = contact.send(method)
    elsif contactable.respond_to?(method)
      substitutions_hash[method_key] = contactable.send(method)
    else
      substitutions_hash[method_key] = ''
    end
  end
  substitutions_hash.merge('UNSUBSCRIBE_URL' => unsubscribe_url)
end

#unsubscribe_urlObject



97
98
99
# File 'app/models/mail_manager/test_message.rb', line 97

def unsubscribe_url
  "#{MailManager.site_url}#{MailManager.unsubscribe_path}/#{guid}"
end

#valid_statusesObject



105
106
107
# File 'app/models/mail_manager/test_message.rb', line 105

def valid_statuses
  ['pending','processing','sent','failed','ready']
end