<commit_before>class NanoApi::Backends::ClicksController < NanoApi::ApplicationController
  respond_to :html, :js

  def show
    if @click_params = click_params
      render
    else
      render nothing: true, status: 404
    end
  end

  def link
    if @link_params = link_params
      redirect_to @link_params.try(:[], :url).presence
    else
      render nothing: true, status: 404
    end
  end

  def deeplink
    if @deeplink_params = deeplink_params
      render
    else
      render nothing: true, status: 404
    end
  end

private

  def click_params
    NanoApi.client.click(params[:search_id], params[:id],
      {unique: _uniq_click?('c'), ref_name: params[:ref_name], ref_value: params[:ref_value], fallback: params[:fallback]})
  end

  def link_params
    NanoApi.client.link(params[:search_id], params[:id],
      {:unique => _uniq_click?('l')})
  end

  def deeplink_params
    NanoApi.client.deeplink(params[:search_id], params[:id],
      params.except(:id, :search_id).merge(:unique => _uniq_click?('l')))
  end

  def _uniq_click? scope, gate_id = _gate_id<commit_msg>fix(Clicks) Processing order and airline_deeplink API responses to convert method value into downcase.<commit_after>class NanoApi::Backends::ClicksController < NanoApi::ApplicationController
  respond_to :html, :js

  def show
    if @click_params = click_params
      render
    else
      render nothing: true, status: 404
    end
  end

  def link
    if @link_params = link_params
      redirect_to @link_params.try(:[], :url).presence
    else
      render nothing: true, status: 404
    end
  end

  def deeplink
    if @deeplink_params = deeplink_params
      render
    else
      render nothing: true, status: 404
    end
  end

private

  def click_params
    result = NanoApi.client.click(params[:search_id], params[:id],
      {unique: _uniq_click?('c'), ref_name: params[:ref_name], ref_value: params[:ref_value], fallback: params[:fallback]}
    )

    result[:method].downcase!
    result
  end

  def link_params
    NanoApi.client.link(params[:search_id], params[:id],
      {:unique => _uniq_click?('l')})
  end

  def deeplink_params
    result = NanoApi.client.deeplink(
      params[:search_id],
      params[:id],
      params.except(:id, :search_id).merge(:unique => _uniq_click?('l'))
    )

    result[:method].downcase!
    result
  end

  def _uniq_click? scope, gate_id = _gate_id
{'fraction_non_alphanumeric': 0.11199000832639468, 'fraction_numerical': 0.00749375520399667, 'mean_word_length': 3.4417744916820703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '412114', 'n_tokens_mistral': 842, 'n_tokens_neox': 796, 'n_words': 186}