mad_mimi_two 0.04 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +25 -10
- data/Rakefile +1 -1
- data/lib/mad_mimi_two/mad_mimi_mailer.rb +24 -2
- data/lib/mad_mimi_two.rb +1 -1
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_mad_mimi_two.rb +34 -4
- metadata +72 -29
data/README.rdoc
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
courtesy scott sproule
|
6
6
|
www.estormtech.com
|
7
7
|
|
8
|
-
|
8
|
+
Why use Mad Mimi rather than action mailer? Primarily since it allows you to separate the design of your emails from the code. Create nice designs on mad mimi, add analytics tracking urls, and update the contents of promotions via the mad mimi interface rather than trying to do it all in your code.
|
9
9
|
|
10
10
|
== DESCRIPTION:
|
11
11
|
|
12
|
-
Using Mad Mimi on rails 3. All of the elegant portions of the code are based on the original http://github.com/redsquirrel/mad_mimi_mailer by ethangunderson.
|
12
|
+
Using Mad Mimi on rails 3. All of the elegant portions of the code are based on the original http://github.com/redsquirrel/mad_mimi_mailer by ethangunderson. (MadMimiTwo also runs in Rails 2)
|
13
13
|
|
14
14
|
All of the terrible stuff is by me. Apologies for taking an elegant solution and just crafting something that works.
|
15
15
|
|
@@ -18,13 +18,11 @@ All of the terrible stuff is by me. Apologies for taking an elegant solution an
|
|
18
18
|
* FIX (list of features or problems)
|
19
19
|
This has only been tested on Ruby 1.8.7.
|
20
20
|
Testing on Ruby 1.9 required.
|
21
|
-
Currently
|
21
|
+
Currently tested and working with rails 3 beta and Rails 2 (same code works)
|
22
22
|
|
23
|
-
If someone could suggest how to get rid of this I would be grateful:
|
24
|
-
./lib/mad_mimi_two/mad_mimi_mailer.rb:71: warning: default `to_a' will be obsolete
|
25
23
|
|
26
24
|
== SYNOPSIS:
|
27
|
-
== API CONFIG
|
25
|
+
== API CONFIG
|
28
26
|
Setup your api key in application.rb (at the end of the file, after the end for the config)
|
29
27
|
MadMimiTwo::MadMimiMessage.api_settings = {
|
30
28
|
:username => 'your_username@xys.com',
|
@@ -35,7 +33,7 @@ Setup your api key in application.rb (at the end of the file, after the end for
|
|
35
33
|
gem 'mad_mimi_two'
|
36
34
|
|
37
35
|
== MIMI MODEL
|
38
|
-
set up model (something like
|
36
|
+
set up model in your rails model directory (something like the following)
|
39
37
|
class MadMimi < MadMimiTwo::MadMimiMessage
|
40
38
|
def self.mimi_promotion(tpromotion,tuser,thashvalues,cclist, tsubj)
|
41
39
|
msg=MadMimiTwo::MadMimiMessage.new do
|
@@ -44,7 +42,7 @@ class MadMimi < MadMimiTwo::MadMimiMessage
|
|
44
42
|
cc cclist
|
45
43
|
promotion tpromotion #[MAD MIMI PROMOTION NAME]
|
46
44
|
from 'support@estormtech.com'
|
47
|
-
bcc ["
|
45
|
+
bcc ["xyze@estormtech.com", "abc@estormtech.com"]
|
48
46
|
email_placeholders thashvalues # [VALUES THAT NEED TO BE INSERTED AT MAD MIMI EMAIL these are the values in {} in the mad mimi email that you want replaced eg {:url='www.estormtech.com'}]
|
49
47
|
content_type "text/html"
|
50
48
|
end
|
@@ -58,6 +56,20 @@ this will return a ID from mad mimi like 1151260526
|
|
58
56
|
|
59
57
|
IGNORE: warning: peer certificate won't be verified in this SSL session
|
60
58
|
|
59
|
+
== Mail::Message
|
60
|
+
As this is subclassed from Mail::Message I believe that other ways to create the message will also work (such as passing in hash, etc (see the documentation))
|
61
|
+
|
62
|
+
== Check Status of sent message
|
63
|
+
t=MadMimiTwo::MadMimiMessage.new
|
64
|
+
r=t.check_status('1159748168') # this is value from ID
|
65
|
+
r is 'Sent'
|
66
|
+
|
67
|
+
== RAILS 2:
|
68
|
+
NOTE, The same code works in Rails 2 as well.
|
69
|
+
except that you need to change environment.rb
|
70
|
+
config.gem 'mad_mimi_two'
|
71
|
+
and at the end of the environment.rb file:
|
72
|
+
insert the api settings.
|
61
73
|
|
62
74
|
== REQUIREMENTS:
|
63
75
|
|
@@ -67,8 +79,11 @@ gem mail
|
|
67
79
|
|
68
80
|
== INSTALL:
|
69
81
|
|
70
|
-
|
71
|
-
|
82
|
+
gem install mad_mimi_two (it is now up on rubygems.org)
|
83
|
+
|
84
|
+
== RAILS TESTING:
|
85
|
+
|
86
|
+
Apologies but this needs work. I have simple tests in my application but nothing spectacular.
|
72
87
|
|
73
88
|
== LICENSE:
|
74
89
|
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ $hoe = Hoe.spec 'mad_mimi_two' do
|
|
16
16
|
self.post_install_message = 'For more information on mad_mimi_two, see
|
17
17
|
http://github.com/semdinsp/mad_mimi_two' # TODO remove if post-install message not required
|
18
18
|
self.rubyforge_name = self.name # TODO this is default value
|
19
|
-
#
|
19
|
+
#self.add_dependency("httpclient")
|
20
20
|
|
21
21
|
end
|
22
22
|
|
@@ -1,3 +1,14 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'httpclient'
|
4
|
+
require 'httpclient'
|
5
|
+
class Hash
|
6
|
+
def madmimiurlencode
|
7
|
+
to_a.map do |name_value|
|
8
|
+
name_value.map { |e| CGI.escape e.to_s }.join '='
|
9
|
+
end.join '&'
|
10
|
+
end
|
11
|
+
end
|
1
12
|
module MadMimiTwo
|
2
13
|
module MadMimiMailer
|
3
14
|
SINGLE_SEND_URL = 'https://api.madmimi.com/mailer'
|
@@ -5,6 +16,17 @@ module MadMimiTwo
|
|
5
16
|
def self.included(base)
|
6
17
|
base.extend(ClassMethods)
|
7
18
|
end
|
19
|
+
# check the status of a sent email
|
20
|
+
def check_status(msg_id)
|
21
|
+
url = "#{SINGLE_SEND_URL}s/status/#{msg_id}?#{MadMimiTwo::MadMimiMessage.api_settings.madmimiurlencode}"
|
22
|
+
begin
|
23
|
+
client= HTTPClient.new
|
24
|
+
res=client.get_content(url)
|
25
|
+
rescue HTTPClient::BadResponseError
|
26
|
+
res="problem retrieving status"
|
27
|
+
end
|
28
|
+
res
|
29
|
+
end
|
8
30
|
|
9
31
|
# Custom Mailer attributes
|
10
32
|
|
@@ -68,9 +90,9 @@ module MadMimiTwo
|
|
68
90
|
'username' => MadMimiTwo::MadMimiMessage.api_settings[:username],
|
69
91
|
'api_key' => MadMimiTwo::MadMimiMessage.api_settings[:api_key],
|
70
92
|
'promotion_name' => self.promotion, # scott || method.to_s.sub(/^#{method_prefix}_/, ''),
|
71
|
-
'recipients' => serialize(self[:to].
|
93
|
+
'recipients' => serialize(self[:to].to_s.split(',')), #removed to_a, needs comma
|
72
94
|
'subject' => self[:subject].to_s,
|
73
|
-
'bcc' => serialize(self[:bcc].
|
95
|
+
'bcc' => serialize(self[:bcc].to_s.split(',') || MadMimiMailer.default_parameters[:bcc]),
|
74
96
|
'from' => (self[:from].to_s || MadMimiMailer.default_parameters[:from]),
|
75
97
|
'hidden' => serialize(self.hidden)
|
76
98
|
}
|
data/lib/mad_mimi_two.rb
CHANGED
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/mad_mimi_two.rb'}"
|
9
|
+
puts "Loading mad_mimi_two gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_mad_mimi_two.rb
CHANGED
@@ -14,7 +14,9 @@ class TestMadMimiTwo < Test::Unit::TestCase
|
|
14
14
|
puts t.inspect
|
15
15
|
assert t.headers.size==0, "headers not empty"
|
16
16
|
end
|
17
|
-
def
|
17
|
+
def test_header
|
18
|
+
test="hello there"
|
19
|
+
hashv={ :body => test, :user => 'string'}
|
18
20
|
t=MadMimiTwo::MadMimiMessage.new do
|
19
21
|
subject 'tsubj test subject'
|
20
22
|
to 'scott.sproule@ficonab.com'
|
@@ -23,13 +25,33 @@ class TestMadMimiTwo < Test::Unit::TestCase
|
|
23
25
|
from 'support@estormtech.com'
|
24
26
|
bcc ["scott.sproule@estormtech.com", "eka.mardiarti@estormtech.com"]
|
25
27
|
# sent_on Time.now
|
26
|
-
|
28
|
+
email_placeholders hashv # :user => tuser, :url => turl
|
27
29
|
content_type "text/html"
|
28
30
|
end
|
29
31
|
puts t.inspect
|
30
32
|
assert t.headers.size==0, "headers not empty"
|
31
33
|
assert t[:to].to_s=='scott.sproule@ficonab.com', "to person not correct #{t[:to]}"
|
32
34
|
assert t.promotion.to_s=='new_crm', 'promotion first wrong'
|
35
|
+
assert t.email_placeholders.has_key?(:body), "placeholders seem wrong #{t.email_placeholders}"
|
36
|
+
assert t.email_placeholders.value?("hello there"), "placeholders seem wrong #{t.email_placeholders}"
|
37
|
+
#assert t[:promotion].to_s=='new_crm', 'promotion wrong'
|
38
|
+
end
|
39
|
+
def test_header_setup2
|
40
|
+
test="hello there"
|
41
|
+
t=MadMimiTwo::MadMimiMessage.new do
|
42
|
+
subject 'tsubj test subject'
|
43
|
+
to 'scott.sproule@ficonab.com'
|
44
|
+
# cc admin
|
45
|
+
promotion 'new_crm'
|
46
|
+
from 'support@estormtech.com'
|
47
|
+
bcc ["scott.sproule@estormtech.com", "eka.mardiarti@estormtech.com"]
|
48
|
+
# sent_on Time.now
|
49
|
+
email_placeholders :body => test, :user => 'string'
|
50
|
+
content_type "text/html"
|
51
|
+
end
|
52
|
+
puts t.inspect
|
53
|
+
assert t.email_placeholders.has_key?(:body), "placeholders seem wrong #{t.email_placeholders}"
|
54
|
+
assert t.email_placeholders.value?("hello there"), "placeholders seem wrong #{t.email_placeholders}"
|
33
55
|
#assert t[:promotion].to_s=='new_crm', 'promotion wrong'
|
34
56
|
end
|
35
57
|
def test_sending_mesage
|
@@ -47,11 +69,19 @@ class TestMadMimiTwo < Test::Unit::TestCase
|
|
47
69
|
end
|
48
70
|
# t.email_placeholders(thash)
|
49
71
|
r=t.deliver_mimi_message
|
50
|
-
puts "result: #{r} message: t.inspect"
|
51
|
-
assert t.headers.size==0, "headers not empty"
|
72
|
+
puts "result: #{r} message: #{t.inspect}"
|
52
73
|
assert t.headers.size==0, "headers not empty"
|
53
74
|
assert t[:to].to_s=='scott.sproule@ficonab.com', "to person not correct #{t[:to]}"
|
54
75
|
assert t.promotion.to_s=='new_crm', 'promotion first wrong'
|
55
76
|
#assert t[:promotion].to_s=='new_crm', 'promotion wrong'
|
56
77
|
end
|
78
|
+
def test_check_status
|
79
|
+
# puts "message id: 1159748168" (old message id)
|
80
|
+
t=MadMimiTwo::MadMimiMessage.new
|
81
|
+
r=t.check_status('1159748168')
|
82
|
+
puts "'r is ' #{r}"
|
83
|
+
assert r.class==String, "response is not string r is: #{r} #{r.class}"
|
84
|
+
assert r=='sent', "message response not correct: #{r}"
|
85
|
+
|
86
|
+
end
|
57
87
|
end
|
metadata
CHANGED
@@ -1,49 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mad_mimi_two
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
-
|
13
|
+
- scott sproule
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-26 00:00:00 +08:00
|
18
19
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rubyforge
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 2.0.3
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 0
|
50
|
+
version: 2.6.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: |-
|
54
|
+
Using Mad Mimi on rails 3. All of the elegant portions of the code are based on the original http://github.com/redsquirrel/mad_mimi_mailer by ethangunderson. (MadMimiTwo also runs in Rails 2)
|
55
|
+
|
56
|
+
All of the terrible stuff is by me. Apologies for taking an elegant solution and just crafting something that works.
|
57
|
+
email:
|
58
|
+
- scott.sproule@ficonab.com
|
23
59
|
executables: []
|
24
60
|
|
25
61
|
extensions: []
|
26
62
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
63
|
+
extra_rdoc_files:
|
64
|
+
- History.txt
|
65
|
+
- Manifest.txt
|
66
|
+
- PostInstall.txt
|
29
67
|
files:
|
30
|
-
- lib/mad_mimi_two/mad_mimi_mailer.rb
|
31
|
-
- lib/mad_mimi_two/mad_mimi_message.rb
|
32
|
-
- lib/mad_mimi_two.rb
|
33
|
-
- test/test_helper.rb
|
34
|
-
- test/test_mad_mimi_two.rb
|
35
68
|
- History.txt
|
36
69
|
- Manifest.txt
|
37
70
|
- PostInstall.txt
|
38
|
-
- Rakefile
|
39
71
|
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- lib/mad_mimi_two.rb
|
74
|
+
- lib/mad_mimi_two/mad_mimi_mailer.rb
|
75
|
+
- lib/mad_mimi_two/mad_mimi_message.rb
|
76
|
+
- script/console
|
77
|
+
- script/destroy
|
78
|
+
- script/generate
|
79
|
+
- test/test_helper.rb
|
80
|
+
- test/test_mad_mimi_two.rb
|
40
81
|
has_rdoc: true
|
41
|
-
homepage: http://github.com/semdinsp/
|
82
|
+
homepage: http://github.com/semdinsp/mad_mimi_two
|
42
83
|
licenses: []
|
43
84
|
|
44
|
-
post_install_message:
|
45
|
-
|
46
|
-
|
85
|
+
post_install_message: |-
|
86
|
+
For more information on mad_mimi_two, see
|
87
|
+
http://github.com/semdinsp/mad_mimi_two
|
88
|
+
rdoc_options:
|
89
|
+
- --main
|
90
|
+
- README.rdoc
|
47
91
|
require_paths:
|
48
92
|
- lib
|
49
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -60,18 +104,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
104
|
requirements:
|
61
105
|
- - ">="
|
62
106
|
- !ruby/object:Gem::Version
|
63
|
-
hash:
|
107
|
+
hash: 3
|
64
108
|
segments:
|
65
|
-
-
|
66
|
-
|
67
|
-
- 4
|
68
|
-
version: 1.3.4
|
109
|
+
- 0
|
110
|
+
version: "0"
|
69
111
|
requirements: []
|
70
112
|
|
71
113
|
rubyforge_project: mad_mimi_two
|
72
114
|
rubygems_version: 1.3.7
|
73
115
|
signing_key:
|
74
116
|
specification_version: 3
|
75
|
-
summary:
|
76
|
-
test_files:
|
77
|
-
|
117
|
+
summary: Using Mad Mimi on rails 3
|
118
|
+
test_files:
|
119
|
+
- test/test_helper.rb
|
120
|
+
- test/test_mad_mimi_two.rb
|