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
Looks good...
- #clear_body ⇒ Object
- #config ⇒ Object
- #from_email ⇒ Object
- #get_binding ⇒ Object
- #preview_str ⇒ Object
- #sch ⇒ Object
- #subject ⇒ Object
- #tmpl ⇒ Object
- #to_email ⇒ Object
- #unsubscribe_url ⇒ Object
- #utm_tracking_str ⇒ Object
Instance Attribute Details
#tid ⇒ Object (readonly)
For tracking / utm
110 111 112 |
# File 'app/models/wco_email/context.rb', line 110 def tid @tid end |
Class Method Details
.not_sent ⇒ Object
88 89 90 |
# File 'app/models/wco_email/context.rb', line 88 def self.not_sent self.notsent end |
.notsent ⇒ Object
85 86 87 |
# File 'app/models/wco_email/context.rb', line 85 def self.notsent where( sent_at: nil, unsubscribed_at: nil ) end |
.scheduled ⇒ Object
92 93 94 |
# File 'app/models/wco_email/context.rb', line 92 def self.scheduled where( :send_at.lte => Time.now ) end |
.summary ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'app/models/wco_email/context.rb', line 119 def self.summary pipeline = [ { '$group' => { '_id' => { '$dateToString' => { 'format' => "%Y-%m-%d", 'date' => "$sent_at", 'timezone' => 'America/Chicago' } }, 'total' => { '$sum' => 1 } } }, { '$sort' => { '_id': -1 } }, ] outs = WcoEmail::Context.collection.aggregate( pipeline ) outs.to_a end |
Instance Method Details
#body ⇒ Object
Looks good... 2024-01-17
31 32 33 34 35 36 37 |
# File 'app/models/wco_email/context.rb', line 31 def body if self[:body].presence return self[:body] else return tmpl&.body || '' end end |
#clear_body ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/wco_email/context.rb', line 39 def clear_body tmp = ActionView::Base.full_sanitizer.sanitize body if tmp.blank? self[:body] = nil end end |
#config ⇒ Object
130 131 132 133 |
# File 'app/models/wco_email/context.rb', line 130 def config @config ||= OpenStruct.new JSON.parse( tmpl[:config_json] ) @config end |
#from_email ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/models/wco_email/context.rb', line 48 def from_email if self[:from_email].presence return self[:from_email] elsif tmpl&.from_email return tmpl.from_email else return DEFAULT_FROM_EMAIL end end |
#get_binding ⇒ Object
112 113 114 115 116 117 |
# File 'app/models/wco_email/context.rb', line 112 def get_binding @lead = lead @utm_tracking_str = utm_tracking_str # eval( tmpl.config_exe ) ## @TODO: remove? 2024-01-17 binding() end |
#preview_str ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/models/wco_email/context.rb', line 21 def preview_str if self[:preview_str].presence return self[:preview_str] else return tmpl.preview_str end end |
#sch ⇒ Object
72 |
# File 'app/models/wco_email/context.rb', line 72 def sch; email_action; end |
#subject ⇒ Object
61 62 63 |
# File 'app/models/wco_email/context.rb', line 61 def subject self[:subject].presence || tmpl&.subject end |
#tmpl ⇒ Object
69 |
# File 'app/models/wco_email/context.rb', line 69 def tmpl; email_template; end |
#to_email ⇒ Object
98 99 100 |
# File 'app/models/wco_email/context.rb', line 98 def to_email lead.email end |
#unsubscribe_url ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'app/models/wco_email/context.rb', line 144 def unsubscribe_url Wco::Engine.routes.url_helpers.unsubscribes_url({ host: Rails.application.routes.[:host], lead_id: lead_id, template_id: tmpl.id, token: lead.unsubscribe_token, }) end |
#utm_tracking_str ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'app/models/wco_email/context.rb', line 135 def utm_tracking_str { 'cid' => lead_id, 'utm_campaign' => tmpl.slug, 'utm_medium' => 'email', 'utm_source' => tmpl.slug, }.map { |k, v| "#{k}=#{v}" }.join("&") end |