sendgrid-rails23 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.textile +117 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/sendgrid.rb +227 -0
- data/sendgrid.gemspec +16 -0
- data/test/sendgrid_test.rb +24 -0
- data/test/test_helper.rb +55 -0
- metadata +79 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Stephen Blankenship
|
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.textile
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
h1. sendgrid
|
2
|
+
|
3
|
+
h3. About this fork
|
4
|
+
|
5
|
+
This fork improves the sendgrid gem by adding a gemspec for Bundler compatibility (via "Ryan Bigg":http://github.com/radar). This fork is expected
|
6
|
+
to work on Rails 2.3.
|
7
|
+
|
8
|
+
h3. What is SendGrid?
|
9
|
+
|
10
|
+
SendGrid is an awesome way to send large amounts of email (bells and whistles included) without spending large amounts of money. This gem allows for painless integration between ActionMailer and the SendGrid SMTP API. The current scope of this gem is focused around setting configuration options for outgoing email (essentially, setting categories, filters and the settings that can accompany those filters). SendGrid's service allows for some other cool stuff (such as postback notification of unsubscribes, bounces, etc.), but you'll have to integrate those features on your own.
|
11
|
+
|
12
|
+
Visit "SendGrid":http://sendgrid.com to learn more.
|
13
|
+
|
14
|
+
h3. Getting Started
|
15
|
+
|
16
|
+
First of all, you'll need the gem. Add sendgrid to Gemfile:
|
17
|
+
|
18
|
+
@gem 'sendgrid', :git => 'git://github.com/jeremyw/sendgrid.git'@
|
19
|
+
|
20
|
+
Then run @bundle install@.
|
21
|
+
|
22
|
+
Before you can do anything with the sendgrid gem, you'll need to create your very own SendGrid account. Go ahead and do so at "http://sendgrid.com":http://sendgrid.com (there's even a FREE account option).
|
23
|
+
|
24
|
+
Next, update your application's SMTP settings to use SendGrid's servers (see "SendGrid's getting started guide":http://wiki.sendgrid.com/doku.php?id=get_started for instructions).
|
25
|
+
|
26
|
+
Example:
|
27
|
+
|
28
|
+
ActionMailer::Base.smtp_settings = {
|
29
|
+
:address => "smtp.sendgrid.net",
|
30
|
+
:port => 25,
|
31
|
+
:domain => "mysite.com",
|
32
|
+
:authentication => :plain,
|
33
|
+
:user_name => "sendgrid_username@mysite.com",
|
34
|
+
:password => "sendgrid_password"
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
h3. Using the sendgrid Gem
|
39
|
+
|
40
|
+
If you do not already have an ActionMailer class up and running, then check out "this guide.":http://guides.rubyonrails.org/action_mailer_basics.html#walkthrough-to-generating-a-mailer
|
41
|
+
|
42
|
+
1) add the following line within your mailer class:
|
43
|
+
|
44
|
+
@include SendGrid@
|
45
|
+
|
46
|
+
2) customize your sendgrid settings:
|
47
|
+
|
48
|
+
There are 2 types of settings
|
49
|
+
|
50
|
+
* Category settings
|
51
|
+
* Enable/disable settings
|
52
|
+
|
53
|
+
You can set both global and per-email settings -- the same syntax is used in either case. Here is an example of what typical usage may look like:
|
54
|
+
|
55
|
+
<pre>
|
56
|
+
class MyMailer < ActionMailer::Base
|
57
|
+
include SendGrid
|
58
|
+
sendgrid_category :use_subject_lines
|
59
|
+
sendgrid_enable :ganalytics, :opentracking
|
60
|
+
|
61
|
+
def welcome_message(to_user)
|
62
|
+
sendgrid_category "Welcome"
|
63
|
+
|
64
|
+
recipients to_user.email
|
65
|
+
subject "Welcome :-)"
|
66
|
+
body :to_user => to_user
|
67
|
+
end
|
68
|
+
|
69
|
+
def goodbye_message(to_user)
|
70
|
+
sendgrid_disable :ganalytics
|
71
|
+
|
72
|
+
recipients to_user.email
|
73
|
+
subject "Fare thee well :-("
|
74
|
+
body :to_user => to_user
|
75
|
+
end
|
76
|
+
end
|
77
|
+
</pre>
|
78
|
+
|
79
|
+
Category settings can be any text you like and will allow you to view statistics per-category (very nice). There is also a custom global setting that will automatically use the subject-line of your email as the sendgrid_category:
|
80
|
+
|
81
|
+
@sendgrid_category :use_subject_lines@
|
82
|
+
|
83
|
+
Calling @sendgrid_cateogry@ from within one of your mailer methods will override this global setting. Similarly, calling @sendgrid_enable@/@sendgrid_disable@ from within a mailer method will add or remove from any defaults that may have been set globally.
|
84
|
+
|
85
|
+
Here are a list of supported options for @sendgrid_enable@ and @sendgrid_disable@:
|
86
|
+
|
87
|
+
* :opentrack
|
88
|
+
* :clicktrack
|
89
|
+
* :ganalytics
|
90
|
+
* :gravatar
|
91
|
+
* :subscriptiontrack
|
92
|
+
** Call sendgrid_subscriptiontrack_text(:html => 'Unsubscribe <% Here %>', :plain => 'Unsubscribe Here: <% %>') to set a custom format for html/plain or both.
|
93
|
+
** OR Call sendgrid_subscriptiontrack_text(:replace => '.unsubscribe_link.') to replace all occurrences of .unsubscribe_link. with the url of the unsubscribe link
|
94
|
+
* :footer
|
95
|
+
** Call sendgrid_footer_text(:html => 'My HTML footer rocks!', :plain => 'My plain text footer is so-so.') to set custom footer text for html/plain or both.
|
96
|
+
* :spamcheck
|
97
|
+
** Call sendgrid_spamcheck_maxscore(4.5) to set a custom SpamAssassin threshold at which SendGrid drops emails (default value is 5.0).
|
98
|
+
|
99
|
+
For further explanation see "SendGrid's wiki page on filters.":http://wiki.sendgrid.com/doku.php?id=filters
|
100
|
+
|
101
|
+
h3. Delivering to multiple recipients
|
102
|
+
|
103
|
+
There is a per-mailer-method setting that can be used to deliver campaigns to multiple recipients at once. You should still set the "recipients" to an address per the normal ActionMailer usage, but it will not be used.
|
104
|
+
|
105
|
+
@sendgrid_recipients ["email1@blah.com", "email2@blah.com", "email2@blah.com", ...]@
|
106
|
+
|
107
|
+
One issue that arises when delivering multiple emails at once is custom content. Luckily, there is also a per-mailer-method setting that can be used to substitute custom content.
|
108
|
+
|
109
|
+
@sendgrid_substitue "<subme>", ["sub text for 1st recipient", "sub text for 2nd recipient", "sub text for 3rd recipient", ...]@
|
110
|
+
|
111
|
+
In this example, if <code><subme></code> is in the body of your email SendGrid will automatically substitute it for the string corresponding the recipient being delivered to. NOTE: You should ensure that the length of the substitution array is equal to the length of the recipients array.
|
112
|
+
|
113
|
+
h3. TODO
|
114
|
+
|
115
|
+
* Test coverage (I would appreciate help writing tests).
|
116
|
+
* Possibly integrate with SendGrid's Event API and some of the other goodies they provide.
|
117
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sendgrid"
|
8
|
+
gem.summary = %Q{A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)}
|
9
|
+
gem.description = %Q{This gem allows simple integration between ActionMailer and SendGrid.
|
10
|
+
SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.}
|
11
|
+
gem.email = "stephenrb@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/stephenb/sendgrid"
|
13
|
+
gem.authors = ["Stephen Blankenship"]
|
14
|
+
# gem.add_development_dependency "thoughtbot-shoulda"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/*_test.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/*_test.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
if File.exist?('VERSION')
|
49
|
+
version = File.read('VERSION')
|
50
|
+
else
|
51
|
+
version = ""
|
52
|
+
end
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "sendgrid #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
data/lib/sendgrid.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module SendGrid
|
4
|
+
|
5
|
+
VALID_OPTIONS = [
|
6
|
+
:opentrack,
|
7
|
+
:clicktrack,
|
8
|
+
:ganalytics,
|
9
|
+
:gravatar,
|
10
|
+
:subscriptiontrack,
|
11
|
+
:footer,
|
12
|
+
:spamcheck,
|
13
|
+
:bypass_list_management
|
14
|
+
]
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.class_eval do
|
18
|
+
class << self
|
19
|
+
attr_accessor :default_sg_category, :default_sg_options, :default_subscriptiontrack_text,
|
20
|
+
:default_footer_text, :default_spamcheck_score
|
21
|
+
end
|
22
|
+
attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions, :subscriptiontrack_text, :footer_text, :spamcheck_score
|
23
|
+
end
|
24
|
+
base.extend(ClassMethods)
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
|
29
|
+
# Sets a default category for all emails.
|
30
|
+
# :use_subject_lines has special behavior that uses the subject-line of
|
31
|
+
# each outgoing email for the SendGrid category. This special behavior
|
32
|
+
# can still be overridden by calling sendgrid_category from within a
|
33
|
+
# mailer method.
|
34
|
+
def sendgrid_category(category)
|
35
|
+
self.default_sg_category = category
|
36
|
+
end
|
37
|
+
|
38
|
+
# Enables a default option for all emails.
|
39
|
+
# See documentation for details.
|
40
|
+
#
|
41
|
+
# Supported options:
|
42
|
+
# * :opentrack
|
43
|
+
# * :clicktrack
|
44
|
+
# * :ganalytics
|
45
|
+
# * :gravatar
|
46
|
+
# * :subscriptiontrack
|
47
|
+
# * :footer
|
48
|
+
# * :spamcheck
|
49
|
+
def sendgrid_enable(*options)
|
50
|
+
self.default_sg_options = Array.new unless self.default_sg_options
|
51
|
+
options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) }
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets the default text for subscription tracking (must be enabled).
|
55
|
+
# There are two options:
|
56
|
+
# 1. Add an unsubscribe link at the bottom of the email
|
57
|
+
# {:html => "Unsubscribe <% here %>", :plain => "Unsubscribe here: <% %>"}
|
58
|
+
# 2. Replace given text with the unsubscribe link
|
59
|
+
# {:replace => "<unsubscribe_link>" }
|
60
|
+
def sendgrid_subscriptiontrack_text(texts)
|
61
|
+
self.default_subscriptiontrack_text = texts
|
62
|
+
end
|
63
|
+
|
64
|
+
# Sets the default footer text (must be enabled).
|
65
|
+
# Should be a hash containing the html/plain text versions:
|
66
|
+
# {:html => "html version", :plain => "plan text version"}
|
67
|
+
def sendgrid_footer_text(texts)
|
68
|
+
self.default_footer_text = texts
|
69
|
+
end
|
70
|
+
|
71
|
+
# Sets the default spamcheck score text (must be enabled).
|
72
|
+
def sendgrid_spamcheck_maxscore(score)
|
73
|
+
self.default_spamcheck_score = score
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Call within mailer method to override the default value.
|
78
|
+
def sendgrid_category(category)
|
79
|
+
@sg_category = category
|
80
|
+
end
|
81
|
+
|
82
|
+
# Call within mailer method to add an option not in the defaults.
|
83
|
+
def sendgrid_enable(*options)
|
84
|
+
@sg_options = Array.new unless @sg_options
|
85
|
+
options.each { |option| @sg_options << option if VALID_OPTIONS.include?(option) }
|
86
|
+
end
|
87
|
+
|
88
|
+
# Call within mailer method to remove one of the defaults.
|
89
|
+
def sendgrid_disable(*options)
|
90
|
+
@sg_disabled_options = Array.new unless @sg_disabled_options
|
91
|
+
options.each { |option| @sg_disabled_options << option if VALID_OPTIONS.include?(option) }
|
92
|
+
end
|
93
|
+
|
94
|
+
# Call within mailer method to add an array of recipients
|
95
|
+
def sendgrid_recipients(emails)
|
96
|
+
@sg_recipients = Array.new unless @sg_recipients
|
97
|
+
@sg_recipients = emails
|
98
|
+
end
|
99
|
+
|
100
|
+
# Call within mailer method to add an array of substitions
|
101
|
+
# NOTE: you must ensure that the length of the substitions equals the
|
102
|
+
# length of the sendgrid_recipients.
|
103
|
+
def sendgrid_substitute(placeholder, subs)
|
104
|
+
@sg_substitutions = Hash.new unless @sg_substitutions
|
105
|
+
@sg_substitutions[placeholder] = subs
|
106
|
+
end
|
107
|
+
|
108
|
+
# Call within mailer method to override the default value.
|
109
|
+
def sendgrid_subscriptiontrack_text(texts)
|
110
|
+
@subscriptiontrack_text = texts
|
111
|
+
end
|
112
|
+
|
113
|
+
# Call within mailer method to override the default value.
|
114
|
+
def sendgrid_footer_text(texts)
|
115
|
+
@footer_text = texts
|
116
|
+
end
|
117
|
+
|
118
|
+
# Call within mailer method to override the default value.
|
119
|
+
def sendgrid_spamcheck_maxscore(score)
|
120
|
+
@spamcheck_score = score
|
121
|
+
end
|
122
|
+
|
123
|
+
# Sets the custom X-SMTPAPI header after creating the email but before delivery
|
124
|
+
def create!(method_name, *parameters)
|
125
|
+
super
|
126
|
+
if @sg_substitutions && !@sg_substitutions.empty?
|
127
|
+
@sg_substitutions.each do |find, replace|
|
128
|
+
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
|
129
|
+
end
|
130
|
+
end
|
131
|
+
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
|
132
|
+
@mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
# Take all of the options and turn it into the json format that SendGrid expects
|
138
|
+
def sendgrid_json_headers(mail)
|
139
|
+
header_opts = {}
|
140
|
+
|
141
|
+
# Set category
|
142
|
+
if @sg_category && @sg_category == :use_subject_lines
|
143
|
+
header_opts[:category] = mail.subject
|
144
|
+
elsif @sg_category
|
145
|
+
header_opts[:category] = @sg_category
|
146
|
+
elsif self.class.default_sg_category && self.class.default_sg_category.to_sym == :use_subject_lines
|
147
|
+
header_opts[:category] = mail.subject
|
148
|
+
elsif self.class.default_sg_category
|
149
|
+
header_opts[:category] = self.class.default_sg_category
|
150
|
+
end
|
151
|
+
|
152
|
+
# Set multi-recipients
|
153
|
+
if @sg_recipients && !@sg_recipients.empty?
|
154
|
+
header_opts[:to] = @sg_recipients
|
155
|
+
end
|
156
|
+
|
157
|
+
# Set custom substitions
|
158
|
+
if @sg_substitutions && !@sg_substitutions.empty?
|
159
|
+
header_opts[:sub] = @sg_substitutions
|
160
|
+
end
|
161
|
+
|
162
|
+
# Set enables/disables
|
163
|
+
header_opts[:filters] = {} unless header_opts.has_key?(:filters)
|
164
|
+
enabled_opts = []
|
165
|
+
if @sg_options && !@sg_options.empty?
|
166
|
+
# merge the options so that the instance-level "overrides"
|
167
|
+
merged = self.class.default_sg_options || []
|
168
|
+
merged += @sg_options
|
169
|
+
enabled_opts = merged
|
170
|
+
elsif self.class.default_sg_options
|
171
|
+
enabled_opts = self.class.default_sg_options
|
172
|
+
end
|
173
|
+
if !enabled_opts.empty? || (@sg_disabled_options && !@sg_disabled_options.empty?)
|
174
|
+
header_opts[:filters] = filters_hash_from_options(enabled_opts, @sg_disabled_options)
|
175
|
+
end
|
176
|
+
|
177
|
+
header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
|
178
|
+
end
|
179
|
+
|
180
|
+
def filters_hash_from_options(enabled_opts, disabled_opts)
|
181
|
+
filters = {}
|
182
|
+
enabled_opts.each do |opt|
|
183
|
+
filters[opt] = {'settings' => {'enable' => 1}}
|
184
|
+
case opt.to_sym
|
185
|
+
when :subscriptiontrack
|
186
|
+
if @subscriptiontrack_text
|
187
|
+
if @subscriptiontrack_text[:replace]
|
188
|
+
filters[:subscriptiontrack]['settings']['replace'] = @subscriptiontrack_text[:replace]
|
189
|
+
else
|
190
|
+
filters[:subscriptiontrack]['settings']['text/html'] = @subscriptiontrack_text[:html]
|
191
|
+
filters[:subscriptiontrack]['settings']['text/plain'] = @subscriptiontrack_text[:plain]
|
192
|
+
end
|
193
|
+
elsif self.class.default_subscriptiontrack_text
|
194
|
+
if self.class.default_subscriptiontrack_text[:replace]
|
195
|
+
filters[:subscriptiontrack]['settings']['replace'] = self.class.default_subscriptiontrack_text[:replace]
|
196
|
+
else
|
197
|
+
filters[:subscriptiontrack]['settings']['text/html'] = self.class.default_subscriptiontrack_text[:html]
|
198
|
+
filters[:subscriptiontrack]['settings']['text/plain'] = self.class.default_subscriptiontrack_text[:plain]
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
when :footer
|
203
|
+
if @footer_text
|
204
|
+
filters[:footer]['settings']['text/html'] = @footer_text[:html]
|
205
|
+
filters[:footer]['settings']['text/plain'] = @footer_text[:plain]
|
206
|
+
elsif self.class.default_footer_text
|
207
|
+
filters[:footer]['settings']['text/html'] = self.class.default_footer_text[:html]
|
208
|
+
filters[:footer]['settings']['text/plain'] = self.class.default_footer_text[:plain]
|
209
|
+
end
|
210
|
+
|
211
|
+
when :spamcheck
|
212
|
+
if self.class.default_spamcheck_score || @spamcheck_score
|
213
|
+
filters[:spamcheck]['settings']['maxscore'] = @spamcheck_score || self.class.default_spamcheck_score
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
if disabled_opts
|
219
|
+
disabled_opts.each do |opt|
|
220
|
+
filters[opt] = {'settings' => {'enable' => 0}}
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
return filters
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
data/sendgrid.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "sendgrid-rails23"
|
3
|
+
s.version = "0.1.4"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = []
|
6
|
+
s.email = []
|
7
|
+
s.homepage = "http://github.com/jeremyw/sendgrid"
|
8
|
+
s.summary = "Adds ActionMailer settings to easily integrate with SendGrid."
|
9
|
+
s.description = "Adds ActionMailer settings to easily integrate with SendGrid."
|
10
|
+
|
11
|
+
s.required_rubygems_version = ">= 1.3.6"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
15
|
+
s.require_path = 'lib'
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SendgridTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@options = {
|
6
|
+
:to => ['test@example.com'],
|
7
|
+
:from => 'test@example.com',
|
8
|
+
:reply_to => 'reply-to@example.com',
|
9
|
+
:subject => 'The Subject',
|
10
|
+
:html_content => '<html>content</html>',
|
11
|
+
:category => 'MyCategory',
|
12
|
+
:substitutions => {
|
13
|
+
'first_name' => ['Joe'],
|
14
|
+
'last_name' => ['Schmoe', 'Cool']
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
should "require the same number of items in a substitution array as is in the recipient array" do
|
20
|
+
assert_raise ArgumentError do
|
21
|
+
test_email = SendgridCampaignTestMailer.create_test(@options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'sendgrid'
|
8
|
+
require 'action_mailer'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
end
|
12
|
+
|
13
|
+
class SendgridCampaignTestMailer < ActionMailer::Base
|
14
|
+
include SendGrid
|
15
|
+
|
16
|
+
sendgrid_enable :opentrack, :clicktrack, :subscriptiontrack, :bypass_list_management
|
17
|
+
|
18
|
+
REQUIRED_OPTIONS = [:to, :from, :category, :html_content, :subject]
|
19
|
+
|
20
|
+
##
|
21
|
+
# options are:
|
22
|
+
# :from the from address
|
23
|
+
# :to an array of recipients
|
24
|
+
# :substitutions a hash of substitutions of the form: 'text to be
|
25
|
+
# replaced' => [replacements]. The order and size of the replacement
|
26
|
+
# array must match the :to array
|
27
|
+
# :category the sendgrid category used for tracking
|
28
|
+
# :html_content, :text_content, :subject
|
29
|
+
def test(options)
|
30
|
+
handle_sendgrid_options(options)
|
31
|
+
recipients(options[:to])
|
32
|
+
from(options[:from])
|
33
|
+
reply_to(options[:reply_to])
|
34
|
+
subject(options[:subject])
|
35
|
+
body(options[:html_content])
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def handle_sendgrid_options(options)
|
40
|
+
REQUIRED_OPTIONS.each do |option|
|
41
|
+
raise ArgumentError.new("Required sendgrid option ':#{option}' missing") unless options[option]
|
42
|
+
end
|
43
|
+
|
44
|
+
sendgrid_recipients(options[:to])
|
45
|
+
|
46
|
+
if options[:substitutions]
|
47
|
+
options[:substitutions].each do |find, replace|
|
48
|
+
sendgrid_substitute(find, replace)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
sendgrid_category(options[:category])
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendgrid-rails23
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
|
+
platform: ruby
|
12
|
+
authors: []
|
13
|
+
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-01 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Adds ActionMailer settings to easily integrate with SendGrid.
|
23
|
+
email: []
|
24
|
+
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
35
|
+
- README.textile
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- lib/sendgrid.rb
|
39
|
+
- sendgrid.gemspec
|
40
|
+
- test/sendgrid_test.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/jeremyw/sendgrid
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 23
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 3
|
69
|
+
- 6
|
70
|
+
version: 1.3.6
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.7
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Adds ActionMailer settings to easily integrate with SendGrid.
|
78
|
+
test_files: []
|
79
|
+
|