diff --git a/lib/sendgrid.rb b/lib/sendgrid.rb index 7c68943..92d5e78 100644 --- a/lib/sendgrid.rb +++ b/lib/sendgrid.rb @@ -161,7 +161,12 @@ def sendgrid_ganalytics_options(options) @ganalytics_options = [] options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) } end - + + # Call within mailer method to set unsubscribe_group_id + def sendgrid_unsubscribe_group_id(unsubscribe_group_id) + @sg_asm_group_id = unsubscribe_group_id + end + # only override the appropriate methods for the current ActionMailer version if ActionMailer::Base.respond_to?(:mail) @@ -206,7 +211,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 || {} @@ -254,6 +259,9 @@ def sendgrid_json_headers(mail) header_opts[:filters] = filters if filters && !filters.empty? end + # Set unsubscribe group + header_opts[:asm_group_id] = @sg_asm_group_id if @sg_asm_group_id + header_opts.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3') end diff --git a/sendgrid.gemspec b/sendgrid.gemspec index ff125f0..a33430b 100644 --- a/sendgrid.gemspec +++ b/sendgrid.gemspec @@ -45,20 +45,17 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.5.1"]) - s.add_runtime_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.5.1"]) - s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.5.1"]) - s.add_dependency(%q, [">= 0"]) end end