From d0a1e89cd3f9fdcd0e7ec02e1b8cfe42d7cbacf6 Mon Sep 17 00:00:00 2001 From: arthurcyliu Date: Fri, 20 Jan 2017 15:47:09 -0800 Subject: [PATCH] adding method for asm_group_id in SendGrid header construction --- lib/sendgrid.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/sendgrid.rb b/lib/sendgrid.rb index 7c68943..db93bfb 100644 --- a/lib/sendgrid.rb +++ b/lib/sendgrid.rb @@ -67,7 +67,7 @@ def sendgrid_enable(*options) self.default_sg_options = Array.new unless self.default_sg_options options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) } end - + # Sets the default text for subscription tracking (must be enabled). # There are two options: # 1. Add an unsubscribe link at the bottom of the email @@ -98,6 +98,12 @@ def sendgrid_unique_args(unique_args = {}) end end + # Call within mailer to set the asm_group_id for group unsubscribe tracking + # https://sendgrid.com/docs/API_Reference/SMTP_API/suppressions.html + def sendgrid_asm_group_id(asm_group_id) + @sg_asm_group_id = asm_group_id + end + # Call within mailer method to override the default value. def sendgrid_category(category) @sg_category = category @@ -161,7 +167,7 @@ def sendgrid_ganalytics_options(options) @ganalytics_options = [] options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) } end - + # only override the appropriate methods for the current ActionMailer version if ActionMailer::Base.respond_to?(:mail) @@ -206,7 +212,7 @@ def sendgrid_json_headers(mail) #if not called within the mailer method, this will be nil so we default to empty hash @sg_unique_args = @sg_unique_args || {} - + # set the unique arguments if @sg_unique_args || self.class.default_sg_unique_args unique_args = self.class.default_sg_unique_args || {} @@ -226,6 +232,9 @@ def sendgrid_json_headers(mail) header_opts[:category] = self.class.default_sg_category end + # Set asm_group_id if set by the user + header_opts[:asm_group_id] = @sg_asm_group_id unless @sg_asm_group_id.blank? + #Set send_at if set by the user header_opts[:send_at] = @sg_send_at unless @sg_send_at.blank?