sendgrid-rails 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  .rvmrc
4
4
  Gemfile.lock
5
5
  pkg/*
6
+ nbproject/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-19mode
6
+ script: bundle exec rspec spec
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = SendGrid gem for Rails
1
+ = SendGrid gem for Rails 3 {<img src="https://secure.travis-ci.org/PavelTyk/sendgrid-rails.png" />}[http://travis-ci.org/PavelTyk/sendgrid-rails]
2
2
 
3
3
  SendGrid gem provides ActionMailer::Base extensions to use SendGrid API features in you emails.
4
4
  It extends ActionMailer with next methods:
@@ -15,7 +15,7 @@ In your Gemfile:
15
15
 
16
16
  gem 'sendgrid-rails', '~> 2.0'
17
17
 
18
- In your config/environment.rb:
18
+ In config/initializers/mail.rb:
19
19
 
20
20
  ActionMailer::Base.register_interceptor(SendGrid::MailInterceptor)
21
21
 
@@ -28,6 +28,17 @@ In your config/environment.rb:
28
28
  :password => 'your password'
29
29
  }
30
30
 
31
+ === Overriding default recipient in standard SMTP header
32
+
33
+ Dummy recipient email used in sent email's "To" header and seen in received email's Received header.
34
+ By deefault set to 'dummy@email.com'
35
+
36
+ In config/initializers/mail.rb:
37
+
38
+ SendGrid.configure do |config|
39
+ config.dummy_recipient = 'noreply@example.com'
40
+ end
41
+
31
42
  == Usage examples
32
43
 
33
44
  === Adding multiple recipients:
@@ -58,17 +69,17 @@ Mailer class definition:
58
69
 
59
70
  === Adding category
60
71
 
61
- Mailer class definition:
72
+ Mailer class definition:
62
73
 
63
- class Mailer < ActionMailer::Base
64
- default :from => 'no-reply@example.com',
65
- :subject => 'An email sent via SendGrid with substitutions'
74
+ class Mailer < ActionMailer::Base
75
+ default :from => 'no-reply@example.com',
76
+ :subject => 'An email sent via SendGrid with substitutions'
66
77
 
67
- def email_with_category
68
- category 'SendGridRocks'
69
- mail :to => 'email1@email.com'
70
- end
71
- end
78
+ def email_with_category
79
+ category 'SendGridRocks'
80
+ mail :to => 'email1@email.com'
81
+ end
82
+ end
72
83
 
73
84
  == Apps (formerly called Filters)
74
85
 
@@ -90,6 +101,14 @@ Add an invisible image at the end of the email to track e-mail opens. If the ema
90
101
 
91
102
  == Change log
92
103
 
104
+ *v2.0.2*
105
+
106
+ * ApiHeader#to_json wraps array items with spaces
107
+
108
+ *v2.0.1*
109
+
110
+ * Standard SMTP To attribute set to 'dummy@email.com' after recipients added to X-SMTPAPI header
111
+
93
112
  *v2.0*
94
113
 
95
114
  * Using mail interceptor
data/lib/send_grid.rb CHANGED
@@ -2,6 +2,7 @@ module SendGrid
2
2
  autoload :ApiHeader, 'send_grid/api_header'
3
3
  autoload :MailInterceptor, 'send_grid/mail_interceptor'
4
4
  autoload :VERSION, 'send_grid/version'
5
+ autoload :Config, 'send_grid/config'
5
6
 
6
7
  def self.included(base)
7
8
  base.class_eval do
@@ -27,4 +28,17 @@ module SendGrid
27
28
  add_filter_setting(:opentrack, :enabled, enabled ? 1 : 0) unless enabled.nil?
28
29
  end
29
30
  end
31
+
32
+ class << self
33
+ attr_writer :config
34
+
35
+ def config
36
+ @config ||= SendGrid::Config.new
37
+ end
38
+
39
+ # Sendgrid.config will be default if block is not passed
40
+ def configure
41
+ yield(self.config) if block_given?
42
+ end
43
+ end
30
44
  end
@@ -0,0 +1,7 @@
1
+ class SendGrid::Config
2
+ attr_accessor :dummy_recipient
3
+
4
+ def initialize
5
+ @dummy_recipient = "dummy@email.com"
6
+ end
7
+ end
@@ -4,7 +4,7 @@ module SendGrid
4
4
  sendgrid_header = mail.instance_variable_get(:@sendgrid_header)
5
5
  sendgrid_header.add_recipients(mail.to)
6
6
  mail.header['X-SMTPAPI'] = sendgrid_header.to_json if sendgrid_header.data.present?
7
- mail.header['to'] = 'dummy@email.com'
7
+ mail.header['to'] = SendGrid.config.dummy_recipient
8
8
  end
9
9
  end
10
10
  end
@@ -1,4 +1,4 @@
1
1
  module SendGrid
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
4
4
 
@@ -1,6 +1,6 @@
1
1
  require 'send_grid'
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext'
4
- autoload :ActionMailer, 'action_mailer'
4
+ require 'action_mailer'
5
5
 
6
6
  ActionMailer::Base.send :include, SendGrid
data/spec/mailer_spec.rb CHANGED
@@ -1,42 +1,62 @@
1
- require 'spec_helper'
2
-
3
- describe Mailer do
4
- describe 'email with multiple recipients' do
5
- it 'set correct recipients in X-SMTAPI header' do
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" ]}')
8
- end
9
-
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")
13
- end
14
-
15
- it 'maintains recommended header line length' do
16
- emails = 15.times.map{ |i| "email#{i}@example.com" }
17
- header = Mailer.email_with_multiple_recipients(emails).deliver.header.to_s
18
- header.lines.each do |line|
19
- unless line.starts_with?('Message-ID:') # May be longer depending on your test machine
20
- line.should have_at_most(72).characters
21
- end
22
- end
23
- end
24
- end
25
-
26
- describe '#open_tracking' do
27
- it 'set correct open tracking enabled X-SMTAPI header' do
28
- Mailer.email_open_tracking.deliver.header.to_s.
29
- should include('"filters":{"opentrack":{"settings":{"enabled":1}}}')
30
- end
31
-
32
- it 'set correct open tracking disabled X-SMTAPI header' do
33
- Mailer.email_open_tracking(false).deliver.header.to_s.
34
- should include('"filters":{"opentrack":{"settings":{"enabled":0}}}')
35
- end
36
-
37
- it 'set correct open tracking nil X-SMTAPI header' do
38
- Mailer.email_open_tracking(nil).deliver.header.to_s.
39
- should_not include('"filters":{"opentrack')
40
- end
41
- end
42
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mailer do
4
+ describe 'email with multiple recipients' do
5
+ it 'set correct recipients in X-SMTAPI header' do
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" ]}')
8
+ end
9
+
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")
13
+ end
14
+
15
+ it 'maintains recommended header line length' do
16
+ emails = 15.times.map{ |i| "email#{i}@example.com" }
17
+ header = Mailer.email_with_multiple_recipients(emails).deliver.header.to_s
18
+ header.lines.each do |line|
19
+ unless line.starts_with?('Message-ID:') # May be longer depending on your test machine
20
+ line.should have_at_most(72).characters
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#open_tracking' do
27
+ it 'set correct open tracking enabled X-SMTAPI header' do
28
+ Mailer.email_open_tracking.deliver.header.to_s.
29
+ should include('"filters":{"opentrack":{"settings":{"enabled":1}}}')
30
+ end
31
+
32
+ it 'set correct open tracking disabled X-SMTAPI header' do
33
+ Mailer.email_open_tracking(false).deliver.header.to_s.
34
+ should include('"filters":{"opentrack":{"settings":{"enabled":0}}}')
35
+ end
36
+
37
+ it 'set correct open tracking nil X-SMTAPI header' do
38
+ Mailer.email_open_tracking(nil).deliver.header.to_s.
39
+ should_not include('"filters":{"opentrack')
40
+ end
41
+ end
42
+
43
+ describe 'dummy_recipient used in TO is taken from config' do
44
+ it 'should be used in TO default dummy_recipient' do
45
+ # by defaut dummy_recipient's email is dummy@email.com
46
+
47
+ Mailer.email_with_multiple_recipients(%w(em1@email.com em2@email.com)).deliver.header.to_s.
48
+ should include('To: dummy@email.com')
49
+ end
50
+
51
+ it 'should be used in To defined in config dummy_recipient' do
52
+ # dummy_recipient can be redefined config/initializers
53
+
54
+ SendGrid.configure do |config|
55
+ config.dummy_recipient = 'noreply@example.com'
56
+ end
57
+
58
+ Mailer.email_with_multiple_recipients(%w(em1@email.com em2@email.com)).deliver.header.to_s.
59
+ should include('To: noreply@example.com')
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-28 00:00:00.000000000Z
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70215829558960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 2.5.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70215829558960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.5.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: actionmailer
27
- requirement: &70215829558460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 3.0.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70215829558460
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: activesupport
38
- requirement: &70215829558000 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: 2.1.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70215829558000
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
47
62
  description: Gem to extend ActionMailer with SendGrid API support
48
63
  email:
49
64
  - paveltyk@gmail.com
@@ -53,11 +68,13 @@ extra_rdoc_files: []
53
68
  files:
54
69
  - .gitignore
55
70
  - .rspec
71
+ - .travis.yml
56
72
  - Gemfile
57
73
  - README.rdoc
58
74
  - Rakefile
59
75
  - lib/send_grid.rb
60
76
  - lib/send_grid/api_header.rb
77
+ - lib/send_grid/config.rb
61
78
  - lib/send_grid/mail_interceptor.rb
62
79
  - lib/send_grid/version.rb
63
80
  - lib/sendgrid-rails.rb
@@ -87,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
104
  version: '0'
88
105
  requirements: []
89
106
  rubyforge_project: sendgrid-rails
90
- rubygems_version: 1.8.10
107
+ rubygems_version: 1.8.25
91
108
  signing_key:
92
109
  specification_version: 3
93
110
  summary: SendGrid gem fo Rails 3