Sha256: 2957952f95dcdd878537bfb127951a33b1a76fcc4291eabb3290659841ed0a7c

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

##
## Sends a campaign.
## _vp_ 2023-02-02
##
class Ish::EmailCampaign
  include Mongoid::Document
  include Mongoid::Timestamps
  store_in collection: 'ish_email_campaigns'

  field :slug
  validates_uniqueness_of :slug, allow_nil: true

  PAGE_PARAM_NAME = 'email_contexts_page'

  field :from_email
  validates_presence_of :from_email
  FROM_EMAILS = %w|    hello@infiniteshelter.com no-reply@infiniteshelter.com
    piousbox@gmail.com hello@piousbox.com        no-reply@piousbox.com        victor@piousbox.com
    admin@wasya.co     hello@wasya.co            no-reply@wasya.co            victor@wasya.co |
  def self.from_email_list
    [ [nil, nil] ] + FROM_EMAILS.map { |i| [i, i] }
  end

  belongs_to :email_template
  def tmpl; email_template; end

  field :subject
  field :body

  field :sent_at, type: DateTime
  field :send_at, type: DateTime

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

  def leads
    campaign_leads&.map { |p| p.lead }
  end

  ##
  ## For tracking
  ##
  attr_reader :tid

  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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ish_models-0.0.33.243 lib/ish/email_campaign.rb
ish_models-0.0.33.242 lib/ish/email_campaign.rb
ish_models-0.0.33.241 lib/ish/email_campaign.rb
ish_models-0.0.33.240 lib/ish/email_campaign.rb
ish_models-0.0.33.239 lib/ish/email_campaign.rb
ish_models-0.0.33.238 lib/ish/email_campaign.rb
ish_models-0.0.33.237 lib/ish/email_campaign.rb
ish_models-0.0.33.236 lib/ish/email_campaign.rb