Module: Lettr::Deliverable

Included in:
ApiMailing
Defined in:
lib/lettr/deliverable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/lettr/deliverable.rb', line 4

def self.included base
  base.class_eval do
    attr_accessor :recipient
  end
end

Instance Method Details

#build_delivery_recordObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lettr/deliverable.rb', line 29

def build_delivery_record
  build_initial_delivery_hash
  group_variables if respond_to? :group_variables
  handle_options
  append_used_variables if respond_to? :append_used_variables
  Rails.logger.debug @hash.inspect if defined? Rails

  # perform delivery request
  rec = Lettr::Delivery.new @hash, @files
  rec
end

#build_initial_delivery_hashObject



41
42
43
44
45
46
# File 'lib/lettr/deliverable.rb', line 41

def build_initial_delivery_hash
  @hash = {}
  @files = {}
  @hash[ :recipient ] = recipient
  @hash[ :api_mailing_id ] = identifier
end

#deliverObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lettr/deliverable.rb', line 14

def deliver
  fail ArgumentError, 'Empfänger nicht übergeben' unless recipient?
  rec = build_delivery_record
  rec.save
  if rec.errors.any?
    # invalidate cache and retry
    old_recipient = @hash[:recipient]
    reload
    recipient = old_recipient
    rec = build_delivery_record
    rec.save
  end
  rec
end

#recipient?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/lettr/deliverable.rb', line 10

def recipient?
  !!@recipient
end