Class: Nuntius::MessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/nuntius/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

GET /messages/:message_id/link?url=…



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/nuntius/messages_controller.rb', line 28

def link
  url = params[:url]

  if external? && @message&.link_tracking_enabled? && url.present?
    # Record the first click time
    @message.clicked_at ||= Time.current
    @message.click_count = (@message.click_count || 0) + 1
    @message.save

    tracking = @message.message_trackings.find_or_create_by(url: url)
    tracking.count = (tracking.count || 0) + 1
    tracking.save!
  end

  # Redirect to the original URL
  if url.present?
    redirect_to url, allow_other_host: true
  else
    head :not_found
  end
end

#pixelObject

GET /messages/:message_id/pixel.gif



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/nuntius/messages_controller.rb', line 15

def pixel
  if external? && @message&.open_tracking_enabled?
    # Record the first open time
    @message.opened_at ||= Time.current
    @message.open_count = (@message.open_count || 0) + 1
    @message.save
  end

  # Return a 1x1 transparent GIF pixel
  send_data(Base64.decode64("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"), type: "image/gif", disposition: "inline")
end

#showObject



11
12
# File 'app/controllers/nuntius/messages_controller.rb', line 11

def show
end