From fc813638f40d47e708aafd8f7a3ec2403d2f581e Mon Sep 17 00:00:00 2001 From: Kunal Madhav Date: Sun, 3 Dec 2023 11:53:01 +0000 Subject: [PATCH] feat: add bypass_unsubscribe_management to mail settings --- USAGE.md | 3 +++ examples/helpers/mail/example.rb | 1 + examples/mail/mail.rb | 3 +++ lib/sendgrid-ruby.rb | 1 + lib/sendgrid/helpers/mail/mail_settings.rb | 8 +++++++- test/sendgrid/helpers/mail/test_mail.rb | 3 ++- test/sendgrid/test_sendgrid-ruby.rb | 3 +++ 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 2a9dae6a..6a05c58c 100644 --- a/USAGE.md +++ b/USAGE.md @@ -2284,6 +2284,9 @@ data = JSON.parse('{ "bypass_spam_management": { "enable": true }, + "bypass_unsubscribe_management": { + "enable": true + }, "footer": { "enable": true, "html": "

Thanks
The Twilio SendGrid Team

", diff --git a/examples/helpers/mail/example.rb b/examples/helpers/mail/example.rb index a340a2aa..4d94d627 100644 --- a/examples/helpers/mail/example.rb +++ b/examples/helpers/mail/example.rb @@ -107,6 +107,7 @@ def kitchen_sink 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: 'Footer Text') 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') diff --git a/examples/mail/mail.rb b/examples/mail/mail.rb index 7aa01aa6..ee09a8ae 100644 --- a/examples/mail/mail.rb +++ b/examples/mail/mail.rb @@ -81,6 +81,9 @@ "bypass_spam_management": { "enable": true }, + "bypass_unsubscribe_management": { + "enable": true + }, "footer": { "enable": true, "html": "

Thanks
The Twilio SendGrid Team

", diff --git a/lib/sendgrid-ruby.rb b/lib/sendgrid-ruby.rb index 9f2adb78..06b6e936 100644 --- a/lib/sendgrid-ruby.rb +++ b/lib/sendgrid-ruby.rb @@ -10,6 +10,7 @@ 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' diff --git a/lib/sendgrid/helpers/mail/mail_settings.rb b/lib/sendgrid/helpers/mail/mail_settings.rb index 5915886b..88adb154 100644 --- a/lib/sendgrid/helpers/mail/mail_settings.rb +++ b/lib/sendgrid/helpers/mail/mail_settings.rb @@ -2,13 +2,14 @@ module SendGrid class MailSettings - attr_writer :sandbox_mode, :footer, :bcc, :spam_check, :bypass_list_management, :bypass_spam_management, :bypass_bounce_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 @@ -30,6 +31,10 @@ 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 @@ -48,6 +53,7 @@ def to_json(*) '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 diff --git a/test/sendgrid/helpers/mail/test_mail.rb b/test/sendgrid/helpers/mail/test_mail.rb index bb5fa074..7c4f35cb 100644 --- a/test/sendgrid/helpers/mail/test_mail.rb +++ b/test/sendgrid/helpers/mail/test_mail.rb @@ -102,6 +102,7 @@ def test_kitchen_sink 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: 'Footer Text') 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') @@ -117,7 +118,7 @@ def test_kitchen_sink mail.reply_to = Email.new(email: 'test@example.com') # 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":"some text here"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","enable":true},"bypass_bounce_management":{"enable":true"},"bypass_list_management":{"enable":true},"bypass_spam_management":{"enable":true"},"footer":{"enable":true,"html":"Footer Text","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]},{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]}],"reply_to":{"email":"test@example.com"},"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":"some text here"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","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":"Footer Text","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]},{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]}],"reply_to":{"email":"test@example.com"},"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 diff --git a/test/sendgrid/test_sendgrid-ruby.rb b/test/sendgrid/test_sendgrid-ruby.rb index 10f3d807..c9731ece 100644 --- a/test/sendgrid/test_sendgrid-ruby.rb +++ b/test/sendgrid/test_sendgrid-ruby.rb @@ -1181,6 +1181,9 @@ def test_mail_send_post "bypass_spam_management": { "enable": true }, +"bypass_unsubscribe_management": { + "enable": true +}, "footer": { "enable": true, "html": "

Thanks
The SendGrid Team

",