Module: RenoteDac::Mailer

Defined in:
lib/renote_dac/mailer.rb

Defined Under Namespace

Classes: Client

Constant Summary collapse

InvalidTemplate =
Class.new(StandardError)
BATCH_ID =
0
BATCH_TEMPLATE =
1
BATCH_EMAIL =
2
BATCH_PARAMS =
3
BATCH_ATTACHMENT_PARAMS =
4

Class Method Summary collapse

Class Method Details

.base_urlObject



41
42
43
44
45
46
47
# File 'lib/renote_dac/mailer.rb', line 41

def self.base_url
  if Rails.env.production?
    RenoteDac.configuration.prod_base_url
  else
    RenoteDac.configuration.dev_base_url
  end
end

.enqueue(template, email_address, params = {}, attachment_params = []) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/renote_dac/mailer.rb', line 13

def self.enqueue(template, email_address, params = {}, attachment_params = [])
  meta = Mailer.get_template_meta(template)

  RenoteDac::Email.create!(
    priority: meta[:priority],
    template: template,
    address: email_address,
    params: params,
    attachment_params: attachment_params
  )
end

.get_batch(size) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/renote_dac/mailer.rb', line 25

def self.get_batch(size)
  raise 'Max batch size is 500' if size > 500

  RenoteDac::Email
    .where(error: nil)
    .order(priority: :asc, id: :asc)
    .limit(size)
    .pluck(:id, :template, :address, :params, :attachment_params)
end

.get_template_meta(template) ⇒ Object



35
36
37
38
39
# File 'lib/renote_dac/mailer.rb', line 35

def self.get_template_meta(template)
  meta = RenoteDac.configuration.templates[template.to_sym]
  raise RenoteDac::Mailer::InvalidTemplate unless meta
  meta
end