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



80
81
82
# File 'lib/ish/email_context.rb', line 80

def tid
  @tid
end

Class Method Details

.from_email_listObject



67
68
69
# File 'lib/ish/email_context.rb', line 67

def self.from_email_list
  Ish::EmailCampaign.from_email_list
end

.notsentObject



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

def self.notsent; new.notsent; end

.scheduledObject



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

def self.scheduled; new.scheduled; end

.summaryObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/ish/email_context.rb', line 87

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

#get_bindingObject



82
83
84
85
# File 'lib/ish/email_context.rb', line 82

def get_binding
  @lead = lead()
  binding()
end

#leadObject



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

def lead; Lead.find( lead_id ); end

#lead_idObject

like belongs_to to_lead , but Lead is SQL to just the lead_id



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

field :lead_id, type: :integer

#notsentObject



54
55
56
# File 'lib/ish/email_context.rb', line 54

def notsent
  Ish::EmailContext.where( sent_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



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

def sch; scheduled_email_action; end

#scheduledObject



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

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



36
37
38
# File 'lib/ish/email_context.rb', line 36

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

#tmplObject



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

def tmpl; email_template; end

#to_emailObject

@TODO: remove, just use the lead. vp 2023-03-27



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

def to_email; lead[:email]; end