Class: WcoEmail::Campaign

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/wco_email/campaign.rb

Overview

Sends a campaign. vp 2023-02-02

Constant Summary collapse

PAGE_PARAM_NAME =
'email_contexts_page'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tidObject (readonly)

For tracking



41
42
43
# File 'app/models/wco_email/campaign.rb', line 41

def tid
  @tid
end

Instance Method Details

#campaign_leadsObject



30
31
32
# File 'app/models/wco_email/campaign.rb', line 30

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

#do_sendObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/wco_email/campaign.rb', line 43

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



34
35
36
# File 'app/models/wco_email/campaign.rb', line 34

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

#tmplObject



20
# File 'app/models/wco_email/campaign.rb', line 20

def tmpl; email_template; end