redsquirrel-mad_mimi_mailer 0.0.1
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 +70 -0
- metadata +53 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require "actionmailer"
|
|
2
|
+
require "net/http"
|
|
3
|
+
|
|
4
|
+
class MadMimiMailer < ActionMailer::Base
|
|
5
|
+
VERSION = '0.0.1'
|
|
6
|
+
SINGLE_SEND_URL = 'https://madmimi.com/single_sends'
|
|
7
|
+
|
|
8
|
+
@@api_settings = {}
|
|
9
|
+
cattr_accessor :api_settings
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
|
|
13
|
+
def method_missing(method_symbol, *parameters)
|
|
14
|
+
if method_symbol.id2name.match(/^deliver_(mimi_[_a-z]\w*)/)
|
|
15
|
+
deliver_mimi_mail($1, *parameters)
|
|
16
|
+
|
|
17
|
+
else
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def deliver_mimi_mail(method, *parameters)
|
|
23
|
+
mail = new
|
|
24
|
+
mail.__send__(method, *parameters)
|
|
25
|
+
|
|
26
|
+
return unless perform_deliveries
|
|
27
|
+
|
|
28
|
+
if delivery_method == :test
|
|
29
|
+
deliveries << self
|
|
30
|
+
|
|
31
|
+
else
|
|
32
|
+
call_api!(mail, method)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def call_api!(mail, method)
|
|
37
|
+
response = post_request do |request|
|
|
38
|
+
request.set_form_data(
|
|
39
|
+
'username' => api_settings[:username],
|
|
40
|
+
'api_key' => api_settings[:api_key],
|
|
41
|
+
|
|
42
|
+
'promotion_name' => method.to_s.sub(/^mimi_/, ''),
|
|
43
|
+
'recipients' => mail.recipients,
|
|
44
|
+
'subject' => mail.subject,
|
|
45
|
+
'bcc' => mail.bcc,
|
|
46
|
+
'from' => mail.from,
|
|
47
|
+
'body' => mail.body.to_yaml
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
case response
|
|
52
|
+
when Net::HTTPSuccess
|
|
53
|
+
response
|
|
54
|
+
else
|
|
55
|
+
response.error!
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def post_request
|
|
60
|
+
url = URI.parse(SINGLE_SEND_URL)
|
|
61
|
+
request = Net::HTTP::Post.new(url.path)
|
|
62
|
+
yield(request)
|
|
63
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
64
|
+
http.use_ssl = true
|
|
65
|
+
http.start do |http|
|
|
66
|
+
http.request(request)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: redsquirrel-mad_mimi_mailer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dave Hoover
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-05-06 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Use Mad Mimi to send beautiful HTML emails using the ActionMailer API.
|
|
17
|
+
email: dave@obtiva.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- lib/mad_mimi_mailer.rb
|
|
26
|
+
has_rdoc: true
|
|
27
|
+
homepage: http://madmimi.com/support/mailer
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: "0"
|
|
38
|
+
version:
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: "1.2"
|
|
44
|
+
version:
|
|
45
|
+
requirements: []
|
|
46
|
+
|
|
47
|
+
rubyforge_project: mad_mimi_mailer
|
|
48
|
+
rubygems_version: 1.2.0
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 2
|
|
51
|
+
summary: Extending ActionMailer::Base for Mad Mimi integration.
|
|
52
|
+
test_files: []
|
|
53
|
+
|