madmimi_for_rails_two 0.5.0 → 0.5.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/madmimi_for_rails_two.rb +77 -0
- metadata +5 -5
@@ -0,0 +1,77 @@
|
|
1
|
+
class MadMimi
|
2
|
+
BASE_URL = 'api.madmimi.com'
|
3
|
+
STATUS_PATH = '/mailers/status'
|
4
|
+
SEND_PATH = '/mailer'
|
5
|
+
cattr_accessor :api_settings
|
6
|
+
|
7
|
+
def self.is_transactional
|
8
|
+
api_settings[:transactional].nil? || api_settings[:transactional] == true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.username
|
12
|
+
api_settings[:username]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.api_key
|
16
|
+
api_settings[:api_key]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.check_status(transaction_id)
|
20
|
+
return if transaction_id.nil?
|
21
|
+
return unless is_transactional
|
22
|
+
|
23
|
+
connection.get("#{STATUS_PATH}/#{transaction_id}?username=#{username}&api_key=#{api_key}").body
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.connection
|
27
|
+
http = Net::HTTP.new(BASE_URL, is_transactional ? 443 : 80)
|
28
|
+
|
29
|
+
if is_transactional
|
30
|
+
http.use_ssl = true
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
+
end
|
33
|
+
|
34
|
+
http
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class TMail::Mail
|
39
|
+
|
40
|
+
attr_accessor :transaction_id
|
41
|
+
|
42
|
+
def check_madmimi_status
|
43
|
+
MadMimi.check_status(transaction_id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class ActionMailer::Base
|
48
|
+
|
49
|
+
adv_attr_accessor :promotion_name
|
50
|
+
|
51
|
+
def perform_delivery_madmimi(mail)
|
52
|
+
|
53
|
+
form_data = {
|
54
|
+
'username' => MadMimi.username,
|
55
|
+
'api_key' => MadMimi.api_key,
|
56
|
+
'promotion_name' => promotion_name,
|
57
|
+
'recipients' => recipients,
|
58
|
+
'from' => from,
|
59
|
+
'subject' => subject,
|
60
|
+
'reply_to' => reply_to,
|
61
|
+
'raw_html' => body + ' [[tracking_beacon]]'
|
62
|
+
}
|
63
|
+
|
64
|
+
http = MadMimi.connection
|
65
|
+
|
66
|
+
begin
|
67
|
+
http.start do |http|
|
68
|
+
request = Net::HTTP::Post.new(MadMimi::SEND_PATH)
|
69
|
+
request.set_form_data(form_data)
|
70
|
+
response = http.request(request)
|
71
|
+
mail.transaction_id = response.body.strip
|
72
|
+
end
|
73
|
+
rescue SocketError
|
74
|
+
raise "Host unreachable."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madmimi_for_rails_two
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Soarez
|
@@ -27,8 +27,8 @@ extensions: []
|
|
27
27
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
|
-
files:
|
31
|
-
|
30
|
+
files:
|
31
|
+
- lib/madmimi_for_rails_two.rb
|
32
32
|
has_rdoc: true
|
33
33
|
homepage: https://github.com/Soarez/madmimi_for_rails_two
|
34
34
|
licenses: []
|