class NotificationsController

Public Instance Methods

cancel() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 63
def cancel
  notification.cancel

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end
click() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 25
def click
  trackable.click

  # To prevent a bare redirect, validate that the redirect url
  # was generated when the email was sent
  target_url = params[:r]
  target_url = root_url if trackable.email_urls.blank? || !trackable.email_urls.split("\n").index(target_url)

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to append_tracking_params(target_url) }
  end
end
ignore() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 54
def ignore
  notification.ignore

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end
read() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 39
def read
  trackable.read
  respond_with_no_content
end
recent() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 12
def recent
  respond_to do |format|
    format.json { render json: recent_notifications.to_json }
  end
end
unsubscribe() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 44
def unsubscribe
  trackable.unsubscribe

  # TODO you may want to improve the unsubscribe logic here
  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end
view() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 18
def view
  respond_to do |format|
    format.html { render text: notification.email_html }
    format.text { render text: notification.email_text }
  end
end

Protected Instance Methods

append_tracking_params(url) click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 102
def append_tracking_params(url)
  return url if trackable.do_not_track
  query = []
  query << "utm_campaign=#{utm_campaign}" unless url =~ /utm_campaign/
  query << "utm_medium=#{utm_medium}" unless url =~ /utm_medium/
  query << "utm_source=#{utm_source}" unless url =~ /utm_source/ || utm_source.blank?
  url += (url =~ /\?/) ? "&" : "?"
  url += query.join('&')
end
notification() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 82
def notification
  return @notification if defined?(@notification)
  @notification = current_user.notifications.where(token: params[:token]).first || raise(ActiveRecord::RecordNotFound)
end
require_notification() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 74
def require_notification
  notification
end
require_trackable() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 78
def require_trackable
  trackable
end
respond_with_no_content() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 92
def respond_with_no_content
  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
    format.gif {
      send_data Notifykit.tracking_pixel, :filename => 'blank.gif', :type => 'image/gif', :disposition => 'inline'
    }
  end
end
trackable() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 87
def trackable
  return @trackable if defined?(@trackable)
  @trackable = Notification.where(token: params[:token]).first || raise(ActiveRecord::RecordNotFound)
end
utm_campaign() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 116
def utm_campaign
  trackable.kind
end
utm_medium() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 120
def utm_medium
  "notification"
end
utm_source() click to toggle source
# File lib/generators/notifykit/templates/app/controllers/notifications_controller.rb, line 112
def utm_source
  # TODO insert your company name here or the source of the campaign you would like when the redirect lands
end