sendgrid 1.1.0 → 1.2.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.
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
@@ -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.0
@@ -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,8 @@ 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 unique args for this email.
107
+ # Merged with class-level unique args, if any exist.
105
108
  def sendgrid_unique_args(unique_args = {})
106
109
  @sg_unique_args = unique_args
107
110
  end
@@ -153,12 +156,7 @@ module SendGrid
153
156
  @ganalytics_options = []
154
157
  options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) }
155
158
  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
-
159
+
162
160
  # only override the appropriate methods for the current ActionMailer version
163
161
  if ActionMailer::Base.respond_to?(:mail)
164
162
 
@@ -167,7 +165,7 @@ module SendGrid
167
165
  # Sets the custom X-SMTPAPI header after creating the email but before delivery
168
166
  # NOTE: This override is used for Rails 3 ActionMailer classes.
169
167
  def mail(headers={}, &block)
170
- super
168
+ m = super
171
169
  if @sg_substitutions && !@sg_substitutions.empty?
172
170
  @sg_substitutions.each do |find, replace|
173
171
  raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
@@ -175,6 +173,7 @@ module SendGrid
175
173
  end
176
174
  puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
177
175
  self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
176
+ m
178
177
  end
179
178
 
180
179
  else
@@ -200,12 +199,15 @@ module SendGrid
200
199
  def sendgrid_json_headers(mail)
201
200
  header_opts = {}
202
201
 
202
+ #if not called within the mailer method, this will be nil so we default to empty hash
203
+ @sg_unique_args = @sg_unique_args || {}
204
+
203
205
  # set the unique arguments
204
206
  if @sg_unique_args || self.class.default_sg_unique_args
205
207
  unique_args = self.class.default_sg_unique_args || {}
206
208
  unique_args = unique_args.merge(@sg_unique_args)
207
209
 
208
- header_opts[:unique_args] = unique_args
210
+ header_opts[:unique_args] = unique_args unless unique_args.empty?
209
211
  end
210
212
 
211
213
  # Set category
@@ -230,7 +232,6 @@ module SendGrid
230
232
  end
231
233
 
232
234
  # Set enables/disables
233
- header_opts[:filters] = {} unless header_opts.has_key?(:filters)
234
235
  enabled_opts = []
235
236
  if @sg_options && !@sg_options.empty?
236
237
  # merge the options so that the instance-level "overrides"
@@ -241,12 +242,8 @@ module SendGrid
241
242
  enabled_opts = self.class.default_sg_options
242
243
  end
243
244
  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
245
+ filters = filters_hash_from_options(enabled_opts, @sg_disabled_options)
246
+ header_opts[:filters] = filters if filters && !filters.empty?
250
247
  end
251
248
 
252
249
  header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
@@ -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.0"
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 = "2013-05-15"
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 = [
@@ -39,17 +39,20 @@ Gem::Specification.new do |s|
39
39
 
40
40
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
41
  s.add_runtime_dependency(%q<json>, [">= 0"])
42
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
42
43
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
44
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
44
45
  s.add_runtime_dependency(%q<json>, [">= 0"])
45
46
  else
46
47
  s.add_dependency(%q<json>, [">= 0"])
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
47
49
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
50
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
49
51
  s.add_dependency(%q<json>, [">= 0"])
50
52
  end
51
53
  else
52
54
  s.add_dependency(%q<json>, [">= 0"])
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
56
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
57
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
58
  s.add_dependency(%q<json>, [">= 0"])
@@ -1,7 +1,11 @@
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',
@@ -18,7 +22,21 @@ class SendgridTest < Test::Unit::TestCase
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
@@ -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.0
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: 2013-05-15 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