Class: Ish::EmailContext

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tidObject (readonly)

For tracking / utm



86
87
88
# File 'lib/ish/email_context.rb', line 86

def tid
  @tid
end

Class Method Details

.notsentObject



64
# File 'lib/ish/email_context.rb', line 64

def self.notsent; new.notsent; end

.scheduledObject



71
# File 'lib/ish/email_context.rb', line 71

def self.scheduled; new.scheduled; end

.summaryObject



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

#bodyObject



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_emailObject



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_bindingObject



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

#leadObject



76
# File 'lib/ish/email_context.rb', line 76

def lead; Lead.find( lead_id ); end

#lead_idObject

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

#notsentObject



61
62
63
# File 'lib/ish/email_context.rb', line 61

def notsent
  Ish::EmailContext.where( sent_at: nil, unsubscribed_at: nil )
end

#preview_strObject



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

#schObject



50
# File 'lib/ish/email_context.rb', line 50

def sch; scheduled_email_action; end

#scheduledObject



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

#subjectObject



42
43
44
# File 'lib/ish/email_context.rb', line 42

def subject
  self[:subject].presence || tmpl.subject
end

#tmplObject



47
# File 'lib/ish/email_context.rb', line 47

def tmpl; email_template; end

#to_emailObject

@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