Class: ProductTours::ToursController

Inherits:
ApplicationController show all
Defined in:
app/controllers/product_tours/tours_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/tours_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?(Post::KEY_FORMAT)

  post = find_post_by_locale(Post.all, key)
  return handle_unresolved_trigger(key, :missing) unless post
  return handle_unresolved_trigger(key, :unpublished) unless post.published?

  render json: post_payload(post)
end

#signalObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/product_tours/tours_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)

  post = find_post_by_locale(Post.published, params[:key].to_s)
  return head :not_found unless post

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