sendgrid-rails 1.1.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/.gitignore +1 -0
- data/README.rdoc +27 -7
- data/Rakefile +3 -0
- data/lib/send_grid/mail_interceptor.rb +10 -0
- data/lib/send_grid/version.rb +1 -1
- data/lib/send_grid.rb +8 -12
- data/lib/sendgrid-rails.rb +2 -1
- data/spec/fixtures/mailers/mailer.rb +1 -2
- data/spec/mailer_spec.rb +11 -14
- data/spec/spec_helper.rb +1 -1
- metadata +47 -77
data/README.rdoc
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
= SendGrid gem for Rails
|
2
2
|
|
3
|
-
SendGrid gem provides ActionMailer extensions to use SendGrid API features in you emails.
|
3
|
+
SendGrid gem provides ActionMailer::Base extensions to use SendGrid API features in you emails.
|
4
4
|
It extends ActionMailer with next methods:
|
5
5
|
|
6
|
-
add_recipients(array_of_emails)
|
7
6
|
substitute(patters_string, array_of_substitunion_strings)
|
8
7
|
uniq_args(hash_of_unique_args)
|
9
8
|
category(category_string)
|
@@ -14,10 +13,12 @@ It extends ActionMailer with next methods:
|
|
14
13
|
|
15
14
|
In your Gemfile:
|
16
15
|
|
17
|
-
gem 'sendgrid-rails', '
|
16
|
+
gem 'sendgrid-rails', '~> 2.0'
|
18
17
|
|
19
18
|
In your config/environment.rb:
|
20
19
|
|
20
|
+
ActionMailer::Base.register_interceptor(SendGrid::MailInterceptor)
|
21
|
+
|
21
22
|
ActionMailer::Base.smtp_settings = {
|
22
23
|
:address => 'smtp.sendgrid.net',
|
23
24
|
:port => '25',
|
@@ -36,8 +37,7 @@ In your config/environment.rb:
|
|
36
37
|
:subject => 'An email sent via SendGrid'
|
37
38
|
|
38
39
|
def email_with_multiple_recipients
|
39
|
-
|
40
|
-
mail
|
40
|
+
mail :to => %w(email1@email.com email2@email.com)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -50,13 +50,26 @@ Mailer class definition:
|
|
50
50
|
:subject => 'An email sent via SendGrid with substitutions'
|
51
51
|
|
52
52
|
def email_with_substitutions
|
53
|
-
add_recipients %w(email1@email.com email2@email.com)
|
54
53
|
substitute '-user_name-', %w(User1 User2)
|
55
54
|
|
56
|
-
mail :body => "Hello, -user_name-!"
|
55
|
+
mail :to => %w(email1@email.com email2@email.com), :body => "Hello, -user_name-!"
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
59
|
+
=== Adding category
|
60
|
+
|
61
|
+
Mailer class definition:
|
62
|
+
|
63
|
+
class Mailer < ActionMailer::Base
|
64
|
+
default :from => 'no-reply@example.com',
|
65
|
+
:subject => 'An email sent via SendGrid with substitutions'
|
66
|
+
|
67
|
+
def email_with_category
|
68
|
+
category 'SendGridRocks'
|
69
|
+
mail :to => 'email1@email.com'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
60
73
|
== Apps (formerly called Filters)
|
61
74
|
|
62
75
|
Apps can be applied to any of your email messages and can be configured through SendGrid gem.
|
@@ -75,3 +88,10 @@ Add an invisible image at the end of the email to track e-mail opens. If the ema
|
|
75
88
|
end
|
76
89
|
end
|
77
90
|
|
91
|
+
== Change log
|
92
|
+
|
93
|
+
*v2.0*
|
94
|
+
|
95
|
+
* Using mail interceptor
|
96
|
+
* ActionMailer::Base#add_recipients - removed
|
97
|
+
* Standard SMTP To attribute get nullified after recipients added to X-SMTPAPI header
|
data/Rakefile
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
module SendGrid
|
2
|
+
class MailInterceptor
|
3
|
+
def self.delivering_email(mail)
|
4
|
+
sendgrid_header = mail.instance_variable_get(:@sendgrid_header)
|
5
|
+
sendgrid_header.add_recipients(mail.to)
|
6
|
+
mail.header['X-SMTPAPI'] = sendgrid_header.to_json if sendgrid_header.data.present?
|
7
|
+
mail.header['to'] = nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/send_grid/version.rb
CHANGED
data/lib/send_grid.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module SendGrid
|
2
2
|
autoload :ApiHeader, 'send_grid/api_header'
|
3
|
+
autoload :MailInterceptor, 'send_grid/mail_interceptor'
|
3
4
|
autoload :VERSION, 'send_grid/version'
|
4
5
|
|
5
6
|
def self.included(base)
|
6
7
|
base.class_eval do
|
7
8
|
include InstanceMethods
|
8
|
-
delegate :
|
9
|
-
alias_method_chain :mail, :
|
9
|
+
delegate :substitute, :uniq_args, :category, :add_filter_setting, :to => :sendgrid_header
|
10
|
+
alias_method_chain :mail, :sendgrid
|
11
|
+
alias_method :sendgrid_header, :send_grid_header
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -15,15 +17,10 @@ module SendGrid
|
|
15
17
|
@send_grid_header ||= SendGrid::ApiHeader.new
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def mail_with_send_grid(headers={}, &block)
|
24
|
-
headers[:to] ||= send_grid_stub_for_recipient_email
|
25
|
-
headers['X-SMTPAPI'] = send_grid_header.to_json if send_grid_header.data.present?
|
26
|
-
mail_without_send_grid(headers, &block)
|
20
|
+
def mail_with_sendgrid(headers={}, &block)
|
21
|
+
mail_without_sendgrid(headers, &block).tap do |message|
|
22
|
+
message.instance_variable_set :@sendgrid_header, sendgrid_header
|
23
|
+
end
|
27
24
|
end
|
28
25
|
|
29
26
|
def open_tracking(enabled = true)
|
@@ -31,4 +28,3 @@ module SendGrid
|
|
31
28
|
end
|
32
29
|
end
|
33
30
|
end
|
34
|
-
|
data/lib/sendgrid-rails.rb
CHANGED
@@ -3,8 +3,7 @@ class Mailer < ActionMailer::Base
|
|
3
3
|
:subject => 'Test email'
|
4
4
|
|
5
5
|
def email_with_multiple_recipients(recipients)
|
6
|
-
|
7
|
-
mail :body => "Hello!"
|
6
|
+
mail :to => recipients, :body => "Hello!"
|
8
7
|
end
|
9
8
|
|
10
9
|
def email_open_tracking(opentrack_enabled = true)
|
data/spec/mailer_spec.rb
CHANGED
@@ -2,34 +2,31 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mailer do
|
4
4
|
describe 'email with multiple recipients' do
|
5
|
-
let(:recipients) { %w(email1@email.com email2@email.com) }
|
6
|
-
let(:mail) { Mailer.email_with_multiple_recipients recipients }
|
7
|
-
|
8
5
|
it 'set correct recipients in X-SMTAPI header' do
|
9
|
-
|
6
|
+
Mailer.email_with_multiple_recipients(%w(em1@email.com em2@email.com)).deliver.header.to_s.
|
7
|
+
should include('X-SMTPAPI: {"to":["em1@email.com","em2@email.com"]}')
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ActionMailer::Base.smtp_settings = { :domain => 'sendgrid.com' }
|
16
|
-
mail.to.should eq ['group-delivery@sendgrid.com']
|
10
|
+
it 'removes original TO header part' do
|
11
|
+
Mailer.email_with_multiple_recipients(%w(em1@email.com em2@email.com)).deliver.header.to_s.
|
12
|
+
should_not include("To: em1@email.com")
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
20
16
|
describe '#open_tracking' do
|
21
|
-
|
22
17
|
it 'set correct open tracking enabled X-SMTAPI header' do
|
23
|
-
Mailer.email_open_tracking.to_s.
|
18
|
+
Mailer.email_open_tracking.deliver.header.to_s.
|
19
|
+
should include('"filters":{"opentrack":{"settings":{"enabled":1}}}')
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'set correct open tracking disabled X-SMTAPI header' do
|
27
|
-
Mailer.email_open_tracking(false).to_s.
|
23
|
+
Mailer.email_open_tracking(false).deliver.header.to_s.
|
24
|
+
should include('"filters":{"opentrack":{"settings":{"enabled":0}}}')
|
28
25
|
end
|
29
26
|
|
30
27
|
it 'set correct open tracking nil X-SMTAPI header' do
|
31
|
-
Mailer.email_open_tracking(nil).to_s.
|
28
|
+
Mailer.email_open_tracking(nil).deliver.header.to_s.
|
29
|
+
should_not include('"filters":{"opentrack')
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
35
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'sendgrid-rails'
|
2
2
|
|
3
|
+
ActionMailer::Base.register_interceptor(SendGrid::MailInterceptor)
|
3
4
|
ActionMailer::Base.delivery_method = :test
|
4
5
|
ActionMailer::Base.prepend_view_path File.join(File.dirname(__FILE__), "fixtures", "views")
|
5
6
|
|
6
7
|
Dir["#{File.dirname(__FILE__)}/fixtures/mailers/*.rb"].each { |f| require f }
|
7
|
-
|
metadata
CHANGED
@@ -1,81 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '2.0'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 1.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- PavelTyk
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70309266084920 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 27
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 5
|
33
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 2.5.0
|
35
22
|
type: :development
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: actionmailer
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *70309266084920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionmailer
|
27
|
+
requirement: &70309266079020 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 7
|
46
|
-
segments:
|
47
|
-
- 3
|
48
|
-
- 0
|
49
|
-
- 0
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
50
32
|
version: 3.0.0
|
51
33
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: activesupport
|
55
34
|
prerelease: false
|
56
|
-
|
35
|
+
version_requirements: *70309266079020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
requirement: &70309266078560 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 11
|
62
|
-
segments:
|
63
|
-
- 2
|
64
|
-
- 1
|
65
|
-
- 0
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
66
43
|
version: 2.1.0
|
67
44
|
type: :runtime
|
68
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70309266078560
|
69
47
|
description: Gem to extend ActionMailer with SendGrid API support
|
70
|
-
email:
|
48
|
+
email:
|
71
49
|
- paveltyk@gmail.com
|
72
50
|
executables: []
|
73
|
-
|
74
51
|
extensions: []
|
75
|
-
|
76
52
|
extra_rdoc_files: []
|
77
|
-
|
78
|
-
files:
|
53
|
+
files:
|
79
54
|
- .gitignore
|
80
55
|
- .rspec
|
81
56
|
- Gemfile
|
@@ -83,6 +58,7 @@ files:
|
|
83
58
|
- Rakefile
|
84
59
|
- lib/send_grid.rb
|
85
60
|
- lib/send_grid/api_header.rb
|
61
|
+
- lib/send_grid/mail_interceptor.rb
|
86
62
|
- lib/send_grid/version.rb
|
87
63
|
- lib/sendgrid-rails.rb
|
88
64
|
- send_grid.gemspec
|
@@ -91,39 +67,33 @@ files:
|
|
91
67
|
- spec/mailer_spec.rb
|
92
68
|
- spec/spec_helper.rb
|
93
69
|
- spec/version_spec.rb
|
94
|
-
has_rdoc: true
|
95
70
|
homepage: https://github.com/PavelTyk/sendgrid-rails
|
96
71
|
licenses: []
|
97
|
-
|
98
72
|
post_install_message:
|
99
73
|
rdoc_options: []
|
100
|
-
|
101
|
-
require_paths:
|
74
|
+
require_paths:
|
102
75
|
- lib
|
103
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
77
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
|
110
|
-
- 0
|
111
|
-
version: "0"
|
112
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
83
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
segments:
|
119
|
-
- 0
|
120
|
-
version: "0"
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
121
88
|
requirements: []
|
122
|
-
|
123
89
|
rubyforge_project: sendgrid-rails
|
124
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.10
|
125
91
|
signing_key:
|
126
92
|
specification_version: 3
|
127
93
|
summary: SendGrid gem fo Rails 3
|
128
|
-
test_files:
|
129
|
-
|
94
|
+
test_files:
|
95
|
+
- spec/api_header_spec.rb
|
96
|
+
- spec/fixtures/mailers/mailer.rb
|
97
|
+
- spec/mailer_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/version_spec.rb
|