brightbytes-sendgrid 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2U2NTdjZDQ5OWM5NjRhZWE5MjFjNGViYTc2MDI3ZGFlMWM4N2IwNw==
4
+ ZDA1YWNiMmIxY2JhOTU0NmQxYzcyM2QyZGQ1Y2EyOTU1YmM0MWU3ZA==
5
5
  data.tar.gz: !binary |-
6
- M2YwNjgwM2JhYzBhNWJiMWZjZGYzZWNlNjU0M2UxODBjOWI4NDQ2Yg==
6
+ ZGQzNzAzZjA4ZWFlN2ZjMDUwZWU0YmZiOTAyOTUzOTkyOWY2OWRjNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjVhNWVmMzg1OTU1ZDdmYjZjNGVhZTU0NjBlYWU1NTQ1YWJkODMyNDc2MTQ1
10
- ZTNlYTUzZTAyYmY2YmUxMmNiYzQ1MmMzOTFlNDg2NGU2MTlmNjViMDk1YmI2
11
- MzE4NzlmZGZkNmRiZDY0ZjBmNGY0MzlkMjIyOGY5MjJhZjFlMzk=
9
+ NWNmMjlkNzJjMDc4YTI2ZDVkYzI4MDAwYTg5ZTI0ZjZhYjVlYTM3NDQyNGMx
10
+ YzdhMjA1MDU2MzlhOGM3ZDk4NWExNThjOWM0ZTk3ZTEwZDYxZWU3NDAzYWM0
11
+ ZjIyNTM2NzFlZTM0ODIyZGIxZWMyZDQxZjUyNmFkYzc5Mjk2ZDY=
12
12
  data.tar.gz: !binary |-
13
- MDE4ZGMwNmUxNzUyODNjNzk5ZWE3Mzc0YTgyOTRlMTgzNzUzN2U0Y2UyODc2
14
- YmVlM2IxODUzNjczYzdlN2Q1NmU2ZGRlZjc4NzE4NWFmMWY1MmNlNTNkZDhl
15
- Mjc0NTMwNzI4MDU5YTVjMmVmZTgyNmE5N2ZlZDBmNjVlMDc3ZDM=
13
+ ZDFiM2RlMWU3YmY0ZGNlYzAyZTUxMGZhYzQ0NzkyZTc5Mzg2ZTVmOWNiM2Ji
14
+ OTFkNzQ4MzZiNzBhMWY0NDgyMWJiZWRjYzI5NzMwZWZiZDRiY2Y5MmY3YTkw
15
+ ZTYxMDY1N2QxOTE2NjQyODVhMWYyZDFmNjVkNTE4MTUzMDI4YWE=
data/README.md CHANGED
@@ -70,6 +70,10 @@ You can use following methods to set both global and per-email SendGrid SMTP API
70
70
 
71
71
  sendgrid_disable :clicktrack
72
72
 
73
+ **sendgrid_bcc**
74
+
75
+ sendgrid_bcc 'some@email.com'
76
+
73
77
  ## Auto generated unsubscribe link
74
78
 
75
79
  It is not a SendGrid **subscriptiontrack** filter!
@@ -80,8 +84,21 @@ Those links will be sent as a substitutions to SendGrid.
80
84
  So, to make this feature work, you have to:
81
85
 
82
86
  1. Configure unsubscribe categories. It will trigger link generator
87
+
88
+ config.unsubscribe_categories [:newsletter, :notifications]
89
+
83
90
  2. Configure an unsubscribe_url. The resulting URL will be composed of unsubscribe_url and email and category parameters.
84
- 3. Put {{unsubscribe}} placeholder somewhere in your email body
91
+
92
+ config.unsubscribe_url 'http://domain.com/unsubscribe'
93
+ config.unsubscribe_url Proc.new { |params| your_way_to_build_the_url(params) }
94
+
95
+ 3. Put {{unsubscribe_html}} or {{unsubscribe_text}} or {{unsubcribe_url}} placeholder somewhere in your email body. You can adjust how html and text version are built:
96
+
97
+ config.unsubcribe_html_message "Click here to"
98
+ config.unsubcribe_link_text "unsubcribe"
99
+ # will produce "Click here to <a href="url">unsubscribe</a>"
100
+ config.unsubcribe_text_message "Go there to unsubscribe:"
101
+ # will produce "Go there to unsubscribe: url"
85
102
 
86
103
  ##Contributors
87
104
 
@@ -17,20 +17,28 @@ module Brightbytes
17
17
 
18
18
  # Unsubscribe default settings storage
19
19
 
20
- class UnsubscribeConfig < Struct.new(:categories, :url); end
20
+ class UnsubscribeConfig < Struct.new(:categories, :url, :html_message, :link_text, :text_message); end
21
21
 
22
22
  def unsubscribe
23
- @unsubscribe ||= UnsubscribeConfig.new([],nil)
23
+ @unsubscribe ||= UnsubscribeConfig.new(
24
+ [], nil,
25
+ "If you would like to unsubscribe and stop receiving these emails", "click here",
26
+ "If you would like to unsubscribe and stop receiving these emails click here:"
27
+ )
24
28
  end
25
29
 
26
30
  def unsubscribe_categories(*categories)
27
31
  unsubscribe.categories = categories.flatten.map(&:to_sym)
28
32
  end
29
33
 
30
- def unsubscribe_url(url)
31
- unsubscribe.url = url
34
+ [:url, :html_message, :link_text, :text_message].each do |meth|
35
+ class_eval <<-DEF
36
+ def unsubscribe_#{meth}(value)
37
+ unsubscribe.#{meth} = value
38
+ end
39
+ DEF
32
40
  end
33
-
41
+
34
42
  end
35
43
  end
36
44
  end
@@ -23,30 +23,32 @@ module Brightbytes
23
23
  def add_links
24
24
  return unless feature_active?
25
25
  if categories.present?
26
- sendgrid.section :unsubscribe, "<a href=\"{{unsubscribe_link}}\">Unsubscribe</a>"
26
+ sendgrid.section :unsubscribe_html_section, "#{unsubscribe.html_message} <a href=\"{{unsubscribe_url}}\" rel=\"nofollow\">#{unsubscribe.link_text}</a>"
27
+ sendgrid.section :unsubscribe_text_section, "#{unsubscribe.text_message} {{unsubscribe_url}}"
27
28
  emails.each do |email|
28
- sendgrid.add_substitute :unsubscribe_link, unsubscribe_link(email)
29
+ sendgrid.add_substitute :unsubscribe_html, "{{unsubscribe_html_section}}"
30
+ sendgrid.add_substitute :unsubscribe_text, "{{unsubscribe_text_section}}"
31
+ sendgrid.add_substitute :unsubscribe_url, unsubscribe_url(email)
29
32
  end
30
33
  else
31
- sendgrid.section :unsubscribe, ''
32
- sendgrid.add_substitute :unsubscribe_link, Array.new(emails.size, '')
34
+ sendgrid.add_substitute :unsubscribe_html, Array.new(emails.size, '')
35
+ sendgrid.add_substitute :unsubscribe_text, Array.new(emails.size, '')
36
+ sendgrid.add_substitute :unsubscribe_url, Array.new(emails.size, '')
33
37
  end
34
38
  end
35
39
 
36
40
  private
37
41
 
38
- def config
42
+ def unsubscribe
39
43
  Brightbytes::Sendgrid.config.unsubscribe
40
44
  end
41
45
 
42
- delegate :categories, :url, to: :config, prefix: :unsubscribe
43
-
44
46
  def feature_active?
45
- unsubscribe_categories.present? || unsubscribe_url.present?
47
+ unsubscribe.categories.present? || unsubscribe.url.present?
46
48
  end
47
49
 
48
50
  def categories
49
- @categories ||= unsubscribe_categories & sendgrid.categories
51
+ @categories ||= unsubscribe.categories & sendgrid.categories
50
52
  end
51
53
 
52
54
  def emails
@@ -60,12 +62,12 @@ module Brightbytes
60
62
  def message_recipients
61
63
  Array.wrap(message.to) + Array.wrap(message.cc) + Array.wrap(message.bcc)
62
64
  end
63
-
64
- def unsubscribe_link(email)
65
- if unsubscribe_url.instance_of? Proc
66
- unsubscribe_url.call(email: email, category: categories)
65
+
66
+ def unsubscribe_url(email)
67
+ if unsubscribe.url.instance_of? Proc
68
+ unsubscribe.url.call(email: email, category: categories)
67
69
  else
68
- "#{unsubscribe_url}#{unsubscribe_url[-1] == '?' ? '' : '?'}#{url_parameters(email)}"
70
+ "#{unsubscribe.url}#{unsubscribe.url[-1] == '?' ? '' : '?'}#{url_parameters(email)}"
69
71
  end
70
72
  end
71
73
 
@@ -1,5 +1,5 @@
1
1
  module Brightbytes
2
2
  module Sendgrid
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -42,9 +42,17 @@ describe SendgridMailer do
42
42
  subject(:message) { described_class.unsubscribe_not_required }
43
43
 
44
44
  before(:each) { sendgrid_config_setup }
45
-
46
- it 'unsubscribe section should be empty' do
47
- header.should include('"{{unsubscribe}}": ""')
45
+
46
+ it 'unsubscribe html version should be empty' do
47
+ header.should include('"{{unsubscribe_html}}": ["",""]')
48
+ end
49
+
50
+ it 'unsubscribe text version should be empty' do
51
+ header.should include('"{{unsubscribe_text}}": ["",""]')
52
+ end
53
+
54
+ it 'unsubscribe url should be empty' do
55
+ header.should include('"{{unsubscribe_url}}": ["",""]')
48
56
  end
49
57
  end
50
58
 
@@ -53,12 +61,24 @@ describe SendgridMailer do
53
61
 
54
62
  before(:each) { sendgrid_config_setup }
55
63
 
56
- it 'unsubscribe section should be set' do
57
- header.should include('"{{unsubscribe}}": "<a href=\"{{unsubscribe_link}}\">Unsubscribe</a>"')
64
+ it 'unsubscribe html section should be set' do
65
+ header.should include('"{{unsubscribe_html_section}}": "If you would like to unsubscribe and stop receiving these emails <a href=\"{{unsubscribe_url}}\" rel=\"nofollow\">click here</a>"')
58
66
  end
59
-
60
- it 'unsubscribe link should be set' do
61
- header.should include('"{{unsubscribe_link}}": ["http://example.com/u?email=email1%40email.com&category=unsubscribe","http://example.com/u?email=email2%40email.com&category=unsubscribe"]')
67
+
68
+ it 'unsubscribe text section should be set' do
69
+ header.should include('"{{unsubscribe_text_section}}": "If you would like to unsubscribe and stop receiving these emails click here: {{unsubscribe_url}}"')
70
+ end
71
+
72
+ it 'unsubscribe html version should be set' do
73
+ header.should include('"{{unsubscribe_html}}": ["{{unsubscribe_html_section}}","{{unsubscribe_html_section}}"]')
74
+ end
75
+
76
+ it 'unsubscribe text version should be set' do
77
+ header.should include('"{{unsubscribe_text}}": ["{{unsubscribe_text_section}}","{{unsubscribe_text_section}}"]')
78
+ end
79
+
80
+ it 'unsubscribe url should be set' do
81
+ header.should include('"{{unsubscribe_url}}": ["http://example.com/u?email=email1%40email.com&category=unsubscribe","http://example.com/u?email=email2%40email.com&category=unsubscribe"]')
62
82
  end
63
83
  end
64
84
 
@@ -17,8 +17,16 @@ describe StandardMailer do
17
17
 
18
18
  before(:each) { sendgrid_config_setup }
19
19
 
20
- it 'unsubscribe section should be empty' do
21
- header.should include('"{{unsubscribe}}": ""')
20
+ it 'unsubscribe html version should be empty' do
21
+ header.should include('"{{unsubscribe_html}}": [""]')
22
+ end
23
+
24
+ it 'unsubscribe text version should be empty' do
25
+ header.should include('"{{unsubscribe_text}}": [""]')
26
+ end
27
+
28
+ it 'unsubscribe url should be empty' do
29
+ header.should include('"{{unsubscribe_url}}": [""]')
22
30
  end
23
31
  end
24
32
 
@@ -27,12 +35,24 @@ describe StandardMailer do
27
35
 
28
36
  before(:each) { sendgrid_config_setup }
29
37
 
30
- it 'unsubscribe section should be set' do
31
- header.should include('"{{unsubscribe}}": "<a href=\"{{unsubscribe_link}}\">Unsubscribe</a>"')
38
+ it 'unsubscribe html section should be set' do
39
+ header.should include('"{{unsubscribe_html_section}}": "If you would like to unsubscribe and stop receiving these emails <a href=\"{{unsubscribe_url}}\" rel=\"nofollow\">click here</a>"')
40
+ end
41
+
42
+ it 'unsubscribe text section should be set' do
43
+ header.should include('"{{unsubscribe_text_section}}": "If you would like to unsubscribe and stop receiving these emails click here: {{unsubscribe_url}}"')
44
+ end
45
+
46
+ it 'unsubscribe html version should be set' do
47
+ header.should include('"{{unsubscribe_html}}": ["{{unsubscribe_html_section}}"]')
48
+ end
49
+
50
+ it 'unsubscribe text version should be set' do
51
+ header.should include('"{{unsubscribe_text}}": ["{{unsubscribe_text_section}}"]')
32
52
  end
33
53
 
34
- it 'unsubscribe link should be set' do
35
- header.should include('"{{unsubscribe_link}}": ["http://example.com/u?email=email%40email.com&category=unsubscribe"]')
54
+ it 'unsubscribe url should be set' do
55
+ header.should include('"{{unsubscribe_url}}": ["http://example.com/u?email=email%40email.com&category=unsubscribe"]')
36
56
  end
37
57
  end
38
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbytes-sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brightbytes Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-17 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler