mad_mimi_mailer 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. data/lib/mad_mimi_mailer.rb +22 -18
  2. metadata +2 -2
@@ -12,13 +12,13 @@ class MadMimiMailer < ActionMailer::Base
12
12
  # Custom Mailer attributes
13
13
 
14
14
  def promotion(promotion = nil)
15
- if promotion.nil?
15
+ if promotion.nil?
16
16
  @promotion
17
17
  else
18
18
  @promotion = promotion
19
19
  end
20
20
  end
21
-
21
+
22
22
  def use_erb(use_erb = nil)
23
23
  if use_erb.nil?
24
24
  @use_erb
@@ -26,7 +26,7 @@ class MadMimiMailer < ActionMailer::Base
26
26
  @use_erb = use_erb
27
27
  end
28
28
  end
29
-
29
+
30
30
  def hidden(hidden = nil)
31
31
  if hidden.nil?
32
32
  @hidden
@@ -36,39 +36,38 @@ class MadMimiMailer < ActionMailer::Base
36
36
  end
37
37
 
38
38
  # Class methods
39
-
40
- class << self
41
-
39
+
40
+ class << self
41
+
42
42
  def method_missing(method_symbol, *parameters)
43
43
  if method_symbol.id2name.match(/^deliver_(mimi_[_a-z]\w*)/)
44
44
  deliver_mimi_mail($1, *parameters)
45
45
  else
46
46
  super
47
- end
47
+ end
48
48
  end
49
-
49
+
50
50
  def deliver_mimi_mail(method, *parameters)
51
- mail = new
51
+ mail = new
52
52
  mail.__send__(method, *parameters)
53
53
 
54
54
  if mail.use_erb
55
55
  mail.create!(method, *parameters)
56
56
  end
57
-
57
+
58
58
  return unless perform_deliveries
59
59
 
60
60
  if delivery_method == :test
61
- deliveries << mail
61
+ deliveries << (mail.mail ? mail.mail : mail)
62
62
  else
63
63
  call_api!(mail, method)
64
64
  end
65
65
  end
66
-
66
+
67
67
  def call_api!(mail, method)
68
68
  params = {
69
69
  'username' => api_settings[:username],
70
70
  'api_key' => api_settings[:api_key],
71
-
72
71
  'promotion_name' => mail.promotion || method.to_s.sub(/^mimi_/, ''),
73
72
  'recipients' => serialize(mail.recipients),
74
73
  'subject' => mail.subject,
@@ -78,18 +77,23 @@ class MadMimiMailer < ActionMailer::Base
78
77
  }
79
78
 
80
79
  if mail.use_erb
80
+ if mail.parts.any?
81
+ mail = mail.parts.detect {|p| p.content_type == 'text/html' }
82
+ end
83
+
81
84
  unless mail.body.include?("[[peek_image]]")
82
85
  raise ValidationError, "You must include a web beacon in your Mimi email: [[peek_image]]"
83
86
  end
87
+
84
88
  params['raw_html'] = mail.body
85
89
  else
86
90
  params['body'] = mail.body.to_yaml
87
91
  end
88
-
92
+
89
93
  response = post_request do |request|
90
94
  request.set_form_data(params)
91
95
  end
92
-
96
+
93
97
  case response
94
98
  when Net::HTTPSuccess
95
99
  response.body
@@ -97,7 +101,7 @@ class MadMimiMailer < ActionMailer::Base
97
101
  response.error!
98
102
  end
99
103
  end
100
-
104
+
101
105
  def post_request
102
106
  url = URI.parse(SINGLE_SEND_URL)
103
107
  request = Net::HTTP::Post.new(url.path)
@@ -108,7 +112,7 @@ class MadMimiMailer < ActionMailer::Base
108
112
  http.request(request)
109
113
  end
110
114
  end
111
-
115
+
112
116
  def serialize(recipients)
113
117
  case recipients
114
118
  when String
@@ -122,7 +126,7 @@ class MadMimiMailer < ActionMailer::Base
122
126
  end
123
127
  end
124
128
  end
125
-
129
+
126
130
  class ValidationError < StandardError; end
127
131
  end
128
132
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mad_mimi_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-09-30 00:00:00 -05:00
12
+ date: 2009-10-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15