redsquirrel-mad_mimi_mailer 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mad_mimi_mailer.rb +52 -16
- metadata +2 -2
data/lib/mad_mimi_mailer.rb
CHANGED
|
@@ -3,26 +3,45 @@ require "net/http"
|
|
|
3
3
|
require "net/https"
|
|
4
4
|
|
|
5
5
|
class MadMimiMailer < ActionMailer::Base
|
|
6
|
-
VERSION = '0.0.
|
|
6
|
+
VERSION = '0.0.5'
|
|
7
7
|
SINGLE_SEND_URL = 'https://madmimi.com/mailer'
|
|
8
8
|
|
|
9
9
|
@@api_settings = {}
|
|
10
10
|
cattr_accessor :api_settings
|
|
11
11
|
|
|
12
|
+
# Custom Mailer attributes
|
|
13
|
+
|
|
12
14
|
def promotion(promotion = nil)
|
|
13
|
-
if promotion.
|
|
15
|
+
if promotion.nil?
|
|
16
|
+
@promotion
|
|
17
|
+
else
|
|
14
18
|
@promotion = promotion
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def use_erb(use_erb = nil)
|
|
23
|
+
if use_erb.nil?
|
|
24
|
+
@use_erb
|
|
15
25
|
else
|
|
16
|
-
@
|
|
26
|
+
@use_erb = use_erb
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def hidden(hidden = nil)
|
|
31
|
+
if hidden.nil?
|
|
32
|
+
@hidden
|
|
33
|
+
else
|
|
34
|
+
@hidden = hidden
|
|
17
35
|
end
|
|
18
36
|
end
|
|
19
37
|
|
|
38
|
+
# Class methods
|
|
39
|
+
|
|
20
40
|
class << self
|
|
21
41
|
|
|
22
42
|
def method_missing(method_symbol, *parameters)
|
|
23
43
|
if method_symbol.id2name.match(/^deliver_(mimi_[_a-z]\w*)/)
|
|
24
44
|
deliver_mimi_mail($1, *parameters)
|
|
25
|
-
|
|
26
45
|
else
|
|
27
46
|
super
|
|
28
47
|
end
|
|
@@ -31,7 +50,11 @@ class MadMimiMailer < ActionMailer::Base
|
|
|
31
50
|
def deliver_mimi_mail(method, *parameters)
|
|
32
51
|
mail = new
|
|
33
52
|
mail.__send__(method, *parameters)
|
|
34
|
-
|
|
53
|
+
|
|
54
|
+
if mail.use_erb
|
|
55
|
+
mail.create!(method, *parameters)
|
|
56
|
+
end
|
|
57
|
+
|
|
35
58
|
return unless perform_deliveries
|
|
36
59
|
|
|
37
60
|
if delivery_method == :test
|
|
@@ -42,18 +65,29 @@ class MadMimiMailer < ActionMailer::Base
|
|
|
42
65
|
end
|
|
43
66
|
|
|
44
67
|
def call_api!(mail, method)
|
|
68
|
+
params = {
|
|
69
|
+
'username' => api_settings[:username],
|
|
70
|
+
'api_key' => api_settings[:api_key],
|
|
71
|
+
|
|
72
|
+
'promotion_name' => mail.promotion || method.to_s.sub(/^mimi_/, ''),
|
|
73
|
+
'recipients' => serialize(mail.recipients),
|
|
74
|
+
'subject' => mail.subject,
|
|
75
|
+
'bcc' => serialize(mail.bcc),
|
|
76
|
+
'from' => mail.from,
|
|
77
|
+
'hidden' => serialize(mail.hidden)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if mail.use_erb
|
|
81
|
+
unless mail.body.include?("[[peek_image]]")
|
|
82
|
+
raise ValidationError, "You must include a web beacon in your Mimi email: [[peek_image]]"
|
|
83
|
+
end
|
|
84
|
+
params['raw_html'] = mail.body
|
|
85
|
+
else
|
|
86
|
+
params['body'] = mail.body.to_yaml
|
|
87
|
+
end
|
|
88
|
+
|
|
45
89
|
response = post_request do |request|
|
|
46
|
-
request.set_form_data(
|
|
47
|
-
'username' => api_settings[:username],
|
|
48
|
-
'api_key' => api_settings[:api_key],
|
|
49
|
-
|
|
50
|
-
'promotion_name' => mail.promotion || method.to_s.sub(/^mimi_/, ''),
|
|
51
|
-
'recipients' => serialize(mail.recipients),
|
|
52
|
-
'subject' => mail.subject,
|
|
53
|
-
'bcc' => serialize(mail.bcc),
|
|
54
|
-
'from' => mail.from,
|
|
55
|
-
'body' => mail.body.to_yaml
|
|
56
|
-
)
|
|
90
|
+
request.set_form_data(params)
|
|
57
91
|
end
|
|
58
92
|
|
|
59
93
|
case response
|
|
@@ -88,4 +122,6 @@ class MadMimiMailer < ActionMailer::Base
|
|
|
88
122
|
end
|
|
89
123
|
end
|
|
90
124
|
end
|
|
125
|
+
|
|
126
|
+
class ValidationError < StandardError; end
|
|
91
127
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: redsquirrel-mad_mimi_mailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dave Hoover
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-09-15 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|