Module: Lettr
Defined Under Namespace
Modules: ActionMailer, Deliverable, ObjectConverter, Resource, Whitelist
Classes: Base, Collection, Delivery, Mailer
Class Method Summary
collapse
Class Method Details
._check_options_for_rendered_mail!(options) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/lettr.rb', line 60
def self._check_options_for_rendered_mail! options
[:subject, :recipient].each do |opt|
raise ArgumentError.new ":#{opt} is required" unless options.has_key?( opt )
end
raise ArgumentError.new ":html or :text is required" unless (options.has_key?( :text ) || options.has_key?( :html ))
end
|
._create_rendered_mail(*args) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/lettr.rb', line 67
def self._create_rendered_mail *args
_check_options_for_rendered_mail! args[1]
mailing = RenderedMailing.find args[0].to_s
mailing.attributes = args[1].merge(:identifier => args[0].to_s)
mailing
rescue RestClient::ResourceNotFound
mailing = RenderedMailing.new args[1].merge(:identifier => args[0].to_s)
unless mailing.save
raise ArgumentError.new mailing.errors.join(' ')
end
mailing
end
|
.api_mailings ⇒ Object
80
81
82
|
# File 'lib/lettr.rb', line 80
def self.api_mailings
@@api_mailings
end
|
.credentials=(credentials) ⇒ Object
26
27
28
29
|
# File 'lib/lettr.rb', line 26
def self.credentials=(credentials)
Base.user = credentials[:user]
Base.pass = credentials[:pass]
end
|
.load_api_mailing_or_fail_loud(*args) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/lettr.rb', line 50
def self.load_api_mailing_or_fail_loud *args
identifier = args[0]
api_mailing = self.api_mailings[identifier] ||= ApiMailing.find(identifier)
options = args[1]
api_mailing.delivery_options = options
return api_mailing
rescue RestClient::ResourceNotFound => e
_create_rendered_mail( *args )
end
|
.method_missing(*args, &block) ⇒ Object
84
85
86
87
88
|
# File 'lib/lettr.rb', line 84
def self.method_missing *args, &block
load_api_mailing_or_fail_loud *args
rescue RestClient::ResourceNotFound
super
end
|
.subscribe(recipient) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/lettr.rb', line 31
def self.subscribe(recipient)
raise 'Object muss über das Attribut :email verfügen.' unless recipient.respond_to? :email
rec = Recipient.new recipient.email
attributes.each do |attribute|
if recipient.respond_to? attribute
rec.send("#{attribute}=", recipient.send(attribute))
end
end
rec.approved = true
unless rec.save
raise rec.errors.join(' ')
end
rec
end
|
.unsubscribe(email) ⇒ Object
46
47
48
|
# File 'lib/lettr.rb', line 46
def self.unsubscribe(email)
Recipient.delete_by_email(email)
end
|