Skip to content

Commit

Permalink
feat: add bypass_unsubscribe_management to mail settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gando001 committed Dec 3, 2023
1 parent ae3682b commit fc81363
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,9 @@ data = JSON.parse('{
"bypass_spam_management": {
"enable": true
},
"bypass_unsubscribe_management": {
"enable": true
},
"footer": {
"enable": true,
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
Expand Down
1 change: 1 addition & 0 deletions examples/helpers/mail/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<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
3 changes: 3 additions & 0 deletions examples/mail/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"bypass_spam_management": {
"enable": true
},
"bypass_unsubscribe_management": {
"enable": true
},
"footer": {
"enable": true,
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
Expand Down
1 change: 1 addition & 0 deletions lib/sendgrid-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion lib/sendgrid/helpers/mail/mail_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/sendgrid/helpers/mail/test_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<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 @@ -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":"<html><body>some text here</body></html>"}],"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":"<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":"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":"<html><body>some text here</body></html>"}],"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":"<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":"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

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

0 comments on commit fc81363

Please sign in to comment.