sendgrid 1.0.1 → 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.
Files changed (6) hide show
  1. data/README.md +11 -4
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/sendgrid.rb +67 -26
  5. data/sendgrid.gemspec +10 -16
  6. metadata +81 -83
data/README.md CHANGED
@@ -57,12 +57,14 @@ Here is an example of what typical usage may look like:
57
57
  include SendGrid
58
58
  sendgrid_category :use_subject_lines
59
59
  sendgrid_enable :ganalytics, :opentrack
60
-
60
+ sendgrid_unique_args :key1 => "value1", :key2 => "value2"
61
+
61
62
  def welcome_message(user)
62
63
  sendgrid_category "Welcome"
64
+ sendgrid_unique_args :key2 => "newvalue2", :key3 => "value3"
63
65
  mail :to => user.email, :subject => "Welcome #{user.name} :-)"
64
66
  end
65
-
67
+
66
68
  def goodbye_message(user)
67
69
  sendgrid_disable :ganalytics
68
70
  mail :to => user.email, :subject => "Fare thee well :-("
@@ -80,6 +82,7 @@ Here are a list of supported options for sendgrid\_enable and sendgrid\_disable:
80
82
  * :opentrack
81
83
  * :clicktrack
82
84
  * :ganalytics
85
+ * Call sendgrid\_ganalytics\_options(:utm_source => 'welcome_email', :utm_medium => 'email', :utm_campaign => 'promo', :utm_term => 'intro+text', :utm_content => 'header_link') to set custom Google Analytics variables.
83
86
  * :gravatar
84
87
  * :subscriptiontrack
85
88
  * Call sendgrid\_subscriptiontrack\_text(:html => 'Unsubscribe <% Here %>', :plain => 'Unsubscribe Here: <% %>') to set a custom format for html/plain or both.
@@ -88,15 +91,19 @@ Here are a list of supported options for sendgrid\_enable and sendgrid\_disable:
88
91
  * 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
92
  * :spamcheck
90
93
  * Call sendgrid\_spamcheck\_maxscore(4.5) to set a custom SpamAssassin threshold at which SendGrid drops emails (default value is 5.0).
91
-
94
+
92
95
  For further explanation see [SendGrid's wiki page on filters.](http://wiki.sendgrid.com/doku.php?id=filters)
93
96
 
97
+ Custom parameters can be set using the sendgrid_unique_args methods. Any key/value pairs defined thusly will
98
+ be included as parameters in SendGrid post backs. These are especially useful in cases where the recipient's
99
+ email address is not unique or when multiple applications/environments are using the same SendGrid account.
100
+
94
101
 
95
102
  Delivering to multiple recipients
96
103
  ---------------------------------
97
104
 
98
105
  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.
106
+ 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
107
  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
108
 
102
109
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.}
11
11
  gem.email = "stephenrb@gmail.com"
12
12
  gem.homepage = "http://github.com/stephenb/sendgrid"
13
- gem.authors = ["Stephen Blankenship"]
13
+ gem.authors = ["Stephen Blankenship", "Marc Tremblay", "Bob Burbach"]
14
14
  gem.add_dependency "json"
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -12,28 +12,37 @@ module SendGrid
12
12
  :spamcheck,
13
13
  :bypass_list_management
14
14
  ]
15
-
15
+
16
+ VALID_GANALYTICS_OPTIONS = [
17
+ :utm_source,
18
+ :utm_medium,
19
+ :utm_campaign,
20
+ :utm_term,
21
+ :utm_content
22
+ ]
23
+
16
24
  def self.included(base)
17
25
  base.class_eval do
18
26
  class << self
19
27
  attr_accessor :default_sg_category, :default_sg_options, :default_subscriptiontrack_text,
20
- :default_footer_text, :default_spamcheck_score
28
+ :default_footer_text, :default_spamcheck_score, :default_sg_unique_args
21
29
  end
22
- attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions, :subscriptiontrack_text, :footer_text, :spamcheck_score
30
+ attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions,
31
+ :subscriptiontrack_text, :footer_text, :spamcheck_score, :sg_unique_args
23
32
  end
24
-
25
- # NOTE: This commented-out approach may be a "safer" option for Rails 3, but it
33
+
34
+ # NOTE: This commented-out approach may be a "safer" option for Rails 3, but it
26
35
  # would cause the headers to get set during delivery, and not when the message is initialized.
27
36
  # If base supports register_interceptor (i.e., Rails 3 ActionMailer), use it...
28
37
  # if base.respond_to?(:register_interceptor)
29
38
  # base.register_interceptor(SendgridInterceptor)
30
39
  # end
31
-
40
+
32
41
  base.extend(ClassMethods)
33
42
  end
34
-
43
+
35
44
  module ClassMethods
36
-
45
+
37
46
  # Sets a default category for all emails.
38
47
  # :use_subject_lines has special behavior that uses the subject-line of
39
48
  # each outgoing email for the SendGrid category. This special behavior
@@ -42,7 +51,7 @@ module SendGrid
42
51
  def sendgrid_category(category)
43
52
  self.default_sg_category = category
44
53
  end
45
-
54
+
46
55
  # Enables a default option for all emails.
47
56
  # See documentation for details.
48
57
  #
@@ -58,19 +67,19 @@ module SendGrid
58
67
  self.default_sg_options = Array.new unless self.default_sg_options
59
68
  options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) }
60
69
  end
61
-
70
+
62
71
  # Sets the default text for subscription tracking (must be enabled).
63
- # There are two options:
64
- # 1. Add an unsubscribe link at the bottom of the email
72
+ # There are two options:
73
+ # 1. Add an unsubscribe link at the bottom of the email
65
74
  # {:html => "Unsubscribe <% here %>", :plain => "Unsubscribe here: <% %>"}
66
75
  # 2. Replace given text with the unsubscribe link
67
76
  # {:replace => "<unsubscribe_link>" }
68
77
  def sendgrid_subscriptiontrack_text(texts)
69
78
  self.default_subscriptiontrack_text = texts
70
79
  end
71
-
80
+
72
81
  # Sets the default footer text (must be enabled).
73
- # Should be a hash containing the html/plain text versions:
82
+ # Should be a hash containing the html/plain text versions:
74
83
  # {:html => "html version", :plain => "plan text version"}
75
84
  def sendgrid_footer_text(texts)
76
85
  self.default_footer_text = texts
@@ -80,6 +89,11 @@ module SendGrid
80
89
  def sendgrid_spamcheck_maxscore(score)
81
90
  self.default_spamcheck_score = score
82
91
  end
92
+
93
+ # Sets the default unique arguments to send
94
+ def sendgrid_unique_args(unique_args = {})
95
+ self.default_sg_unique_args = unique_args
96
+ end
83
97
  end
84
98
 
85
99
  # Call within mailer method to override the default value.
@@ -87,12 +101,17 @@ module SendGrid
87
101
  @sg_category = category
88
102
  end
89
103
 
104
+ # Call within mailer method to add/override unique arguments in the defaults
105
+ def sendgrid_unique_args(unique_args = {})
106
+ @sg_unique_args = unique_args
107
+ end
108
+
90
109
  # Call within mailer method to add an option not in the defaults.
91
110
  def sendgrid_enable(*options)
92
111
  @sg_options = Array.new unless @sg_options
93
112
  options.each { |option| @sg_options << option if VALID_OPTIONS.include?(option) }
94
113
  end
95
-
114
+
96
115
  # Call within mailer method to remove one of the defaults.
97
116
  def sendgrid_disable(*options)
98
117
  @sg_disabled_options = Array.new unless @sg_disabled_options
@@ -104,7 +123,7 @@ module SendGrid
104
123
  @sg_recipients = Array.new unless @sg_recipients
105
124
  @sg_recipients = emails
106
125
  end
107
-
126
+
108
127
  # Call within mailer method to add an array of substitions
109
128
  # NOTE: you must ensure that the length of the substitions equals the
110
129
  # length of the sendgrid_recipients.
@@ -128,6 +147,13 @@ module SendGrid
128
147
  @spamcheck_score = score
129
148
  end
130
149
 
150
+ # Call within mailer method to set custom google analytics options
151
+ # http://sendgrid.com/documentation/appsGoogleAnalytics
152
+ def sendgrid_ganalytics_options(options)
153
+ @ganalytics_options = []
154
+ options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) }
155
+ end
156
+
131
157
  # Call within mailer method to set unique args for this email.
132
158
  def sendgrid_unique_args(args)
133
159
  @sg_unique_args = args
@@ -154,7 +180,7 @@ module SendGrid
154
180
  else
155
181
 
156
182
  # Sets the custom X-SMTPAPI header after creating the email but before delivery
157
- # NOTE: This override is used for Rails 2 ActionMailer classes.
183
+ # NOTE: This override is used for Rails 2 ActionMailer classes.
158
184
  def create!(method_name, *parameters)
159
185
  super
160
186
  if @sg_substitutions && !@sg_substitutions.empty?
@@ -174,6 +200,14 @@ module SendGrid
174
200
  def sendgrid_json_headers(mail)
175
201
  header_opts = {}
176
202
 
203
+ # set the unique arguments
204
+ if @sg_unique_args || self.class.default_sg_unique_args
205
+ unique_args = self.class.default_sg_unique_args || {}
206
+ unique_args = unique_args.merge(@sg_unique_args)
207
+
208
+ header_opts[:unique_args] = unique_args
209
+ end
210
+
177
211
  # Set category
178
212
  if @sg_category && @sg_category == :use_subject_lines
179
213
  header_opts[:category] = mail.subject
@@ -184,12 +218,12 @@ module SendGrid
184
218
  elsif self.class.default_sg_category
185
219
  header_opts[:category] = self.class.default_sg_category
186
220
  end
187
-
221
+
188
222
  # Set multi-recipients
189
223
  if @sg_recipients && !@sg_recipients.empty?
190
224
  header_opts[:to] = @sg_recipients
191
225
  end
192
-
226
+
193
227
  # Set custom substitions
194
228
  if @sg_substitutions && !@sg_substitutions.empty?
195
229
  header_opts[:sub] = @sg_substitutions
@@ -214,10 +248,10 @@ module SendGrid
214
248
  if @sg_unique_args && !@sg_unique_args.empty?
215
249
  header_opts[:unique_args] = @sg_unique_args
216
250
  end
217
-
251
+
218
252
  header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
219
253
  end
220
-
254
+
221
255
  def filters_hash_from_options(enabled_opts, disabled_opts)
222
256
  filters = {}
223
257
  enabled_opts.each do |opt|
@@ -239,7 +273,7 @@ module SendGrid
239
273
  filters[:subscriptiontrack]['settings']['text/plain'] = self.class.default_subscriptiontrack_text[:plain]
240
274
  end
241
275
  end
242
-
276
+
243
277
  when :footer
244
278
  if @footer_text
245
279
  filters[:footer]['settings']['text/html'] = @footer_text[:html]
@@ -248,21 +282,28 @@ module SendGrid
248
282
  filters[:footer]['settings']['text/html'] = self.class.default_footer_text[:html]
249
283
  filters[:footer]['settings']['text/plain'] = self.class.default_footer_text[:plain]
250
284
  end
251
-
285
+
252
286
  when :spamcheck
253
287
  if self.class.default_spamcheck_score || @spamcheck_score
254
288
  filters[:spamcheck]['settings']['maxscore'] = @spamcheck_score || self.class.default_spamcheck_score
255
289
  end
290
+
291
+ when :ganalytics
292
+ if @ganalytics_options
293
+ @ganalytics_options.each do |key, value|
294
+ filters[:ganalytics]['settings'][key.to_s] = value
295
+ end
296
+ end
256
297
  end
257
298
  end
258
-
299
+
259
300
  if disabled_opts
260
301
  disabled_opts.each do |opt|
261
302
  filters[opt] = {'settings' => {'enable' => 0}}
262
303
  end
263
304
  end
264
-
305
+
265
306
  return filters
266
307
  end
267
-
308
+
268
309
  end
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{sendgrid}
8
- s.version = "1.0.1"
7
+ s.name = "sendgrid"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Stephen Blankenship"]
12
- s.date = %q{2011-09-08}
13
- s.description = %q{This gem allows simple integration between ActionMailer and SendGrid.
14
- SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.}
15
- s.email = %q{stephenrb@gmail.com}
11
+ s.authors = ["Stephen Blankenship", "Marc Tremblay", "Bob Burbach"]
12
+ s.date = "2012-10-05"
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"
16
15
  s.extra_rdoc_files = [
17
16
  "LICENSE",
18
17
  "README.md"
@@ -30,20 +29,15 @@ Gem::Specification.new do |s|
30
29
  "test/sendgrid_test.rb",
31
30
  "test/test_helper.rb"
32
31
  ]
33
- s.homepage = %q{http://github.com/stephenb/sendgrid}
32
+ s.homepage = "http://github.com/stephenb/sendgrid"
34
33
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.6}
36
- s.summary = %q{A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)}
37
- s.test_files = [
38
- "test/sendgrid_test.rb",
39
- "test/test_helper.rb"
40
- ]
34
+ s.rubygems_version = "1.8.24"
35
+ s.summary = "A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)"
41
36
 
42
37
  if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
38
  s.specification_version = 3
45
39
 
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
41
  s.add_runtime_dependency(%q<json>, [">= 0"])
48
42
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
43
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
metadata CHANGED
@@ -1,86 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sendgrid
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 1
9
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Stephen Blankenship
9
+ - Marc Tremblay
10
+ - Bob Burbach
13
11
  autorequire:
14
12
  bindir: bin
15
13
  cert_chain: []
16
-
17
- date: 2011-09-08 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
14
+ date: 2012-10-05 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
22
17
  name: json
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- requirement: *id001
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
31
25
  prerelease: false
32
- - !ruby/object:Gem::Dependency
33
- type: :development
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
34
33
  name: bundler
35
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
- requirements:
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
37
  - - ~>
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 1
41
- - 0
42
- - 0
38
+ - !ruby/object:Gem::Version
43
39
  version: 1.0.0
44
- requirement: *id002
45
- prerelease: false
46
- - !ruby/object:Gem::Dependency
47
40
  type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ - !ruby/object:Gem::Dependency
48
49
  name: jeweler
49
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
- requirements:
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
51
53
  - - ~>
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 1
55
- - 5
56
- - 1
54
+ - !ruby/object:Gem::Version
57
55
  version: 1.5.1
58
- requirement: *id003
56
+ type: :development
59
57
  prerelease: false
60
- - !ruby/object:Gem::Dependency
61
- type: :runtime
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 1.5.1
64
+ - !ruby/object:Gem::Dependency
62
65
  name: json
63
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- version: "0"
70
- requirement: *id004
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :runtime
71
73
  prerelease: false
72
- description: |-
73
- This gem allows simple integration between ActionMailer and SendGrid.
74
- SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ description: ! "This gem allows simple integration between ActionMailer and SendGrid.
81
+ \n SendGrid is an email deliverability API that is affordable
82
+ and has lots of bells and whistles."
75
83
  email: stephenrb@gmail.com
76
84
  executables: []
77
-
78
85
  extensions: []
79
-
80
- extra_rdoc_files:
86
+ extra_rdoc_files:
81
87
  - LICENSE
82
88
  - README.md
83
- files:
89
+ files:
84
90
  - .document
85
91
  - Gemfile
86
92
  - Gemfile.lock
@@ -92,36 +98,28 @@ files:
92
98
  - sendgrid.gemspec
93
99
  - test/sendgrid_test.rb
94
100
  - test/test_helper.rb
95
- has_rdoc: true
96
101
  homepage: http://github.com/stephenb/sendgrid
97
102
  licenses: []
98
-
99
103
  post_install_message:
100
104
  rdoc_options: []
101
-
102
- require_paths:
105
+ require_paths:
103
106
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- segments:
109
- - 0
110
- version: "0"
111
- required_rubygems_version: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
118
119
  requirements: []
119
-
120
120
  rubyforge_project:
121
- rubygems_version: 1.3.6
121
+ rubygems_version: 1.8.24
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)
125
- test_files:
126
- - test/sendgrid_test.rb
127
- - test/test_helper.rb
125
+ test_files: []