sendgrid-enphase 1.1.0

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "json"
4
+
5
+ # Add dependencies required to use your gem here.
6
+ # Example:
7
+ # gem "activesupport", ">= 2.3.5"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ # gem "shoulda", ">= 0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.5.1"
15
+ # gem "rcov", ">= 0"
16
+ end
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.5.1)
10
+ rake (0.8.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.5.1)
18
+ json
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.
@@ -0,0 +1,120 @@
1
+ sendgrid
2
+ =========
3
+
4
+ _Now updated to work with Rails 3._
5
+
6
+ What is SendGrid?
7
+ -----------------
8
+
9
+ SendGrid is an awesome service that helps you 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 those features are currently outside the scope of this gem.
10
+
11
+ Visit [SendGrid](http://sendgrid.com) to learn more.
12
+
13
+ Getting Started
14
+ ---------------
15
+
16
+ First of all, you'll need the gem. It's at http://rubygems.org/gems/sendgrid. If you're using Bundler, just add the following to your Gemfile.
17
+
18
+ gem 'sendgrid'
19
+
20
+
21
+ 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).
22
+
23
+ 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).
24
+
25
+ Example:
26
+
27
+ ActionMailer::Base.smtp_settings = {
28
+ :address => "smtp.sendgrid.net",
29
+ :port => 25,
30
+ :domain => "mysite.com",
31
+ :authentication => :plain,
32
+ :user_name => "sendgrd_username@mysite.com",
33
+ :password => "sendgrid_password"
34
+ }
35
+
36
+ Using the sendgrid Gem
37
+ ----------------------
38
+
39
+ 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)
40
+
41
+ 1) add the following line within your mailer class:
42
+
43
+ include SendGrid
44
+
45
+
46
+ 2) customize your sendgrid settings:
47
+
48
+ There are 2 main 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.
54
+ Here is an example of what typical usage may look like:
55
+
56
+ class MyMailer < ActionMailer::Base
57
+ include SendGrid
58
+ sendgrid_category :use_subject_lines
59
+ sendgrid_enable :ganalytics, :opentrack
60
+
61
+ def welcome_message(user)
62
+ sendgrid_category "Welcome"
63
+ mail :to => user.email, :subject => "Welcome #{user.name} :-)"
64
+ end
65
+
66
+ def goodbye_message(user)
67
+ sendgrid_disable :ganalytics
68
+ mail :to => user.email, :subject => "Fare thee well :-("
69
+ end
70
+ end
71
+
72
+ Category settings can be any text you like and SendGrid's website will allow you to view email statistics per-category (very nice). There is also a custom global setting that will automatically use the subject line of each email as the sendgrid\_category:
73
+
74
+ sendgrid_category :use_subject_lines
75
+
76
+ If you have any dynamic subject lines, you'll want to override this setting within the mailer method. Calling sendgrid\_category 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.
77
+
78
+ Here are a list of supported options for sendgrid\_enable and sendgrid\_disable:
79
+
80
+ * :opentrack
81
+ * :clicktrack
82
+ * :ganalytics
83
+ * :gravatar
84
+ * :subscriptiontrack
85
+ * Call sendgrid\_subscriptiontrack\_text(:html => 'Unsubscribe <% Here %>', :plain => 'Unsubscribe Here: <% %>') to set a custom format for html/plain or both.
86
+ * OR Call sendgrid\_subscriptiontrack\_text(:replace => '|unsubscribe\_link|') to replace all occurrences of |unsubscribe\_link| with the url of the unsubscribe link
87
+ * :footer
88
+ * 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.
89
+ * :spamcheck
90
+ * Call sendgrid\_spamcheck\_maxscore(4.5) to set a custom SpamAssassin threshold at which SendGrid drops emails (default value is 5.0).
91
+
92
+ For further explanation see [SendGrid's wiki page on filters.](http://wiki.sendgrid.com/doku.php?id=filters)
93
+
94
+
95
+ Delivering to multiple recipients
96
+ ---------------------------------
97
+
98
+ There is a per-mailer-method setting that can be used to deliver campaigns to multiple (many) recipients in a single delivery/SMTP call.
99
+ It is quite easy to build a robust mass-delivery system utilizing this feature, and it is quite difficult to deliver a large email campaign quickly without this feature.
100
+ Note: While it may be worth asking yourself, a SendGrid engineer told me it's best to keep the number of recipients to <= 1,000 per delivery.
101
+
102
+
103
+ sendgrid_recipients ["email1@blah.com", "email2@blah.com", "email3@blah.com", ...]
104
+
105
+
106
+ 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.
107
+
108
+
109
+ sendgrid_substitute "|subme|", ["sub text for 1st recipient", "sub text for 2nd recipient", "sub text for 3rd recipient", ...]
110
+
111
+
112
+ 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.
113
+
114
+
115
+ TODO
116
+ ----
117
+
118
+ * Test coverage (I would appreciate help writing tests).
119
+ * Possibly integrate with SendGrid's Event API and some of the other goodies they provide.
120
+
@@ -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-enphase"
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_dependency "json"
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
+ 1.1.0
@@ -0,0 +1,274 @@
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
+
25
+ # NOTE: This commented-out approach may be a "safer" option for Rails 3, but it
26
+ # would cause the headers to get set during delivery, and not when the message is initialized.
27
+ # If base supports register_interceptor (i.e., Rails 3 ActionMailer), use it...
28
+ # if base.respond_to?(:register_interceptor)
29
+ # base.register_interceptor(SendgridInterceptor)
30
+ # end
31
+
32
+ base.extend(ClassMethods)
33
+ end
34
+
35
+ module ClassMethods
36
+
37
+ # Sets a default category for all emails.
38
+ # :use_subject_lines has special behavior that uses the subject-line of
39
+ # each outgoing email for the SendGrid category. This special behavior
40
+ # can still be overridden by calling sendgrid_category from within a
41
+ # mailer method.
42
+ def sendgrid_category(category)
43
+ if category.length > 0 && (!self.default_sg_category || self.default_sg_category.length < 1)
44
+ self.default_sg_category = []
45
+ end
46
+ self.default_sg_category.push(category)
47
+ end
48
+
49
+ # Enables a default option for all emails.
50
+ # See documentation for details.
51
+ #
52
+ # Supported options:
53
+ # * :opentrack
54
+ # * :clicktrack
55
+ # * :ganalytics
56
+ # * :gravatar
57
+ # * :subscriptiontrack
58
+ # * :footer
59
+ # * :spamcheck
60
+ def sendgrid_enable(*options)
61
+ self.default_sg_options = Array.new unless self.default_sg_options
62
+ options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) }
63
+ end
64
+
65
+ # Sets the default text for subscription tracking (must be enabled).
66
+ # There are two options:
67
+ # 1. Add an unsubscribe link at the bottom of the email
68
+ # {:html => "Unsubscribe <% here %>", :plain => "Unsubscribe here: <% %>"}
69
+ # 2. Replace given text with the unsubscribe link
70
+ # {:replace => "<unsubscribe_link>" }
71
+ def sendgrid_subscriptiontrack_text(texts)
72
+ self.default_subscriptiontrack_text = texts
73
+ end
74
+
75
+ # Sets the default footer text (must be enabled).
76
+ # Should be a hash containing the html/plain text versions:
77
+ # {:html => "html version", :plain => "plan text version"}
78
+ def sendgrid_footer_text(texts)
79
+ self.default_footer_text = texts
80
+ end
81
+
82
+ # Sets the default spamcheck score text (must be enabled).
83
+ def sendgrid_spamcheck_maxscore(score)
84
+ self.default_spamcheck_score = score
85
+ end
86
+ end
87
+
88
+ # Call within mailer method to override the default value.
89
+ def sendgrid_category(category)
90
+ if category.length > 0 && (!@sg_category || @sg_category.length < 1)
91
+ @sg_category = []
92
+ end
93
+ @sg_category.push(category)
94
+ end
95
+
96
+ # Call within mailer method to add an option not in the defaults.
97
+ def sendgrid_enable(*options)
98
+ @sg_options = Array.new unless @sg_options
99
+ options.each { |option| @sg_options << option if VALID_OPTIONS.include?(option) }
100
+ end
101
+
102
+ # Call within mailer method to remove one of the defaults.
103
+ def sendgrid_disable(*options)
104
+ @sg_disabled_options = Array.new unless @sg_disabled_options
105
+ options.each { |option| @sg_disabled_options << option if VALID_OPTIONS.include?(option) }
106
+ end
107
+
108
+ # Call within mailer method to add an array of recipients
109
+ def sendgrid_recipients(emails)
110
+ @sg_recipients = Array.new unless @sg_recipients
111
+ @sg_recipients = emails
112
+ end
113
+
114
+ # Call within mailer method to add an array of substitions
115
+ # NOTE: you must ensure that the length of the substitions equals the
116
+ # length of the sendgrid_recipients.
117
+ def sendgrid_substitute(placeholder, subs)
118
+ @sg_substitutions = Hash.new unless @sg_substitutions
119
+ @sg_substitutions[placeholder] = subs
120
+ end
121
+
122
+ # Call within mailer method to override the default value.
123
+ def sendgrid_subscriptiontrack_text(texts)
124
+ @subscriptiontrack_text = texts
125
+ end
126
+
127
+ # Call within mailer method to override the default value.
128
+ def sendgrid_footer_text(texts)
129
+ @footer_text = texts
130
+ end
131
+
132
+ # Call within mailer method to override the default value.
133
+ def sendgrid_spamcheck_maxscore(score)
134
+ @spamcheck_score = score
135
+ end
136
+
137
+ # Call within mailer method to set unique args for this email.
138
+ def sendgrid_unique_args(args)
139
+ @sg_unique_args = args
140
+ end
141
+
142
+ # only override the appropriate methods for the current ActionMailer version
143
+ if ActionMailer::Base.respond_to?(:mail)
144
+
145
+ protected
146
+
147
+ # Sets the custom X-SMTPAPI header after creating the email but before delivery
148
+ # NOTE: This override is used for Rails 3 ActionMailer classes.
149
+ def mail(headers={}, &block)
150
+ super
151
+ if @sg_substitutions && !@sg_substitutions.empty?
152
+ @sg_substitutions.each do |find, replace|
153
+ raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
154
+ end
155
+ end
156
+ puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
157
+ self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
158
+ end
159
+
160
+ else
161
+
162
+ # Sets the custom X-SMTPAPI header after creating the email but before delivery
163
+ # NOTE: This override is used for Rails 2 ActionMailer classes.
164
+ def create!(method_name, *parameters)
165
+ super
166
+ if @sg_substitutions && !@sg_substitutions.empty?
167
+ @sg_substitutions.each do |find, replace|
168
+ raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
169
+ end
170
+ end
171
+ puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
172
+ @mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
173
+ end
174
+
175
+ end
176
+
177
+ private
178
+
179
+ # Take all of the options and turn it into the json format that SendGrid expects
180
+ def sendgrid_json_headers(mail)
181
+ header_opts = {}
182
+
183
+ # Set category
184
+ if @sg_category && @sg_category == :use_subject_lines
185
+ header_opts[:category] = mail.subject
186
+ elsif @sg_category
187
+ header_opts[:category] = @sg_category + self.class.default_sg_category
188
+ elsif self.class.default_sg_category && self.class.default_sg_category.to_sym == :use_subject_lines
189
+ header_opts[:category] = mail.subject
190
+ elsif self.class.default_sg_category
191
+ header_opts[:category] = self.class.default_sg_category
192
+ end
193
+
194
+ # Set multi-recipients
195
+ if @sg_recipients && !@sg_recipients.empty?
196
+ header_opts[:to] = @sg_recipients
197
+ end
198
+
199
+ # Set custom substitions
200
+ if @sg_substitutions && !@sg_substitutions.empty?
201
+ header_opts[:sub] = @sg_substitutions
202
+ end
203
+
204
+ # Set enables/disables
205
+ header_opts[:filters] = {} unless header_opts.has_key?(:filters)
206
+ enabled_opts = []
207
+ if @sg_options && !@sg_options.empty?
208
+ # merge the options so that the instance-level "overrides"
209
+ merged = self.class.default_sg_options || []
210
+ merged += @sg_options
211
+ enabled_opts = merged
212
+ elsif self.class.default_sg_options
213
+ enabled_opts = self.class.default_sg_options
214
+ end
215
+ if !enabled_opts.empty? || (@sg_disabled_options && !@sg_disabled_options.empty?)
216
+ header_opts[:filters] = filters_hash_from_options(enabled_opts, @sg_disabled_options)
217
+ end
218
+
219
+ # Set unique_args
220
+ if @sg_unique_args && !@sg_unique_args.empty?
221
+ header_opts[:unique_args] = @sg_unique_args
222
+ end
223
+
224
+ header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
225
+ end
226
+
227
+ def filters_hash_from_options(enabled_opts, disabled_opts)
228
+ filters = {}
229
+ enabled_opts.each do |opt|
230
+ filters[opt] = {'settings' => {'enable' => 1}}
231
+ case opt.to_sym
232
+ when :subscriptiontrack
233
+ if @subscriptiontrack_text
234
+ if @subscriptiontrack_text[:replace]
235
+ filters[:subscriptiontrack]['settings']['replace'] = @subscriptiontrack_text[:replace]
236
+ else
237
+ filters[:subscriptiontrack]['settings']['text/html'] = @subscriptiontrack_text[:html]
238
+ filters[:subscriptiontrack]['settings']['text/plain'] = @subscriptiontrack_text[:plain]
239
+ end
240
+ elsif self.class.default_subscriptiontrack_text
241
+ if self.class.default_subscriptiontrack_text[:replace]
242
+ filters[:subscriptiontrack]['settings']['replace'] = self.class.default_subscriptiontrack_text[:replace]
243
+ else
244
+ filters[:subscriptiontrack]['settings']['text/html'] = self.class.default_subscriptiontrack_text[:html]
245
+ filters[:subscriptiontrack]['settings']['text/plain'] = self.class.default_subscriptiontrack_text[:plain]
246
+ end
247
+ end
248
+
249
+ when :footer
250
+ if @footer_text
251
+ filters[:footer]['settings']['text/html'] = @footer_text[:html]
252
+ filters[:footer]['settings']['text/plain'] = @footer_text[:plain]
253
+ elsif self.class.default_footer_text
254
+ filters[:footer]['settings']['text/html'] = self.class.default_footer_text[:html]
255
+ filters[:footer]['settings']['text/plain'] = self.class.default_footer_text[:plain]
256
+ end
257
+
258
+ when :spamcheck
259
+ if self.class.default_spamcheck_score || @spamcheck_score
260
+ filters[:spamcheck]['settings']['maxscore'] = @spamcheck_score || self.class.default_spamcheck_score
261
+ end
262
+ end
263
+ end
264
+
265
+ if disabled_opts
266
+ disabled_opts.each do |opt|
267
+ filters[opt] = {'settings' => {'enable' => 0}}
268
+ end
269
+ end
270
+
271
+ return filters
272
+ end
273
+
274
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sendgrid-enphase"
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stephen Blankenship"]
12
+ s.date = "2012-06-25"
13
+ s.description = "This gem allows simple integration between ActionMailer and SendGrid. \n SendGrid is an email deliverability API that is affordable and has lots of bells and whistles."
14
+ s.email = "stephenrb@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/sendgrid.rb",
28
+ "sendgrid-enphase.gemspec",
29
+ "test/sendgrid_test.rb",
30
+ "test/test_helper.rb"
31
+ ]
32
+ s.homepage = "http://github.com/stephenb/sendgrid"
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.11"
35
+ s.summary = "A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)"
36
+ s.test_files = [
37
+ "test/sendgrid_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<json>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
48
+ s.add_runtime_dependency(%q<json>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<json>, [">= 0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
53
+ s.add_dependency(%q<json>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<json>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
59
+ s.add_dependency(%q<json>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -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
@@ -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,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendgrid-enphase
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Stephen Blankenship
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ requirement: *id001
31
+ prerelease: false
32
+ name: json
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ hash: 23
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 0
45
+ version: 1.0.0
46
+ requirement: *id002
47
+ prerelease: false
48
+ name: bundler
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 1
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 1
61
+ version: 1.5.1
62
+ requirement: *id003
63
+ prerelease: false
64
+ name: jeweler
65
+ type: :development
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ prerelease: false
78
+ name: json
79
+ type: :runtime
80
+ description: |-
81
+ This gem allows simple integration between ActionMailer and SendGrid.
82
+ SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.
83
+ email: stephenrb@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.md
91
+ files:
92
+ - .document
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION
99
+ - lib/sendgrid.rb
100
+ - sendgrid-enphase.gemspec
101
+ - test/sendgrid_test.rb
102
+ - test/test_helper.rb
103
+ homepage: http://github.com/stephenb/sendgrid
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options: []
108
+
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.8.11
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)
136
+ test_files:
137
+ - test/sendgrid_test.rb
138
+ - test/test_helper.rb