Class: Ish::EmailContext
- Inherits:
-
Object
- Object
- Ish::EmailContext
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/ish/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
86 87 88 |
# File 'lib/ish/email_context.rb', line 86 def tid @tid end |
Class Method Details
.notsent ⇒ Object
64 |
# File 'lib/ish/email_context.rb', line 64 def self.notsent; new.notsent; end |
.scheduled ⇒ Object
71 |
# File 'lib/ish/email_context.rb', line 71 def self.scheduled; new.scheduled; end |
.summary ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ish/email_context.rb', line 100 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
22 23 24 25 26 27 28 |
# File 'lib/ish/email_context.rb', line 22 def body if self[:body].presence return self[:body] else return tmpl.body end end |
#from_email ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ish/email_context.rb', line 33 def from_email if self[:from_email].presence return self[:from_email] else return tmpl.from_email end end |
#get_binding ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ish/email_context.rb', line 88 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
76 |
# File 'lib/ish/email_context.rb', line 76 def lead; Lead.find( lead_id ); end |
#lead_id ⇒ Object
like belongs_to to_lead , but Lead is SQL to just the lead_id
75 |
# File 'lib/ish/email_context.rb', line 75 field :lead_id, type: :integer |
#notsent ⇒ Object
61 62 63 |
# File 'lib/ish/email_context.rb', line 61 def notsent Ish::EmailContext.where( sent_at: nil, unsubscribed_at: nil ) end |
#preview_str ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/ish/email_context.rb', line 13 def preview_str if self[:preview_str].presence return self[:preview_str] else return tmpl.preview_str end end |
#sch ⇒ Object
50 |
# File 'lib/ish/email_context.rb', line 50 def sch; scheduled_email_action; end |
#scheduled ⇒ Object
67 68 69 70 |
# File 'lib/ish/email_context.rb', line 67 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
42 43 44 |
# File 'lib/ish/email_context.rb', line 42 def subject self[:subject].presence || tmpl.subject end |
#tmpl ⇒ Object
47 |
# File 'lib/ish/email_context.rb', line 47 def tmpl; email_template; end |
#to_email ⇒ Object
@TODO: remove, just use the lead. vp 2023-03-27
77 |
# File 'lib/ish/email_context.rb', line 77 def to_email; lead[:email]; end |