Skip to content

feat: Add missing bypass list management settings to mail settings #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
828 changes: 434 additions & 394 deletions USAGE.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/helpers/mail/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def kitchen_sink

mail_settings = MailSettings.new
mail_settings.bcc = BccSettings.new(enable: true, email: '[email protected]')
mail_settings.bypass_bounce_management = BypassBounceManagement.new(enable: true)
mail_settings.bypass_list_management = BypassListManagement.new(enable: true)
mail_settings.bypass_spam_management = BypassSpamManagement.new(enable: true)
mail_settings.bypass_unsubscribe_management = BypassUnsubscribeManagement.new(enable: true)
mail_settings.footer = Footer.new(enable: true, text: 'Footer Text', html: '<html><body>Footer Text</body></html>')
mail_settings.sandbox_mode = SandBoxMode.new(enable: true)
mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: 'https://spamcatcher.sendgrid.com')
Expand Down
9 changes: 9 additions & 0 deletions examples/mail/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@
"email": "[email protected]",
"enable": true
},
"bypass_bounce_management": {
"enable": true
},
"bypass_list_management": {
"enable": true
},
"bypass_spam_management": {
"enable": true
},
"bypass_unsubscribe_management": {
"enable": true
},
"footer": {
"enable": true,
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
Expand Down
3 changes: 3 additions & 0 deletions lib/sendgrid-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
require_relative 'sendgrid/helpers/mail/asm'
require_relative 'sendgrid/helpers/mail/attachment'
require_relative 'sendgrid/helpers/mail/bcc_settings'
require_relative 'sendgrid/helpers/mail/bypass_bounce_management'
require_relative 'sendgrid/helpers/mail/bypass_list_management'
require_relative 'sendgrid/helpers/mail/bypass_spam_management'
require_relative 'sendgrid/helpers/mail/bypass_unsubscribe_management'
require_relative 'sendgrid/helpers/mail/category'
require_relative 'sendgrid/helpers/mail/click_tracking'
require_relative 'sendgrid/helpers/mail/content'
Expand Down
17 changes: 17 additions & 0 deletions lib/sendgrid/helpers/mail/bypass_bounce_management.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'json'

module SendGrid
class BypassBounceManagement
attr_accessor :enable

def initialize(enable: nil)
@enable = enable
end

def to_json(*)
{
'enable' => enable
}.delete_if { |_, value| value.to_s.strip == '' }
end
end
end
17 changes: 17 additions & 0 deletions lib/sendgrid/helpers/mail/bypass_spam_management.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'json'

module SendGrid
class BypassSpamManagement
attr_accessor :enable

def initialize(enable: nil)
@enable = enable
end

def to_json(*)
{
'enable' => enable
}.delete_if { |_, value| value.to_s.strip == '' }
end
end
end
17 changes: 17 additions & 0 deletions lib/sendgrid/helpers/mail/bypass_unsubscribe_management.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'json'

module SendGrid
class BypassUnsubscribeManagement
attr_accessor :enable

def initialize(enable: nil)
@enable = enable
end

def to_json(*)
{
'enable' => enable
}.delete_if { |_, value| value.to_s.strip == '' }
end
end
end
20 changes: 19 additions & 1 deletion lib/sendgrid/helpers/mail/mail_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

module SendGrid
class MailSettings
attr_writer :sandbox_mode, :footer, :bcc, :spam_check, :bypass_list_management
attr_writer :sandbox_mode, :footer, :bcc, :spam_check, :bypass_list_management, :bypass_spam_management, :bypass_bounce_management, :bypass_unsubscribe_management

def initialize
@bcc = nil
@bypass_bounce_management = nil
@bypass_list_management = nil
@bypass_spam_management = nil
@bypass_unsubscribe_management = nil
@footer = nil
@sandbox_mode = nil
@spam_check = nil
Expand All @@ -20,6 +23,18 @@ def bypass_list_management
@bypass_list_management.nil? ? nil : @bypass_list_management.to_json
end

def bypass_spam_management
@bypass_spam_management.nil? ? nil : @bypass_spam_management.to_json
end

def bypass_bounce_management
@bypass_bounce_management.nil? ? nil : @bypass_bounce_management.to_json
end

def bypass_unsubscribe_management
@bypass_unsubscribe_management.nil? ? nil : @bypass_unsubscribe_management.to_json
end

def footer
@footer.nil? ? nil : @footer.to_json
end
Expand All @@ -35,7 +50,10 @@ def spam_check
def to_json(*)
{
'bcc' => bcc,
'bypass_bounce_management' => bypass_bounce_management,
'bypass_list_management' => bypass_list_management,
'bypass_spam_management' => bypass_spam_management,
'bypass_unsubscribe_management' => bypass_unsubscribe_management,
'footer' => footer,
'sandbox_mode' => sandbox_mode,
'spam_check' => spam_check
Expand Down
5 changes: 4 additions & 1 deletion test/sendgrid/helpers/mail/test_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def test_kitchen_sink

mail_settings = MailSettings.new
mail_settings.bcc = BccSettings.new(enable: true, email: '[email protected]')
mail_settings.bypass_bounce_management = BypassBounceManagement.new(enable: true)
mail_settings.bypass_list_management = BypassListManagement.new(enable: true)
mail_settings.bypass_spam_management = BypassSpamManagement.new(enable: true)
mail_settings.bypass_unsubscribe_management = BypassUnsubscribeManagement.new(enable: true)
mail_settings.footer = Footer.new(enable: true, text: 'Footer Text', html: '<html><body>Footer Text</body></html>')
mail_settings.sandbox_mode = SandBoxMode.new(enable: true)
mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: 'https://spamcatcher.sendgrid.com')
Expand All @@ -115,7 +118,7 @@ def test_kitchen_sink
mail.reply_to = Email.new(email: '[email protected]')

# rubocop:disable Layout/LineLength
assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"<html><body>some text here</body></html>"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"[email protected]"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"[email protected]","enable":true},"bypass_list_management":{"enable":true},"footer":{"enable":true,"html":"<html><body>Footer Text</body></html>","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]},{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]}],"reply_to":{"email":"[email protected]"},"sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"send_at":1443636842,"subject":"Hello World from the Twilio SendGrid Ruby Library","template_id":"13b8f94f-bcae-4ec6-b752-70d6cb59f932","tracking_settings":{"click_tracking":{"enable":false,"enable_text":false},"ganalytics":{"enable":true,"utm_campaign":"some campaign","utm_content":"some content","utm_medium":"some medium","utm_source":"some source","utm_term":"some term"},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"html":"html to insert into the text/html portion of the message","substitution_tag":"Optional tag to replace with the open image in the body of the message","text":"text to insert into the text/plain portion of the message"}}}'))
assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"<html><body>some text here</body></html>"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"[email protected]"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"[email protected]","enable":true},"bypass_bounce_management":{"enable":true"},"bypass_list_management":{"enable":true},"bypass_spam_management":{"enable":true"},"bypass_unsubscribe_management":{"enable":true"},"footer":{"enable":true,"html":"<html><body>Footer Text</body></html>","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]},{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]}],"reply_to":{"email":"[email protected]"},"sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"send_at":1443636842,"subject":"Hello World from the Twilio SendGrid Ruby Library","template_id":"13b8f94f-bcae-4ec6-b752-70d6cb59f932","tracking_settings":{"click_tracking":{"enable":false,"enable_text":false},"ganalytics":{"enable":true,"utm_campaign":"some campaign","utm_content":"some content","utm_medium":"some medium","utm_source":"some source","utm_term":"some term"},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"html":"html to insert into the text/html portion of the message","substitution_tag":"Optional tag to replace with the open image in the body of the message","text":"text to insert into the text/plain portion of the message"}}}'))
# rubocop:enable all
end

Expand Down
9 changes: 9 additions & 0 deletions test/sendgrid/test_sendgrid-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,18 @@ def test_mail_send_post
"email": "[email protected]",
"enable": true
},
"bypass_bounce_management": {
"enable": true
},
"bypass_list_management": {
"enable": true
},
"bypass_spam_management": {
"enable": true
},
"bypass_unsubscribe_management": {
"enable": true
},
"footer": {
"enable": true,
"html": "<p>Thanks</br>The SendGrid Team</p>",
Expand Down