Class: Ish::EmailCampaign

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/ish/email_campaign.rb

Overview

Sends a campaign. vp 2023-02-02

Constant Summary collapse

PAGE_PARAM_NAME =
'email_contexts_page'
FROM_EMAILS =
%w|        [email protected] [email protected]
  [email protected]
                         [email protected]        [email protected]        [email protected]
  [email protected]         [email protected]            [email protected]            [email protected]
  [email protected] [email protected]    [email protected]    [email protected]
|;

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tidObject (readonly)

For tracking



48
49
50
# File 'lib/ish/email_campaign.rb', line 48

def tid
  @tid
end

Class Method Details

.from_email_listObject



24
25
26
# File 'lib/ish/email_campaign.rb', line 24

def self.from_email_list
  [ [nil, nil] ] + FROM_EMAILS.map { |i| [i, i] }
end

Instance Method Details

#campaign_leadsObject



37
38
39
# File 'lib/ish/email_campaign.rb', line 37

def campaign_leads
  return ::EmailCampaignLead.where( email_campaign_id: self.id.to_s ).includes( :lead )
end

#do_sendObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ish/email_campaign.rb', line 50

def do_send
  leads.each do |lead|
    ctx = Ctx.create!({
      email_template: tmpl,
      from_email:     tmpl.from_email,
      lead_id:        lead.id,
      send_at:        Time.now,
      subject:        tmpl.subject,
    })
  end
end

#leadsObject



41
42
43
# File 'lib/ish/email_campaign.rb', line 41

def leads
  ::Lead.joins( :email_campaign_leads ).where( 'email_campaign_leads.email_campaign_id' => self.id.to_s )
end

#tmplObject



29
# File 'lib/ish/email_campaign.rb', line 29

def tmpl; email_template; end