Skip to content

Commit

Permalink
Merge pull request stephenb#2 from bcantin/master
Browse files Browse the repository at this point in the history
Remove dependency on Rails version checking.
  • Loading branch information
stephenb committed Sep 8, 2011
2 parents 4331623 + f5f7806 commit e062e5e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/sendgrid.rb
Expand Up @@ -133,38 +133,39 @@ def sendgrid_unique_args(args)
@sg_unique_args = args
end

# only override the appropriet methods for the current rails version
if Rails.version < '3.0.0'
# only override the appropriate methods for the current ActionMailer version
if ActionMailer::Base.respond_to?(:mail)

protected

# Sets the custom X-SMTPAPI header after creating the email but before delivery
# NOTE: This override is used for Rails 2 ActionMailer classes.
def create!(method_name, *parameters)
# NOTE: This override is used for Rails 3 ActionMailer classes.
def mail(headers={}, &block)
super
if @sg_substitutions && !@sg_substitutions.empty?
@sg_substitutions.each do |find, replace|
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
end
end
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
@mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
end

else

protected

# Sets the custom X-SMTPAPI header after creating the email but before delivery
# NOTE: This override is used for Rails 3 ActionMailer classes.
def mail(headers={}, &block)
# NOTE: This override is used for Rails 2 ActionMailer classes.
def create!(method_name, *parameters)
super
if @sg_substitutions && !@sg_substitutions.empty?
@sg_substitutions.each do |find, replace|
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
end
end
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
@mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
end

end

private
Expand Down

0 comments on commit e062e5e

Please sign in to comment.