Class: WcoEmail::Context
- Inherits:
-
Object
- Object
- WcoEmail::Context
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/wco_email/context.rb
Overview
Send a single email
Constant Summary collapse
- PAGE_PARAM_NAME =
'email_contexts_page'
Instance Attribute Summary collapse
-
#tid ⇒ Object
readonly
For tracking / utm.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #from_email ⇒ Object
- #get_binding ⇒ Object
- #lead ⇒ Object
-
#lead_id ⇒ Object
like belongs_to to_lead , but Lead is SQL to just the lead_id.
- #notsent ⇒ Object
- #preview_str ⇒ Object
- #sch ⇒ Object
- #scheduled ⇒ Object
- #subject ⇒ Object
- #tmpl ⇒ Object
-
#to_email ⇒ Object
@TODO: remove, just use the lead.
Instance Attribute Details
#tid ⇒ Object (readonly)
For tracking / utm
87 88 89 |
# File 'app/models/wco_email/context.rb', line 87 def tid @tid end |
Class Method Details
.notsent ⇒ Object
65 |
# File 'app/models/wco_email/context.rb', line 65 def self.notsent; new.notsent; end |
.scheduled ⇒ Object
72 |
# File 'app/models/wco_email/context.rb', line 72 def self.scheduled; new.scheduled; end |
.summary ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/wco_email/context.rb', line 101 def self.summary pipeline = [ { '$group' => { '_id' => { '$dateToString' => { 'format' => "%Y-%m-%d", 'date' => "$sent_at", 'timezone' => 'America/Chicago' } }, 'total' => { '$sum' => 1 } } }, { '$sort' => { '_id': -1 } }, ] outs = Ish::EmailContext.collection.aggregate( pipeline ) outs.to_a end |
Instance Method Details
#body ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/models/wco_email/context.rb', line 23 def body if self[:body].presence return self[:body] else return tmpl.body end end |
#from_email ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/wco_email/context.rb', line 34 def from_email if self[:from_email].presence return self[:from_email] else return tmpl.from_email end end |
#get_binding ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/wco_email/context.rb', line 89 def get_binding @lead = lead() @utm_tracking_str = { 'cid' => lead.id, 'utm_campaign' => tmpl.slug, 'utm_medium' => 'email', 'utm_source' => tmpl.slug, }.map { |k, v| "#{k}=#{v}" }.join("&") eval( tmpl.config_exe ) binding() end |
#lead ⇒ Object
77 |
# File 'app/models/wco_email/context.rb', line 77 def lead; Lead.find( lead_id ); end |
#lead_id ⇒ Object
like belongs_to to_lead , but Lead is SQL to just the lead_id
76 |
# File 'app/models/wco_email/context.rb', line 76 field :lead_id, type: :integer |
#notsent ⇒ Object
62 63 64 |
# File 'app/models/wco_email/context.rb', line 62 def notsent Ish::EmailContext.where( sent_at: nil, unsubscribed_at: nil ) end |
#preview_str ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/models/wco_email/context.rb', line 14 def preview_str if self[:preview_str].presence return self[:preview_str] else return tmpl.preview_str end end |
#sch ⇒ Object
51 |
# File 'app/models/wco_email/context.rb', line 51 def sch; scheduled_email_action; end |
#scheduled ⇒ Object
68 69 70 71 |
# File 'app/models/wco_email/context.rb', line 68 def scheduled # or({ :send_at.lte => Time.now }, { :send_at => nil }) ## This won't work b/c I need draft state! Ish::EmailContext.where({ :send_at.lte => Time.now }) end |
#subject ⇒ Object
43 44 45 |
# File 'app/models/wco_email/context.rb', line 43 def subject self[:subject].presence || tmpl.subject end |
#tmpl ⇒ Object
48 |
# File 'app/models/wco_email/context.rb', line 48 def tmpl; email_template; end |
#to_email ⇒ Object
@TODO: remove, just use the lead. vp 2023-03-27
78 |
# File 'app/models/wco_email/context.rb', line 78 def to_email; lead[:email]; end |