sendgrid-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,15 +7,14 @@ It extends ActionMailer with next methods:
7
7
  substitute(patters_string, array_of_substitunion_strings)
8
8
  uniq_args(hash_of_unique_args)
9
9
  category(category_string)
10
+ open_tracking(enabled = true)
10
11
  add_filter_setting(filter_name, setting_name, value)
11
12
 
12
- == Examples
13
-
14
- === Rails 3 configuration
13
+ == Rails 3 configuration
15
14
 
16
15
  In your Gemfile:
17
16
 
18
- gem 'sendgrid-rails', '>=1.0.0', :git => 'git://github.com/PavelTyk/sendgrid-rails.git'
17
+ gem 'sendgrid-rails', '>=1.0.0'
19
18
 
20
19
  In your config/environment.rb:
21
20
 
@@ -28,7 +27,9 @@ In your config/environment.rb:
28
27
  :password => 'your password'
29
28
  }
30
29
 
31
- ==== Adding multiple recipients:
30
+ == Usage examples
31
+
32
+ === Adding multiple recipients:
32
33
 
33
34
  class Mailer < ActionMailer::Base
34
35
  default :from => 'no-reply@example.com',
@@ -36,7 +37,7 @@ In your config/environment.rb:
36
37
 
37
38
  def email_with_multiple_recipients
38
39
  add_recipients %w(email1@email.com email2@email.com)
39
- mail :body => 'Hello.'
40
+ mail
40
41
  end
41
42
  end
42
43
 
@@ -48,14 +49,29 @@ Mailer class definition:
48
49
  default :from => 'no-reply@example.com',
49
50
  :subject => 'An email sent via SendGrid with substitutions'
50
51
 
51
- def mail_with_substitutions
52
- emails = %w(email1@email.com email2@email.com)
53
- names = %w(User1 User2)
52
+ def email_with_substitutions
53
+ add_recipients %w(email1@email.com email2@email.com)
54
+ substitute '-user_name-', %w(User1 User2)
55
+
56
+ mail :body => "Hello, -user_name-!"
57
+ end
58
+ end
59
+
60
+ == Apps (formerly called Filters)
54
61
 
55
- add_recipients emails
56
- substitute '-user_name-', names
62
+ Apps can be applied to any of your email messages and can be configured through SendGrid gem.
63
+
64
+ === Open Tracking
65
+
66
+ Add an invisible image at the end of the email to track e-mail opens. If the email recipient has images enabled on the email client, a request to server for the invisible image is executed and an open is logged.
67
+
68
+ class Mailer < ActionMailer::Base
69
+ default :from => 'no-reply@example.com',
70
+ :subject => 'An email sent via SendGrid'
57
71
 
58
- mail :body => "Hello, -user_name-."
72
+ def email_with_open_tracking_enabled
73
+ open_tracking true
74
+ mail :to => 'email@email.com'
59
75
  end
60
76
  end
61
77
 
data/lib/send_grid.rb CHANGED
@@ -22,9 +22,13 @@ module SendGrid
22
22
 
23
23
  def mail_with_send_grid(headers={}, &block)
24
24
  headers[:to] ||= send_grid_stub_for_recipient_email
25
- headers['X-SMTPAPI'] = send_grid_header.to_json
25
+ headers['X-SMTPAPI'] = send_grid_header.to_json if send_grid_header.data.present?
26
26
  mail_without_send_grid(headers, &block)
27
27
  end
28
+
29
+ def open_tracking(enabled = true)
30
+ add_filter_setting(:opentrack, :enabled, enabled ? 1 : 0) unless enabled.nil?
31
+ end
28
32
  end
29
33
  end
30
34
 
@@ -1,4 +1,6 @@
1
1
  class SendGrid::ApiHeader
2
+ attr_reader :data
3
+
2
4
  def initialize
3
5
  @data = {}
4
6
  end
@@ -1,4 +1,4 @@
1
1
  module SendGrid
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
4
4
 
@@ -4,7 +4,12 @@ class Mailer < ActionMailer::Base
4
4
 
5
5
  def email_with_multiple_recipients(recipients)
6
6
  add_recipients recipients
7
- mail
7
+ mail :body => "Hello!"
8
+ end
9
+
10
+ def email_open_tracking(opentrack_enabled = true)
11
+ open_tracking opentrack_enabled
12
+ mail :to => 'email@email.com', :body => 'Hello!'
8
13
  end
9
14
  end
10
15
 
data/spec/mailer_spec.rb CHANGED
@@ -16,5 +16,20 @@ describe Mailer do
16
16
  mail.to.should eq ['group-delivery@sendgrid.com']
17
17
  end
18
18
  end
19
+
20
+ describe '#open_tracking' do
21
+
22
+ it 'set correct open tracking enabled X-SMTAPI header' do
23
+ Mailer.email_open_tracking.to_s.should include('X-SMTPAPI: {"filters":{"opentrack":{"settings":{"enabled":1}}}}')
24
+ end
25
+
26
+ it 'set correct open tracking disabled X-SMTAPI header' do
27
+ Mailer.email_open_tracking(false).to_s.should include('X-SMTPAPI: {"filters":{"opentrack":{"settings":{"enabled":0}}}}')
28
+ end
29
+
30
+ it 'set correct open tracking nil X-SMTAPI header' do
31
+ Mailer.email_open_tracking(nil).to_s.should_not include('X-SMTPAPI: {"filters":{"opentrack')
32
+ end
33
+ end
19
34
  end
20
35
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - PavelTyk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 +02:00
18
+ date: 2011-03-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,6 @@ files:
88
88
  - send_grid.gemspec
89
89
  - spec/api_header_spec.rb
90
90
  - spec/fixtures/mailers/mailer.rb
91
- - spec/fixtures/views/mailer/email_with_multiple_recipients.text.erb
92
91
  - spec/mailer_spec.rb
93
92
  - spec/spec_helper.rb
94
93
  - spec/version_spec.rb