Class: ProductTours::InteractionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/product_tours/interactions_controller.rb

Constant Summary collapse

SIGNALS =
%w[viewed dismissed completed].freeze

Instance Method Summary collapse

Instance Method Details

#resolveObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/product_tours/interactions_controller.rb', line 7

def resolve
  key = params[:key].to_s
  return handle_unresolved_trigger(key, :disabled) unless ProductTours.enabled?(request)
  return handle_unresolved_trigger(key, :invalid_key) unless key.match?(Tour::KEY_FORMAT)

  tour = find_tour_by_locale(Tour.all, key)
  return handle_unresolved_trigger(key, :missing) unless tour
  return handle_unresolved_trigger(key, :unpublished) unless tour.published?

  render json: tour_payload(tour)
end

#signalObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/product_tours/interactions_controller.rb', line 19

def signal
  return head :forbidden unless ProductTours.enabled?(request)

  action = params[:event_action].to_s
  return head :unprocessable_entity unless SIGNALS.include?(action)

  tour = find_tour_by_locale(Tour.published, params[:key].to_s)
  return head :not_found unless tour

  payload = {
    tour_id: tour.id,
    key: tour.key,
    locale: tour.locale,
    page_url: clean_page_url(params[:page_url]),
    source: params[:source].to_s.presence
  }
  event_name = "product_tours.#{action}"
  ActiveSupport::Notifications.instrument(event_name, payload)
  notify_host(event_name, payload)
  head :no_content
end