mad_mimi_mailer 0.1.3.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +20 -0
- data/README.rdoc +57 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/mad_mimi_mail.rb +77 -0
- data/lib/mad_mimi_mailer.rb +1 -35
- data/mad_mimi_mail.gemspec +76 -0
- data/mad_mimi_mailer.gemspec +77 -0
- data/spec/mad_mimi_mail_spec.rb +122 -0
- data/spec/mad_mimi_mailer_spec.rb +10 -0
- data/spec/spec_helper.rb +7 -0
- metadata +122 -25
- data/lib/mad_mimi_mailable.rb +0 -239
data/.bundle/config
ADDED
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.0)
|
6
|
+
actionpack (= 3.0.0)
|
7
|
+
mail (~> 2.2.5)
|
8
|
+
actionpack (3.0.0)
|
9
|
+
activemodel (= 3.0.0)
|
10
|
+
activesupport (= 3.0.0)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4.1)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.12)
|
16
|
+
rack-test (~> 0.5.4)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.0)
|
19
|
+
activesupport (= 3.0.0)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4.1)
|
22
|
+
activesupport (3.0.0)
|
23
|
+
builder (2.1.2)
|
24
|
+
crack (0.1.7)
|
25
|
+
diff-lcs (1.1.2)
|
26
|
+
erubis (2.6.6)
|
27
|
+
abstract (>= 1.0.0)
|
28
|
+
gemcutter (0.6.1)
|
29
|
+
git (1.2.5)
|
30
|
+
i18n (0.4.1)
|
31
|
+
jeweler (1.4.0)
|
32
|
+
gemcutter (>= 0.1.0)
|
33
|
+
git (>= 1.2.5)
|
34
|
+
rubyforge (>= 2.0.0)
|
35
|
+
json_pure (1.4.6)
|
36
|
+
madmimi (1.0.13)
|
37
|
+
crack (= 0.1.7)
|
38
|
+
mail (2.2.6.1)
|
39
|
+
activesupport (>= 2.3.6)
|
40
|
+
mime-types
|
41
|
+
treetop (>= 1.4.5)
|
42
|
+
mime-types (1.16)
|
43
|
+
polyglot (0.3.1)
|
44
|
+
rack (1.2.1)
|
45
|
+
rack-mount (0.6.13)
|
46
|
+
rack (>= 1.0.0)
|
47
|
+
rack-test (0.5.4)
|
48
|
+
rack (>= 1.0)
|
49
|
+
rake (0.8.7)
|
50
|
+
rspec (2.0.0.beta.22)
|
51
|
+
rspec-core (= 2.0.0.beta.22)
|
52
|
+
rspec-expectations (= 2.0.0.beta.22)
|
53
|
+
rspec-mocks (= 2.0.0.beta.22)
|
54
|
+
rspec-core (2.0.0.beta.22)
|
55
|
+
rspec-expectations (2.0.0.beta.22)
|
56
|
+
diff-lcs (>= 1.1.2)
|
57
|
+
rspec-mocks (2.0.0.beta.22)
|
58
|
+
rspec-core (= 2.0.0.beta.22)
|
59
|
+
rspec-expectations (= 2.0.0.beta.22)
|
60
|
+
rubyforge (2.0.4)
|
61
|
+
json_pure (>= 1.1.7)
|
62
|
+
treetop (1.4.8)
|
63
|
+
polyglot (>= 0.3.1)
|
64
|
+
tzinfo (0.3.23)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
actionmailer (>= 3.0.0)
|
71
|
+
jeweler
|
72
|
+
madmimi
|
73
|
+
rake
|
74
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Nate Jackson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= mad_mimi_mailer
|
2
|
+
|
3
|
+
<b><em>If you're not using ActionMailer 3.0 or later, please use version 0.1.2.1 of mad_mimi_mailer.</em></b>
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add to your Gemfile:
|
8
|
+
gem 'mad_mimi_mailer'
|
9
|
+
Then run
|
10
|
+
$ bundle install
|
11
|
+
|
12
|
+
Add to environment.rb, or somewhere before your app loads:
|
13
|
+
MadMimiMail::Configuration.api_settings = {:email => "<email>", :api_key => "<api key>"}
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
=== Create a new mailer as a subclass of MadMimiMailer :
|
18
|
+
|
19
|
+
class MyMailer < MadMimiMailer
|
20
|
+
def money_making_email(user)
|
21
|
+
mimi_params = {
|
22
|
+
:promotion_name => "rakin' it in",
|
23
|
+
:to => user.email,
|
24
|
+
:subject => "sign up now!" }
|
25
|
+
|
26
|
+
mail(mimi_params).do |format|
|
27
|
+
format.html
|
28
|
+
format.text
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
The following parameters are given to Mimi in addition to the rendered content:
|
34
|
+
:name, :from, :subject, :promotion_name, :list_name, :raw_yaml
|
35
|
+
|
36
|
+
http://madmimi.com/developer/mailer/methods
|
37
|
+
|
38
|
+
Use your mailer just like ActionMailer::Base, except your emails will be sent via MadMimi.
|
39
|
+
MyMiailer.money_making_email(user).deliver!
|
40
|
+
|
41
|
+
|
42
|
+
=== Use ActionMailer::Base and configure individual mailers:
|
43
|
+
|
44
|
+
class MyMailer < ActionMailer::Base
|
45
|
+
self.delivery_method = :madmimi
|
46
|
+
...
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
=== Configure ActionMailer::Base to use Mimi by default:
|
51
|
+
|
52
|
+
This may be useful for switching your default mailer in test and/or development environments
|
53
|
+
MyApp::Application.config.action_mailer.delivery_method = :madmimi
|
54
|
+
## or ##
|
55
|
+
ActionMailer::Base.delivery_method = :madmimi
|
56
|
+
|
57
|
+
Copyright (c) 2010 Nate Jackson. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "mad_mimi_mailer"
|
10
|
+
gem.summary = %Q{ActionMailer delivery method for Mad Mimi}
|
11
|
+
gem.description = gem.summary
|
12
|
+
gem.email = "nate.d.jackson@gmail.com"
|
13
|
+
gem.homepage = "http://github.com/njackson/mad_mimi_mailer"
|
14
|
+
gem.authors = ["Nate Jackson"]
|
15
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.20"
|
16
|
+
gem.add_bundler_dependencies
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new(:spec)
|
26
|
+
|
27
|
+
RSpec::Core::RakeTask.new(:rcov => :cleanup_rcov_files) do |spec|
|
28
|
+
spec.rcov = true
|
29
|
+
spec.rcov_opts = %[-Ilib -Ispec --exclude "spec/spec_helper.rb"]
|
30
|
+
spec.rcov_opts << %[--no-html --aggregate coverage.data]
|
31
|
+
end
|
32
|
+
|
33
|
+
task :cleanup_rcov_files do
|
34
|
+
rm_rf 'coverage.data'
|
35
|
+
end
|
36
|
+
|
37
|
+
task :clobber do
|
38
|
+
rm_rf 'pkg'
|
39
|
+
rm_rf 'tmp'
|
40
|
+
rm_rf 'coverage'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :spec => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "mad_mimi_mailer #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'madmimi'
|
2
|
+
require 'action_mailer'
|
3
|
+
|
4
|
+
class MadMimiMail
|
5
|
+
|
6
|
+
attr_accessor :settings
|
7
|
+
def initialize(options)
|
8
|
+
check_api_settings
|
9
|
+
|
10
|
+
@_mimi = MadMimi.new(api_settings[:email], api_settings[:api_key])
|
11
|
+
self.settings = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver!(mail)
|
15
|
+
mail_settings = { :recipients => extract_header(mail, :to),
|
16
|
+
:raw_html => mail.html_part.body,
|
17
|
+
:raw_plain_text => mail.text_part.body}
|
18
|
+
|
19
|
+
[:name, :from, :subject, :promotion_name, :list_name, :raw_yaml].inject(mail_settings) do |hash, header_name|
|
20
|
+
hash.merge!(header_name => extract_header(mail, header_name))
|
21
|
+
end
|
22
|
+
|
23
|
+
mimi_response = @_mimi.send_mail(mail_settings.merge(self.settings), {}.to_yaml)
|
24
|
+
|
25
|
+
#FIXME: (Dirty Hack) Need access to the transaction id from the api call, so
|
26
|
+
# we're defining a new method #transaction_id onto the mail object containing the integer value
|
27
|
+
# DANGER, DANGER! METAPROGRAMMING!
|
28
|
+
transaction_id = mimi_response.to_i
|
29
|
+
add_transaction_id_attribute(mail, transaction_id)
|
30
|
+
|
31
|
+
#if the message isn't an integer, something went wrong and we want to capture it in the mail errors
|
32
|
+
mail.errors << mimi_response if transaction_id.zero?
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_api_settings
|
38
|
+
raise <<-ERROR_STRING.gsub(/^\s+/,'') unless has_required_api_settings?
|
39
|
+
Please configure mad_mimi_mailer with your API settings for MadMimi:
|
40
|
+
|
41
|
+
MadMimiMail::Configuration.api_settings = {:email => "<madmimi email>", :api_key => "<madmimi api key>"}
|
42
|
+
ERROR_STRING
|
43
|
+
end
|
44
|
+
|
45
|
+
def api_settings
|
46
|
+
Configuration.api_settings
|
47
|
+
end
|
48
|
+
|
49
|
+
def has_required_api_settings?
|
50
|
+
api_settings && [:email, :api_key].all? {|k| api_settings.has_key?(k) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def extract_header(mail, header)
|
54
|
+
if mail[header].to_s.blank?
|
55
|
+
nil
|
56
|
+
else
|
57
|
+
mail[header].to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_transaction_id_attribute(object, transaction_id)
|
62
|
+
eigenclass = class << object; self; end
|
63
|
+
eigenclass.class_eval do
|
64
|
+
define_method(:transaction_id) { transaction_id }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class MadMimiMail
|
70
|
+
module Configuration
|
71
|
+
class << self
|
72
|
+
attr_accessor :api_settings
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
ActionMailer::Base.add_delivery_method :madmimi, MadMimiMail
|
data/lib/mad_mimi_mailer.rb
CHANGED
@@ -1,37 +1,3 @@
|
|
1
|
-
require "action_mailer"
|
2
|
-
require "net/http"
|
3
|
-
require "net/https"
|
4
|
-
|
5
|
-
require "mad_mimi_mailable"
|
6
|
-
|
7
1
|
class MadMimiMailer < ActionMailer::Base
|
8
|
-
|
9
|
-
|
10
|
-
@@api_settings = {}
|
11
|
-
cattr_accessor :api_settings
|
12
|
-
|
13
|
-
@@default_parameters = {}
|
14
|
-
cattr_accessor :default_parameters
|
15
|
-
|
16
|
-
@@synchronization_settings = {}
|
17
|
-
cattr_accessor :synchronization_settings
|
18
|
-
|
19
|
-
include MadMimiMailable
|
20
|
-
self.method_prefix = "mimi"
|
21
|
-
|
22
|
-
class ValidationError < StandardError; end
|
23
|
-
|
24
|
-
class TimeoutExceeded < StandardError; end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
# Adding the response body to HTTPResponse errors to provide better error messages.
|
30
|
-
module Net
|
31
|
-
class HTTPResponse
|
32
|
-
def error!
|
33
|
-
message = @code + ' ' + @message.dump + ' ' + body
|
34
|
-
raise error_type().new(message, self)
|
35
|
-
end
|
36
|
-
end
|
2
|
+
self.delivery_method = :madmimi
|
37
3
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mad_mimi_mail}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nate Jackson"]
|
12
|
+
s.date = %q{2010-09-20}
|
13
|
+
s.description = %q{MadMimiMail plugs into ActionMailer to deliver mail through MadMimi in Rails 3}
|
14
|
+
s.email = %q{nate.d.jackson@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".bundle/config",
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/mad_mimi_mail.rb",
|
31
|
+
"lib/mad_mimi_mailer.rb",
|
32
|
+
"mad_mimi_mailer.gemspec",
|
33
|
+
"spec/mad_mimi_mail_spec.rb",
|
34
|
+
"spec/mad_mimi_mailer_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/njackson/mad_mimi_mail}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{ActionMailer delivery method for Mad Mimi}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/mad_mimi_mail_spec.rb",
|
44
|
+
"spec/mad_mimi_mailer_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
54
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<madmimi>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 3.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
61
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
62
|
+
s.add_dependency(%q<madmimi>, [">= 0"])
|
63
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
69
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
70
|
+
s.add_dependency(%q<madmimi>, [">= 0"])
|
71
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
72
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mad_mimi_mailer}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nate Jackson"]
|
12
|
+
s.date = %q{2010-09-22}
|
13
|
+
s.description = %q{ActionMailer delivery method for Mad Mimi}
|
14
|
+
s.email = %q{nate.d.jackson@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".bundle/config",
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/mad_mimi_mail.rb",
|
31
|
+
"lib/mad_mimi_mailer.rb",
|
32
|
+
"mad_mimi_mail.gemspec",
|
33
|
+
"mad_mimi_mailer.gemspec",
|
34
|
+
"spec/mad_mimi_mail_spec.rb",
|
35
|
+
"spec/mad_mimi_mailer_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/njackson/mad_mimi_mailer}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
|
+
s.summary = %q{ActionMailer delivery method for Mad Mimi}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/mad_mimi_mail_spec.rb",
|
45
|
+
"spec/mad_mimi_mailer_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
55
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<madmimi>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 3.0.0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
62
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
63
|
+
s.add_dependency(%q<madmimi>, [">= 0"])
|
64
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
|
70
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
71
|
+
s.add_dependency(%q<madmimi>, [">= 0"])
|
72
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MadMimiMail do
|
4
|
+
let(:mimi) { double(MadMimi) }
|
5
|
+
before :each do
|
6
|
+
MadMimi.stub(:new) { mimi }
|
7
|
+
MadMimiMail::Configuration.api_settings = {:email => "example@example.com", :api_key => "abcdefghijklmnopqrstuvwxyz"}
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#new(options)" do
|
11
|
+
it "stores the options as #settings" do
|
12
|
+
options = {:foo => "bar"}
|
13
|
+
mimi_mail = MadMimiMail.new(options)
|
14
|
+
mimi_mail.settings.should == options
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a MadMimi object with the email and API key from Configuration.api_settings" do
|
18
|
+
settings = MadMimiMail::Configuration.api_settings
|
19
|
+
MadMimi.should_receive(:new).with(settings[:email], settings[:api_key]) { mimi }
|
20
|
+
mimi_mail = MadMimiMail.new(settings)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when Configuration.api_settings is empty" do
|
24
|
+
it "raises an error" do
|
25
|
+
MadMimiMail::Configuration.api_settings = nil
|
26
|
+
lambda {
|
27
|
+
MadMimiMail.new
|
28
|
+
}.should raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#deliver!(mail)" do
|
34
|
+
let(:mail) { double(Mail, :[] => nil).as_null_object }
|
35
|
+
|
36
|
+
it "calls mimi#send_mail with :recipients from the to header" do
|
37
|
+
field = double(:field, :to_s => "to field")
|
38
|
+
mail.stub(:[]).with(:to) { field }
|
39
|
+
mimi.should_receive(:send_mail).with(hash_including(:recipients => field.to_s), anything)
|
40
|
+
mimi_mail = MadMimiMail.new({})
|
41
|
+
mimi_mail.deliver!(mail)
|
42
|
+
end
|
43
|
+
|
44
|
+
[:from, :subject, :name, :promotion_name, :list_name, :raw_yaml].each do |field_name|
|
45
|
+
it "calls mimi#send_mail with :#{field_name} from the #{field_name} header" do
|
46
|
+
field = double(:field, :to_s => "#{field_name} field")
|
47
|
+
mail.stub(:[]).with(field_name) { field }
|
48
|
+
mimi.should_receive(:send_mail).with(hash_including(field_name => field.to_s), anything)
|
49
|
+
mimi_mail = MadMimiMail.new({})
|
50
|
+
mimi_mail.deliver!(mail)
|
51
|
+
end
|
52
|
+
context "when the #{field_name} header is blank" do
|
53
|
+
it "calls mimi#send_mail with :#{field_name} as nil" do
|
54
|
+
field = double(:field, :to_s => "")
|
55
|
+
mail.stub(:[]).with(field_name) { field }
|
56
|
+
mimi.should_receive(:send_mail).with(hash_including(field_name => nil), anything)
|
57
|
+
mimi_mail = MadMimiMail.new({})
|
58
|
+
mimi_mail.deliver!(mail)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "calls mimi#send_mail with :raw_html from mail.html_part" do
|
64
|
+
html_part = double(:part, :body => "<p>HTML part</p>")
|
65
|
+
mail.stub(:html_part) { html_part }
|
66
|
+
mimi.should_receive(:send_mail).with(hash_including(:raw_html => html_part.body), anything)
|
67
|
+
mimi_mail = MadMimiMail.new({})
|
68
|
+
mimi_mail.deliver!(mail)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "calls mimi#send_mail with :raw_plain_text from mail.text_part" do
|
72
|
+
text_part = double(:part, :body => "Text part")
|
73
|
+
mail.stub(:text_part) { text_part }
|
74
|
+
mimi.should_receive(:send_mail).with(hash_including(:raw_plain_text => text_part.body), anything)
|
75
|
+
mimi_mail = MadMimiMail.new({})
|
76
|
+
mimi_mail.deliver!(mail)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "calls mimi#send_mail with the the default settings" do
|
80
|
+
settings = {:promotion_name => "Promotion name", :list_name => "List name", :subject => "A Subject", :from => "from@example.com"}
|
81
|
+
mimi.should_receive(:send_mail).with(hash_including(settings), anything)
|
82
|
+
mimi_mail = MadMimiMail.new(settings)
|
83
|
+
mimi_mail.deliver!(mail)
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when mimi's response is a transaction code" do
|
87
|
+
let(:transaction_id) { 12345567890 }
|
88
|
+
let(:mimi) { double(MadMimi, :send_mail => transaction_id.to_s) }
|
89
|
+
before :each do
|
90
|
+
mail.stub(:html_part) { double(:html_part).as_null_object }
|
91
|
+
mail.stub(:text_part) { double(:text_part).as_null_object }
|
92
|
+
mimi.stub(:send_mail) { transaction_id.to_s }
|
93
|
+
end
|
94
|
+
|
95
|
+
it "defines #transaction_id on the mail object returning the transaction code as an integer" do
|
96
|
+
mimi_mail = MadMimiMail.new({})
|
97
|
+
mimi_mail.deliver!(mail)
|
98
|
+
mail.should respond_to(:transaction_id)
|
99
|
+
mail.transaction_id.should == transaction_id
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when mimi's response is not a transaction code" do
|
104
|
+
let(:error_message) { "Error Message" }
|
105
|
+
before :each do
|
106
|
+
mimi.stub(:send_mail) { error_message }
|
107
|
+
mail.stub(:errors).and_return([])
|
108
|
+
end
|
109
|
+
it "adds mimi's response to the mail#errors array" do
|
110
|
+
mimi_mail = MadMimiMail.new({})
|
111
|
+
mimi_mail.deliver!(mail)
|
112
|
+
mail.errors.should == [error_message]
|
113
|
+
end
|
114
|
+
it "defines #transaction_id on the mail object returning 0" do
|
115
|
+
mimi_mail = MadMimiMail.new({})
|
116
|
+
mimi_mail.deliver!(mail)
|
117
|
+
mail.transaction_id.should == 0
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MadMimiMailer do
|
4
|
+
it "inherits from ActionMailer::Base" do
|
5
|
+
MadMimiMailer.superclass.should == ActionMailer::Base
|
6
|
+
end
|
7
|
+
it "uses :madmimi for the delivery_method" do
|
8
|
+
MadMimiMailer.delivery_method.should == :madmimi
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,43 +1,140 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mad_mimi_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 75
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
- 3
|
7
|
+
- 2
|
10
8
|
- 0
|
11
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
12
10
|
platform: ruby
|
13
11
|
authors:
|
14
|
-
-
|
12
|
+
- Nate Jackson
|
15
13
|
autorequire:
|
16
14
|
bindir: bin
|
17
15
|
cert_chain: []
|
18
16
|
|
19
|
-
date: 2010-
|
17
|
+
date: 2010-09-22 00:00:00 -05:00
|
20
18
|
default_executable:
|
21
|
-
dependencies:
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- beta
|
32
|
+
- 20
|
33
|
+
version: 2.0.0.beta.20
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: madmimi
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: actionmailer
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 3
|
72
|
+
- 0
|
73
|
+
- 0
|
74
|
+
version: 3.0.0
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id006
|
104
|
+
description: ActionMailer delivery method for Mad Mimi
|
105
|
+
email: nate.d.jackson@gmail.com
|
25
106
|
executables: []
|
26
107
|
|
27
108
|
extensions: []
|
28
109
|
|
29
|
-
extra_rdoc_files:
|
30
|
-
|
110
|
+
extra_rdoc_files:
|
111
|
+
- LICENSE
|
112
|
+
- README.rdoc
|
31
113
|
files:
|
114
|
+
- .bundle/config
|
115
|
+
- .document
|
116
|
+
- .gitignore
|
117
|
+
- .rspec
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- LICENSE
|
121
|
+
- README.rdoc
|
122
|
+
- Rakefile
|
123
|
+
- VERSION
|
124
|
+
- lib/mad_mimi_mail.rb
|
32
125
|
- lib/mad_mimi_mailer.rb
|
33
|
-
-
|
126
|
+
- mad_mimi_mail.gemspec
|
127
|
+
- mad_mimi_mailer.gemspec
|
128
|
+
- spec/mad_mimi_mail_spec.rb
|
129
|
+
- spec/mad_mimi_mailer_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
34
131
|
has_rdoc: true
|
35
|
-
homepage: http://
|
132
|
+
homepage: http://github.com/njackson/mad_mimi_mailer
|
36
133
|
licenses: []
|
37
134
|
|
38
135
|
post_install_message:
|
39
|
-
rdoc_options:
|
40
|
-
|
136
|
+
rdoc_options:
|
137
|
+
- --charset=UTF-8
|
41
138
|
require_paths:
|
42
139
|
- lib
|
43
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -45,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
142
|
requirements:
|
46
143
|
- - ">="
|
47
144
|
- !ruby/object:Gem::Version
|
48
|
-
hash:
|
145
|
+
hash: 3932568935660886393
|
49
146
|
segments:
|
50
147
|
- 0
|
51
148
|
version: "0"
|
@@ -54,17 +151,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
151
|
requirements:
|
55
152
|
- - ">="
|
56
153
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 11
|
58
154
|
segments:
|
59
|
-
-
|
60
|
-
|
61
|
-
version: "1.2"
|
155
|
+
- 0
|
156
|
+
version: "0"
|
62
157
|
requirements: []
|
63
158
|
|
64
|
-
rubyforge_project:
|
159
|
+
rubyforge_project:
|
65
160
|
rubygems_version: 1.3.7
|
66
161
|
signing_key:
|
67
162
|
specification_version: 3
|
68
|
-
summary:
|
69
|
-
test_files:
|
70
|
-
|
163
|
+
summary: ActionMailer delivery method for Mad Mimi
|
164
|
+
test_files:
|
165
|
+
- spec/mad_mimi_mail_spec.rb
|
166
|
+
- spec/mad_mimi_mailer_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
data/lib/mad_mimi_mailable.rb
DELETED
@@ -1,239 +0,0 @@
|
|
1
|
-
module MadMimiMailable
|
2
|
-
SINGLE_SEND_URL = 'https://api.madmimi.com/mailer'
|
3
|
-
STATUS_URL = 'https://api.madmimi.com/mailers/status/TRANSACTION_ID'
|
4
|
-
SYNCHRONOUS_SLEEP = 1
|
5
|
-
SYNCHRONOUS_TIMEOUT = 10
|
6
|
-
|
7
|
-
def self.included(base)
|
8
|
-
base.extend(ClassMethods)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Custom Mailer attributes
|
12
|
-
|
13
|
-
def promotion(promotion = nil)
|
14
|
-
if promotion.nil?
|
15
|
-
@promotion
|
16
|
-
else
|
17
|
-
@promotion = promotion
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def use_erb(use_erb = nil)
|
22
|
-
if use_erb.nil?
|
23
|
-
@use_erb
|
24
|
-
else
|
25
|
-
@use_erb = use_erb
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def hidden(hidden = nil)
|
30
|
-
if hidden.nil?
|
31
|
-
@hidden
|
32
|
-
else
|
33
|
-
@hidden = hidden
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def unconfirmed(value = nil)
|
38
|
-
if value.nil?
|
39
|
-
@unconfirmed
|
40
|
-
else
|
41
|
-
@unconfirmed = value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
module ClassMethods
|
46
|
-
attr_accessor :method_prefix, :use_erb
|
47
|
-
|
48
|
-
def method_missing(method_symbol, *parameters)
|
49
|
-
if method_prefix && method_symbol.id2name.match(/^deliver_(#{method_prefix}_[_a-z]\w*)/)
|
50
|
-
deliver_mimi_mail($1, *parameters)
|
51
|
-
elsif method_prefix.nil? && method_symbol.id2name.match(/^deliver_([_a-z]\w*)/)
|
52
|
-
deliver_mimi_mail($1, *parameters)
|
53
|
-
else
|
54
|
-
super
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def deliver_mimi_mail(method, *parameters)
|
59
|
-
mail = new
|
60
|
-
mail.__send__(method, *parameters)
|
61
|
-
|
62
|
-
if use_erb?(mail)
|
63
|
-
mail.create!(method, *parameters)
|
64
|
-
end
|
65
|
-
|
66
|
-
return unless perform_deliveries
|
67
|
-
if delivery_method == :test
|
68
|
-
deliveries << (mail.mail ? mail.mail : mail)
|
69
|
-
else
|
70
|
-
if (all_recipients = mail.recipients).is_a? Array
|
71
|
-
all_recipients.each do |recipient|
|
72
|
-
mail.recipients = recipient
|
73
|
-
call_api!(mail, method)
|
74
|
-
end
|
75
|
-
else
|
76
|
-
call_api!(mail, method)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def call_api!(mail, method)
|
82
|
-
params = {
|
83
|
-
'username' => MadMimiMailer.api_settings[:username],
|
84
|
-
'api_key' => MadMimiMailer.api_settings[:api_key],
|
85
|
-
'promotion_name' => mail.promotion || method.to_s.sub(/^#{method_prefix}_/, ''),
|
86
|
-
'recipients' => serialize(mail.recipients),
|
87
|
-
'subject' => mail.subject,
|
88
|
-
'bcc' => serialize(mail.bcc || MadMimiMailer.default_parameters[:bcc]),
|
89
|
-
'from' => (mail.from || MadMimiMailer.default_parameters[:from]),
|
90
|
-
'hidden' => serialize(mail.hidden)
|
91
|
-
}
|
92
|
-
|
93
|
-
params['unconfirmed'] = '1' if mail.unconfirmed
|
94
|
-
|
95
|
-
if use_erb?(mail)
|
96
|
-
if mail.parts.any?
|
97
|
-
params['raw_plain_text'] = content_for(mail, "text/plain")
|
98
|
-
params['raw_html'] = content_for(mail, "text/html") { |html| validate(html.body) }
|
99
|
-
else
|
100
|
-
validate(mail.body)
|
101
|
-
params['raw_html'] = mail.body
|
102
|
-
end
|
103
|
-
else
|
104
|
-
stringified_default_body = (MadMimiMailer.default_parameters[:body] || {}).stringify_keys!
|
105
|
-
stringified_mail_body = (mail.body || {}).stringify_keys!
|
106
|
-
body_hash = stringified_default_body.merge(stringified_mail_body)
|
107
|
-
params['body'] = body_hash.to_yaml
|
108
|
-
end
|
109
|
-
|
110
|
-
response = post_request do |request|
|
111
|
-
request.set_form_data(params)
|
112
|
-
end
|
113
|
-
|
114
|
-
check_response(response)
|
115
|
-
end
|
116
|
-
|
117
|
-
def call_status_api!(transaction_id)
|
118
|
-
params = {
|
119
|
-
'username' => MadMimiMailer.api_settings[:username],
|
120
|
-
'api_key' => MadMimiMailer.api_settings[:api_key]
|
121
|
-
}
|
122
|
-
response = status_get_request(transaction_id) do |request|
|
123
|
-
request.set_form_data(params)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def check_response(response)
|
128
|
-
transaction_id = asynchronous_response(response)
|
129
|
-
if synchronous?
|
130
|
-
synchronous_response(transaction_id)
|
131
|
-
end
|
132
|
-
transaction_id
|
133
|
-
end
|
134
|
-
|
135
|
-
def synchronous?
|
136
|
-
sync_setting = MadMimiMailer.synchronization_settings[:synchronous]
|
137
|
-
!sync_setting.nil? && sync_setting == true
|
138
|
-
end
|
139
|
-
|
140
|
-
def asynchronous_response(response)
|
141
|
-
check_for_success(response)
|
142
|
-
end
|
143
|
-
|
144
|
-
def synchronous_response(transaction_id)
|
145
|
-
status = nil
|
146
|
-
start = Time.now
|
147
|
-
while (Time.now - start) < timeout_period
|
148
|
-
response = call_status_api!(transaction_id)
|
149
|
-
status = check_for_success(response)
|
150
|
-
if status == 'failed'
|
151
|
-
response.error!
|
152
|
-
elsif !%w(ignorant sending).include?(status)
|
153
|
-
break
|
154
|
-
else
|
155
|
-
sleep(sleep_period)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
raise MadMimiMailer::TimeoutExceeded if !suppress_timeout_exception? &&( status.blank? || %w(ignorant sending).include?(status))
|
159
|
-
status
|
160
|
-
end
|
161
|
-
|
162
|
-
def check_for_success(response)
|
163
|
-
case response
|
164
|
-
when Net::HTTPSuccess
|
165
|
-
response.body
|
166
|
-
else
|
167
|
-
response.error!
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def sleep_period
|
172
|
-
SYNCHRONOUS_SLEEP
|
173
|
-
end
|
174
|
-
|
175
|
-
def timeout_period
|
176
|
-
timeout_setting = MadMimiMailer.synchronization_settings[:timeout]
|
177
|
-
return timeout_setting if !timeout_setting.nil?
|
178
|
-
SYNCHRONOUS_TIMEOUT
|
179
|
-
end
|
180
|
-
|
181
|
-
def suppress_timeout_exception?
|
182
|
-
MadMimiMailer.synchronization_settings[:suppress_timeout_exception] == true
|
183
|
-
end
|
184
|
-
|
185
|
-
def content_for(mail, content_type)
|
186
|
-
part = mail.parts.detect {|p| p.content_type == content_type }
|
187
|
-
if part
|
188
|
-
yield(part) if block_given?
|
189
|
-
part.body
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def validate(content)
|
194
|
-
unless content.include?("[[peek_image]]") || content.include?("[[tracking_beacon]]")
|
195
|
-
raise MadMimiMailer::ValidationError, "You must include a web beacon in your Mimi email: [[peek_image]]"
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def post_request
|
200
|
-
url = URI.parse(SINGLE_SEND_URL)
|
201
|
-
request = Net::HTTP::Post.new(url.path)
|
202
|
-
yield(request)
|
203
|
-
http = Net::HTTP.new(url.host, url.port)
|
204
|
-
http.use_ssl = true
|
205
|
-
http.start do |http|
|
206
|
-
http.request(request)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def status_get_request(transaction_id)
|
211
|
-
url = URI.parse(STATUS_URL.gsub!('TRANSACTION_ID', transaction_id))
|
212
|
-
request = Net::HTTP::Get.new(url.path)
|
213
|
-
yield(request)
|
214
|
-
http = Net::HTTP.new(url.host, url.port)
|
215
|
-
http.use_ssl = true
|
216
|
-
http.start do |http|
|
217
|
-
http.request(request)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def serialize(recipients)
|
222
|
-
case recipients
|
223
|
-
when String
|
224
|
-
recipients
|
225
|
-
when Array
|
226
|
-
recipients.join(", ")
|
227
|
-
when NilClass
|
228
|
-
nil
|
229
|
-
else
|
230
|
-
raise "Please provide a String or an Array for recipients or bcc."
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def use_erb?(mail)
|
235
|
-
mail.use_erb || use_erb
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|