sendgrid 0.1.1 → 0.1.2

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/README.textile CHANGED
@@ -93,6 +93,8 @@ Here are a list of supported options for sendgrid_enable and sendgrid_disable:
93
93
  * :gravatar
94
94
  * :subscriptiontrack
95
95
  ** Call sendgrid_subscriptiontrack_text(:html => 'Unsubscribe <% Here %>', :plain => 'Unsubscribe Here: <% %>') to set a custom format for html/plain or both.
96
+ ** OR Call sendgrid_subscriptiontrack_text(:replace => '.unsubscribe_link.') to replace all occurrences of .unsubscribe_link. with the url of the unsubscribe link
97
+
96
98
  * :footer
97
99
  ** Call sendgrid_footer_text(:html => 'My HTML footer rocks!', :plain => 'My plain text footer is so-so.') to set custom footer text for html/plain or both.
98
100
  * :spamcheck
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/sendgrid.rb CHANGED
@@ -9,7 +9,8 @@ module SendGrid
9
9
  :gravatar,
10
10
  :subscriptiontrack,
11
11
  :footer,
12
- :spamcheck
12
+ :spamcheck,
13
+ :bypass_list_management
13
14
  ]
14
15
 
15
16
  def self.included(base)
@@ -51,8 +52,11 @@ module SendGrid
51
52
  end
52
53
 
53
54
  # Sets the default text for subscription tracking (must be enabled).
54
- # Should be a hash containing the html/plain text versions:
55
- # {:html => "html version", :plain => "plan text version"}
55
+ # There are two options:
56
+ # 1. Add an unsubscribe link at the bottom of the email
57
+ # {:html => "Unsubscribe <% here %>", :plain => "Unsubscribe here: <% %>"}
58
+ # 2. Replace given text with the unsubscribe link
59
+ # {:replace => "<unsubscribe_link>" }
56
60
  def sendgrid_subscriptiontrack_text(texts)
57
61
  self.default_subscriptiontrack_text = texts
58
62
  end
@@ -119,6 +123,11 @@ module SendGrid
119
123
  # Sets the custom X-SMTPAPI header after creating the email but before delivery
120
124
  def create!(method_name, *parameters)
121
125
  super
126
+ if @sg_substitutions && !@sg_substitutions.empty?
127
+ @sg_substitutions.each do |find, replace|
128
+ raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != mail.to.size
129
+ end
130
+ end
122
131
  puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
123
132
  @mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
124
133
  end
@@ -165,7 +174,7 @@ module SendGrid
165
174
  header_opts[:filters] = filters_hash_from_options(enabled_opts, @sg_disabled_options)
166
175
  end
167
176
 
168
- header_opts.to_json
177
+ header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
169
178
  end
170
179
 
171
180
  def filters_hash_from_options(enabled_opts, disabled_opts)
@@ -175,11 +184,19 @@ module SendGrid
175
184
  case opt.to_sym
176
185
  when :subscriptiontrack
177
186
  if @subscriptiontrack_text
178
- filters[:subscriptiontrack]['settings']['text/html'] = @subscriptiontrack_text[:html]
179
- filters[:subscriptiontrack]['settings']['text/plain'] = @subscriptiontrack_text[:plain]
187
+ if @subscription_text[:replace]
188
+ filters[:subscriptiontrack]['settings']['replace'] = @subscription_text[:replace]
189
+ else
190
+ filters[:subscriptiontrack]['settings']['text/html'] = @subscriptiontrack_text[:html]
191
+ filters[:subscriptiontrack]['settings']['text/plain'] = @subscriptiontrack_text[:plain]
192
+ end
180
193
  elsif self.class.default_subscriptiontrack_text
181
- filters[:subscriptiontrack]['settings']['text/html'] = self.class.default_subscriptiontrack_text[:html]
182
- filters[:subscriptiontrack]['settings']['text/plain'] = self.class.default_subscriptiontrack_text[:plain]
194
+ if self.class.default_subscriptiontrack_text[:replace]
195
+ filters[:subscriptiontrack]['settings']['replace'] = self.class.default_subscriptiontrack_text[:replace]
196
+ else
197
+ filters[:subscriptiontrack]['settings']['text/html'] = self.class.default_subscriptiontrack_text[:html]
198
+ filters[:subscriptiontrack]['settings']['text/plain'] = self.class.default_subscriptiontrack_text[:plain]
199
+ end
183
200
  end
184
201
 
185
202
  when :footer
@@ -1,7 +1,24 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SendgridTest < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ def setup
5
+ @options = {
6
+ :to => ['test@example.com'],
7
+ :from => 'test@example.com',
8
+ :reply_to => 'reply-to@example.com',
9
+ :subject => 'The Subject',
10
+ :html_content => '<html>content</html>',
11
+ :category => 'MyCategory',
12
+ :substitutions => {
13
+ 'first_name' => ['Joe'],
14
+ 'last_name' => ['Schmoe', 'Cool']
15
+ }
16
+ }
17
+ end
18
+
19
+ should "require the same number of items in a substitution array as is in the recipient array" do
20
+ assert_raise ArgumentError do
21
+ test_email = SendgridCampaignTestMailer.create_test(@options)
22
+ end
6
23
  end
7
24
  end
data/test/test_helper.rb CHANGED
@@ -5,6 +5,51 @@ require 'shoulda'
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'sendgrid'
8
+ require 'action_mailer'
8
9
 
9
10
  class Test::Unit::TestCase
10
11
  end
12
+
13
+ class SendgridCampaignTestMailer < ActionMailer::Base
14
+ include SendGrid
15
+
16
+ sendgrid_enable :opentrack, :clicktrack, :subscriptiontrack, :bypass_list_management
17
+
18
+ REQUIRED_OPTIONS = [:to, :from, :category, :html_content, :subject]
19
+
20
+ ##
21
+ # options are:
22
+ # :from the from address
23
+ # :to an array of recipients
24
+ # :substitutions a hash of substitutions of the form: 'text to be
25
+ # replaced' => [replacements]. The order and size of the replacement
26
+ # array must match the :to array
27
+ # :category the sendgrid category used for tracking
28
+ # :html_content, :text_content, :subject
29
+ def test(options)
30
+ handle_sendgrid_options(options)
31
+ recipients(options[:to])
32
+ from(options[:from])
33
+ reply_to(options[:reply_to])
34
+ subject(options[:subject])
35
+ body(options[:html_content])
36
+ end
37
+
38
+ protected
39
+ def handle_sendgrid_options(options)
40
+ REQUIRED_OPTIONS.each do |option|
41
+ raise ArgumentError.new("Required sendgrid option ':#{option}' missing") unless options[option]
42
+ end
43
+
44
+ sendgrid_recipients(options[:to])
45
+
46
+ if options[:substitutions]
47
+ options[:substitutions].each do |find, replace|
48
+ sendgrid_substitute(find, replace)
49
+ end
50
+ end
51
+
52
+
53
+ sendgrid_category(options[:category])
54
+ end
55
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Stephen Blankenship
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-02 00:00:00 -07:00
17
+ date: 2010-03-24 00:00:00 -06:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -47,18 +52,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
52
  requirements:
48
53
  - - ">="
49
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
50
57
  version: "0"
51
- version:
52
58
  required_rubygems_version: !ruby/object:Gem::Requirement
53
59
  requirements:
54
60
  - - ">="
55
61
  - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
56
64
  version: "0"
57
- version:
58
65
  requirements: []
59
66
 
60
67
  rubyforge_project:
61
- rubygems_version: 1.3.5
68
+ rubygems_version: 1.3.6
62
69
  signing_key:
63
70
  specification_version: 3
64
71
  summary: A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)