sendgrid 1.1.0 → 1.2.4

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/Gemfile CHANGED
@@ -9,8 +9,12 @@ gem "json"
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
11
11
  group :development do
12
- # gem "shoulda", ">= 0"
12
+ gem "shoulda", ">= 0"
13
13
  gem "bundler", "~> 1.0.0"
14
14
  gem "jeweler", "~> 1.5.1"
15
15
  # gem "rcov", ">= 0"
16
16
  end
17
+
18
+ group :test do
19
+ gem "actionmailer", ">= 2.3.2"
20
+ end
data/Gemfile.lock CHANGED
@@ -1,18 +1,67 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ actionmailer (3.1.5)
5
+ actionpack (= 3.1.5)
6
+ mail (~> 2.3.3)
7
+ actionpack (3.1.5)
8
+ activemodel (= 3.1.5)
9
+ activesupport (= 3.1.5)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.6)
14
+ rack-cache (~> 1.2)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.4)
18
+ activemodel (3.1.5)
19
+ activesupport (= 3.1.5)
20
+ builder (~> 3.0.0)
21
+ i18n (~> 0.6)
22
+ activesupport (3.1.5)
23
+ multi_json (>= 1.0, < 1.3)
24
+ builder (3.0.0)
25
+ erubis (2.7.0)
4
26
  git (1.2.5)
27
+ hike (1.2.1)
28
+ i18n (0.6.0)
5
29
  jeweler (1.5.2)
6
30
  bundler (~> 1.0.0)
7
31
  git (>= 1.2.5)
8
32
  rake
9
33
  json (1.5.1)
34
+ mail (2.3.3)
35
+ i18n (>= 0.4.0)
36
+ mime-types (~> 1.16)
37
+ treetop (~> 1.4.8)
38
+ mime-types (1.18)
39
+ multi_json (1.2.0)
40
+ polyglot (0.3.3)
41
+ rack (1.3.6)
42
+ rack-cache (1.2)
43
+ rack (>= 0.4)
44
+ rack-mount (0.8.3)
45
+ rack (>= 1.0.0)
46
+ rack-test (0.6.1)
47
+ rack (>= 1.0)
10
48
  rake (0.8.7)
49
+ shoulda (2.10.3)
50
+ sprockets (2.0.4)
51
+ hike (~> 1.2)
52
+ rack (~> 1.0)
53
+ tilt (~> 1.1, != 1.3.0)
54
+ tilt (1.3.3)
55
+ treetop (1.4.10)
56
+ polyglot
57
+ polyglot (>= 0.3.1)
11
58
 
12
59
  PLATFORMS
13
60
  ruby
14
61
 
15
62
  DEPENDENCIES
63
+ actionmailer (>= 2.3.2)
16
64
  bundler (~> 1.0.0)
17
65
  jeweler (~> 1.5.1)
18
66
  json
67
+ shoulda
data/README.md CHANGED
@@ -29,7 +29,7 @@ Example:
29
29
  :port => 25,
30
30
  :domain => "mysite.com",
31
31
  :authentication => :plain,
32
- :user_name => "sendgrd_username@mysite.com",
32
+ :user_name => "sendgrd_username",
33
33
  :password => "sendgrid_password"
34
34
  }
35
35
 
data/Rakefile CHANGED
@@ -39,20 +39,20 @@ rescue LoadError
39
39
  end
40
40
  end
41
41
 
42
- task :test => :check_dependencies
42
+ task :test
43
43
 
44
44
  task :default => :test
45
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
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
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
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 CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.4
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module SendGrid
4
+ class Railtie < Rails::Railtie # :nodoc:
5
+
6
+ initializer "send_grid.action_mailer" do
7
+ ActiveSupport.on_load(:action_mailer) { ActionMailer::Base.send(:include, SendGrid) }
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module SendGrid #:nodoc:
2
+ VERSION = "2.0.0"
3
+ end
data/lib/sendgrid.rb CHANGED
@@ -28,7 +28,7 @@ module SendGrid
28
28
  :default_footer_text, :default_spamcheck_score, :default_sg_unique_args
29
29
  end
30
30
  attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions,
31
- :subscriptiontrack_text, :footer_text, :spamcheck_score, :sg_unique_args
31
+ :subscriptiontrack_text, :footer_text, :spamcheck_score, :sg_unique_args, :sg_send_at
32
32
  end
33
33
 
34
34
  # NOTE: This commented-out approach may be a "safer" option for Rails 3, but it
@@ -67,7 +67,7 @@ module SendGrid
67
67
  self.default_sg_options = Array.new unless self.default_sg_options
68
68
  options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) }
69
69
  end
70
-
70
+
71
71
  # Sets the default text for subscription tracking (must be enabled).
72
72
  # There are two options:
73
73
  # 1. Add an unsubscribe link at the bottom of the email
@@ -90,7 +90,9 @@ module SendGrid
90
90
  self.default_spamcheck_score = score
91
91
  end
92
92
 
93
- # Sets the default unique arguments to send
93
+ # Sets unique args at the class level. Should be a hash
94
+ # of name, value pairs.
95
+ # { :some_unique_arg => "some_value"}
94
96
  def sendgrid_unique_args(unique_args = {})
95
97
  self.default_sg_unique_args = unique_args
96
98
  end
@@ -101,7 +103,13 @@ module SendGrid
101
103
  @sg_category = category
102
104
  end
103
105
 
104
- # Call within mailer method to add/override unique arguments in the defaults
106
+ # Call within mailer method to set send time for this mail
107
+ def sendgrid_send_at(utc_timestamp)
108
+ @sg_send_at = utc_timestamp
109
+ end
110
+
111
+ # Call within mailer method to set unique args for this email.
112
+ # Merged with class-level unique args, if any exist.
105
113
  def sendgrid_unique_args(unique_args = {})
106
114
  @sg_unique_args = unique_args
107
115
  end
@@ -153,12 +161,7 @@ module SendGrid
153
161
  @ganalytics_options = []
154
162
  options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) }
155
163
  end
156
-
157
- # Call within mailer method to set unique args for this email.
158
- def sendgrid_unique_args(args)
159
- @sg_unique_args = args
160
- end
161
-
164
+
162
165
  # only override the appropriate methods for the current ActionMailer version
163
166
  if ActionMailer::Base.respond_to?(:mail)
164
167
 
@@ -167,7 +170,7 @@ module SendGrid
167
170
  # Sets the custom X-SMTPAPI header after creating the email but before delivery
168
171
  # NOTE: This override is used for Rails 3 ActionMailer classes.
169
172
  def mail(headers={}, &block)
170
- super
173
+ m = super
171
174
  if @sg_substitutions && !@sg_substitutions.empty?
172
175
  @sg_substitutions.each do |find, replace|
173
176
  raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
@@ -175,6 +178,7 @@ module SendGrid
175
178
  end
176
179
  puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
177
180
  self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
181
+ m
178
182
  end
179
183
 
180
184
  else
@@ -200,12 +204,15 @@ module SendGrid
200
204
  def sendgrid_json_headers(mail)
201
205
  header_opts = {}
202
206
 
207
+ #if not called within the mailer method, this will be nil so we default to empty hash
208
+ @sg_unique_args = @sg_unique_args || {}
209
+
203
210
  # set the unique arguments
204
211
  if @sg_unique_args || self.class.default_sg_unique_args
205
212
  unique_args = self.class.default_sg_unique_args || {}
206
213
  unique_args = unique_args.merge(@sg_unique_args)
207
214
 
208
- header_opts[:unique_args] = unique_args
215
+ header_opts[:unique_args] = unique_args unless unique_args.empty?
209
216
  end
210
217
 
211
218
  # Set category
@@ -219,6 +226,9 @@ module SendGrid
219
226
  header_opts[:category] = self.class.default_sg_category
220
227
  end
221
228
 
229
+ #Set send_at if set by the user
230
+ header_opts[:send_at] = @sg_send_at unless @sg_send_at.blank?
231
+
222
232
  # Set multi-recipients
223
233
  if @sg_recipients && !@sg_recipients.empty?
224
234
  header_opts[:to] = @sg_recipients
@@ -230,7 +240,6 @@ module SendGrid
230
240
  end
231
241
 
232
242
  # Set enables/disables
233
- header_opts[:filters] = {} unless header_opts.has_key?(:filters)
234
243
  enabled_opts = []
235
244
  if @sg_options && !@sg_options.empty?
236
245
  # merge the options so that the instance-level "overrides"
@@ -241,12 +250,8 @@ module SendGrid
241
250
  enabled_opts = self.class.default_sg_options
242
251
  end
243
252
  if !enabled_opts.empty? || (@sg_disabled_options && !@sg_disabled_options.empty?)
244
- header_opts[:filters] = filters_hash_from_options(enabled_opts, @sg_disabled_options)
245
- end
246
-
247
- # Set unique_args
248
- if @sg_unique_args && !@sg_unique_args.empty?
249
- header_opts[:unique_args] = @sg_unique_args
253
+ filters = filters_hash_from_options(enabled_opts, @sg_disabled_options)
254
+ header_opts[:filters] = filters if filters && !filters.empty?
250
255
  end
251
256
 
252
257
  header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
data/sendgrid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sendgrid"
8
- s.version = "1.1.0"
8
+ s.version = "1.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stephen Blankenship", "Marc Tremblay", "Bob Burbach"]
12
- s.date = "2012-10-05"
12
+ s.date = "2016-01-08"
13
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
14
  s.email = "stephenrb@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -25,13 +25,15 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/sendgrid.rb",
28
+ "lib/sendgrid/railtie.rb",
29
+ "lib/sendgrid/version.rb",
28
30
  "sendgrid.gemspec",
29
31
  "test/sendgrid_test.rb",
30
32
  "test/test_helper.rb"
31
33
  ]
32
34
  s.homepage = "http://github.com/stephenb/sendgrid"
33
35
  s.require_paths = ["lib"]
34
- s.rubygems_version = "1.8.24"
36
+ s.rubygems_version = "1.8.23"
35
37
  s.summary = "A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)"
36
38
 
37
39
  if s.respond_to? :specification_version then
@@ -39,17 +41,20 @@ Gem::Specification.new do |s|
39
41
 
40
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
43
  s.add_runtime_dependency(%q<json>, [">= 0"])
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
42
45
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
46
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
44
47
  s.add_runtime_dependency(%q<json>, [">= 0"])
45
48
  else
46
49
  s.add_dependency(%q<json>, [">= 0"])
50
+ s.add_dependency(%q<shoulda>, [">= 0"])
47
51
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
52
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
49
53
  s.add_dependency(%q<json>, [">= 0"])
50
54
  end
51
55
  else
52
56
  s.add_dependency(%q<json>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
58
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
59
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
60
  s.add_dependency(%q<json>, [">= 0"])
@@ -1,13 +1,17 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SendgridTest < Test::Unit::TestCase
4
- def setup
4
+ def setup
5
+ ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.perform_deliveries = true
7
+ ActionMailer::Base.deliveries = []
8
+
5
9
  @options = {
6
10
  :to => ['test@example.com'],
7
11
  :from => 'test@example.com',
8
12
  :reply_to => 'reply-to@example.com',
9
13
  :subject => 'The Subject',
10
- :html_content => '<html>content</html>',
14
+ :body => '<html>content</html>',
11
15
  :category => 'MyCategory',
12
16
  :substitutions => {
13
17
  'first_name' => ['Joe'],
@@ -15,10 +19,24 @@ class SendgridTest < Test::Unit::TestCase
15
19
  }
16
20
  }
17
21
  end
18
-
22
+
19
23
  should "require the same number of items in a substitution array as is in the recipient array" do
20
24
  assert_raise ArgumentError do
21
- test_email = SendgridCampaignTestMailer.create_test(@options)
25
+ test_email = SendgridCampaignTestMailer.create_test(@options).deliver
22
26
  end
23
27
  end
28
+
29
+ should "accept a hash of unique args at the class level" do
30
+ assert_equal ({ :test_arg => "test value" }), SendgridUniqueArgsMailer.default_sg_unique_args
31
+ end
32
+
33
+ should "pass unique args from both the mailer class and the mailer method through custom headers" do
34
+ @options.delete(:substitutions)
35
+ SendgridUniqueArgsMailer.unique_args_test_email(@options).deliver
36
+ mail = ActionMailer::Base.deliveries.last
37
+ # assert({ :unique_args => {:mailer_method_unique_arg => "some value", :test_arg => "test value"} }.to_json == mail.header['X-SMTPAPI'].value)
38
+ expected = { 'unique_args' => {'mailer_method_unique_arg' => "some value", 'test_arg' => "test value"} }
39
+ actual = JSON.parse(mail.header['X-SMTPAPI'].value)
40
+ assert_equal(expected, actual)
41
+ end
24
42
  end
data/test/test_helper.rb CHANGED
@@ -4,11 +4,8 @@ require 'shoulda'
4
4
 
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'sendgrid'
8
7
  require 'action_mailer'
9
-
10
- class Test::Unit::TestCase
11
- end
8
+ require 'sendgrid'
12
9
 
13
10
  class SendgridCampaignTestMailer < ActionMailer::Base
14
11
  include SendGrid
@@ -26,13 +23,9 @@ class SendgridCampaignTestMailer < ActionMailer::Base
26
23
  # array must match the :to array
27
24
  # :category the sendgrid category used for tracking
28
25
  # :html_content, :text_content, :subject
29
- def test(options)
26
+ def create_test(options)
30
27
  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])
28
+ mail(options)
36
29
  end
37
30
 
38
31
  protected
@@ -49,7 +42,16 @@ class SendgridCampaignTestMailer < ActionMailer::Base
49
42
  end
50
43
  end
51
44
 
52
-
53
45
  sendgrid_category(options[:category])
54
46
  end
55
47
  end
48
+
49
+ class SendgridUniqueArgsMailer < ActionMailer::Base
50
+ include SendGrid
51
+ sendgrid_unique_args({ :test_arg => "test value" })
52
+
53
+ def unique_args_test_email(options)
54
+ sendgrid_unique_args({ :mailer_method_unique_arg => "some value" })
55
+ mail(options)
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-05 00:00:00.000000000 Z
14
+ date: 2016-01-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -29,6 +29,22 @@ dependencies:
29
29
  - - ! '>='
30
30
  - !ruby/object:Gem::Version
31
31
  version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: shoulda
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
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: '0'
32
48
  - !ruby/object:Gem::Dependency
33
49
  name: bundler
34
50
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +111,8 @@ files:
95
111
  - Rakefile
96
112
  - VERSION
97
113
  - lib/sendgrid.rb
114
+ - lib/sendgrid/railtie.rb
115
+ - lib/sendgrid/version.rb
98
116
  - sendgrid.gemspec
99
117
  - test/sendgrid_test.rb
100
118
  - test/test_helper.rb
@@ -118,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
136
  version: '0'
119
137
  requirements: []
120
138
  rubyforge_project:
121
- rubygems_version: 1.8.24
139
+ rubygems_version: 1.8.23
122
140
  signing_key:
123
141
  specification_version: 3
124
142
  summary: A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)