brightbytes-sendgrid 0.1.3 → 0.1.4

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
- ZDA1YWNiMmIxY2JhOTU0NmQxYzcyM2QyZGQ1Y2EyOTU1YmM0MWU3ZA==
4
+ YmQzOGZiYmI2YWUyMmMzNzA0NzljZTg2YzJjYzBkZTA3NGMxZTBmYg==
5
5
  data.tar.gz: !binary |-
6
- ZGQzNzAzZjA4ZWFlN2ZjMDUwZWU0YmZiOTAyOTUzOTkyOWY2OWRjNA==
6
+ ZDAxMDI0MjQ1Y2YxYzE5MDQ4YmFjNTJmYzY4MTY0MTEwMzlmYTdkMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWNmMjlkNzJjMDc4YTI2ZDVkYzI4MDAwYTg5ZTI0ZjZhYjVlYTM3NDQyNGMx
10
- YzdhMjA1MDU2MzlhOGM3ZDk4NWExNThjOWM0ZTk3ZTEwZDYxZWU3NDAzYWM0
11
- ZjIyNTM2NzFlZTM0ODIyZGIxZWMyZDQxZjUyNmFkYzc5Mjk2ZDY=
9
+ OTU3ZDY0OWU0NzY2NDRkYTE5YjU5NTVmY2ZlNTNlN2IyYmIzNmNmMDk2M2Uy
10
+ NDQ2ZmJiNTMyMDcxZmZjZGNlYTFkNGNkZmJhZGU5Mzg4Mjk3ODcwOGE3ZTVl
11
+ MTg0MTA5ZDQxMTMyYmZkZDI1ZTQyYWEzODMxOGE1MWUyZjIxZTE=
12
12
  data.tar.gz: !binary |-
13
- ZDFiM2RlMWU3YmY0ZGNlYzAyZTUxMGZhYzQ0NzkyZTc5Mzg2ZTVmOWNiM2Ji
14
- OTFkNzQ4MzZiNzBhMWY0NDgyMWJiZWRjYzI5NzMwZWZiZDRiY2Y5MmY3YTkw
15
- ZTYxMDY1N2QxOTE2NjQyODVhMWYyZDFmNjVkNTE4MTUzMDI4YWE=
13
+ NzdlOTc4MDFhN2U5M2M0YWZmMGQ4YWJjNDUzOWEwYTUyODI2YjAyZDc5MjFj
14
+ YzdiODIyNmI4ZTJjMmQwMDBhNGNkNDE0OGY1MTllYTg3YWE3NGMzNDU4NzQ0
15
+ YTdlYjM0MmFjZDg0ZjJjY2U1OTk3OTY1MzVlZjhkMWEyNjQwYzc=
data/README.md CHANGED
@@ -94,11 +94,10 @@ So, to make this feature work, you have to:
94
94
 
95
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
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"
97
+ config.html_link "Click <a href="%s">here to unsubscribe</a>"
98
+ # will produce "Click <a href="URL">here to unsubscribe</a>"
99
+ config.text_link "Go there to unsubscribe: %s"
100
+ # will produce "Go there to unsubscribe: URL"
102
101
 
103
102
  ##Contributors
104
103
 
@@ -5,7 +5,7 @@ module Brightbytes
5
5
  class Config
6
6
  include Singleton
7
7
 
8
- attr_accessor :dummy_recipient
8
+ attr_accessor :dummy_recipient, :subst_pattern
9
9
 
10
10
  # Sendgrid default settings storage
11
11
 
@@ -17,13 +17,14 @@ module Brightbytes
17
17
 
18
18
  # Unsubscribe default settings storage
19
19
 
20
- class UnsubscribeConfig < Struct.new(:categories, :url, :html_message, :link_text, :text_message); end
20
+ class UnsubscribeConfig < Struct.new(:categories, :url, :html_link, :text_link); end
21
21
 
22
22
  def unsubscribe
23
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:"
24
+ [],
25
+ nil,
26
+ 'If you would like to unsubscribe and stop receiving these emails <a href="%s" rel="nofollow">click here</a>.',
27
+ 'If you would like to unsubscribe and stop receiving these emails click here: %s'
27
28
  )
28
29
  end
29
30
 
@@ -31,7 +32,7 @@ module Brightbytes
31
32
  unsubscribe.categories = categories.flatten.map(&:to_sym)
32
33
  end
33
34
 
34
- [:url, :html_message, :link_text, :text_message].each do |meth|
35
+ [:url, :html_link, :text_link].each do |meth|
35
36
  class_eval <<-DEF
36
37
  def unsubscribe_#{meth}(value)
37
38
  unsubscribe.#{meth} = value
@@ -3,6 +3,7 @@ require 'json'
3
3
  module Brightbytes
4
4
  module Sendgrid
5
5
  class SmtpApiHeader
6
+ include SubstPattern
6
7
 
7
8
  DELEGATE_METHODS = [
8
9
  :substitute,
@@ -43,9 +44,7 @@ module Brightbytes
43
44
  :utm_term,
44
45
  :utm_content
45
46
  ]
46
-
47
- SUBST_PATTERN = '{{\1}}'
48
-
47
+
49
48
  attr_reader :data
50
49
 
51
50
  def initialize(default_data = nil)
@@ -122,15 +121,11 @@ module Brightbytes
122
121
  end
123
122
 
124
123
  private
125
-
126
- def key_to_tag(key)
127
- key.is_a?(Symbol) ? key.to_s.sub(/(.*)/, SUBST_PATTERN) : key.to_s
128
- end
129
-
124
+
130
125
  def init_array_key(key)
131
126
  @data[key] = [] unless @data[key].instance_of?(Array)
132
127
  end
133
-
128
+
134
129
  end
135
130
  end
136
131
  end
@@ -0,0 +1,20 @@
1
+ module Brightbytes
2
+ module Sendgrid
3
+ module SubstPattern
4
+ extend ActiveSupport::Concern
5
+
6
+ DEFAULT_PATTERN = '{{\1}}'
7
+
8
+ private
9
+
10
+ def key_to_tag(key)
11
+ key.is_a?(Symbol) ? key.to_s.sub(/(.*)/, subst_pattern) : key.to_s
12
+ end
13
+
14
+ def subst_pattern
15
+ Brightbytes::Sendgrid.config.subst_pattern || DEFAULT_PATTERN
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -4,6 +4,7 @@
4
4
  module Brightbytes
5
5
  module Sendgrid
6
6
  class Unsubscribe
7
+ include SubstPattern
7
8
 
8
9
  class << self
9
10
 
@@ -23,11 +24,11 @@ module Brightbytes
23
24
  def add_links
24
25
  return unless feature_active?
25
26
  if categories.present?
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
+ sendgrid.section :unsubscribe_html_section, unsubscribe.html_link % key_to_tag(:unsubscribe_url)
28
+ sendgrid.section :unsubscribe_text_section, unsubscribe.text_link % key_to_tag(:unsubscribe_url)
28
29
  emails.each do |email|
29
- sendgrid.add_substitute :unsubscribe_html, "{{unsubscribe_html_section}}"
30
- sendgrid.add_substitute :unsubscribe_text, "{{unsubscribe_text_section}}"
30
+ sendgrid.add_substitute :unsubscribe_html, key_to_tag(:unsubscribe_html_section)
31
+ sendgrid.add_substitute :unsubscribe_text, key_to_tag(:unsubscribe_text_section)
31
32
  sendgrid.add_substitute :unsubscribe_url, unsubscribe_url(email)
32
33
  end
33
34
  else
@@ -42,7 +43,7 @@ module Brightbytes
42
43
  def unsubscribe
43
44
  Brightbytes::Sendgrid.config.unsubscribe
44
45
  end
45
-
46
+
46
47
  def feature_active?
47
48
  unsubscribe.categories.present? || unsubscribe.url.present?
48
49
  end
@@ -1,5 +1,5 @@
1
1
  module Brightbytes
2
2
  module Sendgrid
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
+ require 'brightbytes/sendgrid/subst_pattern'
3
4
  require 'brightbytes/sendgrid/smtp_api_header'
4
5
  require 'brightbytes/sendgrid/config'
5
6
  require 'brightbytes/sendgrid/unsubscribe'
@@ -62,7 +62,7 @@ describe SendgridMailer do
62
62
  before(:each) { sendgrid_config_setup }
63
63
 
64
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>"')
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>."')
66
66
  end
67
67
 
68
68
  it 'unsubscribe text section should be set' do
@@ -36,7 +36,7 @@ describe StandardMailer do
36
36
  before(:each) { sendgrid_config_setup }
37
37
 
38
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>"')
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
40
  end
41
41
 
42
42
  it 'unsubscribe text section should be set' do
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.3
4
+ version: 0.1.4
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-20 00:00:00.000000000 Z
12
+ date: 2014-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -101,6 +101,7 @@ files:
101
101
  - lib/brightbytes/sendgrid.rb
102
102
  - lib/brightbytes/sendgrid/config.rb
103
103
  - lib/brightbytes/sendgrid/smtp_api_header.rb
104
+ - lib/brightbytes/sendgrid/subst_pattern.rb
104
105
  - lib/brightbytes/sendgrid/unsubscribe.rb
105
106
  - lib/brightbytes/sendgrid/version.rb
106
107
  - spec/brightbytes/sendgrid/smtp_api_header_spec.rb