lib/ahoy_email/processor.rb in ahoy_email-0.1.5 vs lib/ahoy_email/processor.rb in ahoy_email-0.2.0

- old
+ new

@@ -1,9 +1,7 @@ module AhoyEmail class Processor - include ActionView::Helpers::AssetTagHelper - attr_reader :message, :options, :ahoy_message def initialize(message, options = {}) @message = message @options = options @@ -52,19 +50,17 @@ def track_open if html_part? raw_source = (message.html_part || message).body.raw_source regex = /<\/body>/i url = - AhoyEmail::Engine.routes.url_helpers.url_for( - Rails.application.config.action_mailer.default_url_options.merge( - controller: "ahoy/messages", - action: "open", - id: ahoy_message.token, - format: "gif" - ) + url_for( + controller: "ahoy/messages", + action: "open", + id: ahoy_message.token, + format: "gif" ) - pixel = image_tag(url, size: "1x1", alt: nil) + pixel = ActionController::Base.helpers.image_tag(url, size: "1x1", alt: nil) # try to add before body tag if raw_source.match(regex) raw_source.gsub!(regex, "#{pixel}\\0") else @@ -90,22 +86,18 @@ link["href"] = uri.to_s end if options[:click] and !skip_attribute?(link, "click") signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), AhoyEmail.secret_token, link["href"]) - url = - AhoyEmail::Engine.routes.url_helpers.url_for( - Rails.application.config.action_mailer.default_url_options.merge( - controller: "ahoy/messages", - action: "click", - id: ahoy_message.token, - url: link["href"], - signature: signature - ) + link["href"] = + url_for( + controller: "ahoy/messages", + action: "click", + id: ahoy_message.token, + url: link["href"], + signature: signature ) - - link["href"] = url end end # hacky body.raw_source.sub!(body.raw_source, doc.to_s) @@ -128,10 +120,14 @@ else false end end + def url_for(options) + AhoyEmail::Engine.routes.url_helpers.url_for((ActionMailer::Base.default_url_options || {}).merge(options)) + end + # not a fan of quiet errors # but tracking should *not* break # email delivery in production def report_error(e) if Rails.env.production? @@ -140,6 +136,6 @@ raise e end end end -end \ No newline at end of file +end