<commit_before># encoding: utf-8
require 'quirky-api/client/signed_request'

module QuirkyApi
  # The Bouncer module ensures that the API request is valid.  It also removes
  # before_filters that would potentially interfere with the API and sets
  # generic before_filters to be shared across all API's.
  module Bouncer
    include SignedRequest

    def self.included(base)
      if base.respond_to?(:skip_before_filter) &&
         base.respond_to?(:before_filter)

        # error_check allows mobile to send fake error codes.
        base.send :before_filter, :raise_error_check

        base.send :skip_before_filter, :verify_authenticity_token

        # Double checks the API token.
        base.send :before_filter, :valid_api_credentials? if defined? ApiKey

        base.send :before_filter, :validate_client_request
      end
    end

    def validate_client_request
      if client_request?
        return error_response('Invalid request.') unless valid_client_request?
      end
    end

    # Ensures that API credentials are valid.  This may disappear one day.
    def valid_api_credentials?<commit_msg>Guard clause for validate_client_request<commit_after># encoding: utf-8
require 'quirky-api/client/signed_request'

module QuirkyApi
  # The Bouncer module ensures that the API request is valid.  It also removes
  # before_filters that would potentially interfere with the API and sets
  # generic before_filters to be shared across all API's.
  module Bouncer
    include SignedRequest

    def self.included(base)
      if base.respond_to?(:skip_before_filter) &&
         base.respond_to?(:before_filter)

        # error_check allows mobile to send fake error codes.
        base.send :before_filter, :raise_error_check

        base.send :skip_before_filter, :verify_authenticity_token

        # Double checks the API token.
        base.send :before_filter, :valid_api_credentials? if defined? ApiKey

        base.send :before_filter, :validate_client_request
      end
    end

    def validate_client_request
      return unless client_request?
      return error_response('Invalid request.') unless valid_client_request?
    end

    # Ensures that API credentials are valid.  This may disappear one day.
    def valid_api_credentials?
{'fraction_non_alphanumeric': 0.05736981465136805, 'fraction_numerical': 0.00088261253309797, 'mean_word_length': 3.393410852713178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '484241', 'n_tokens_mistral': 646, 'n_tokens_neox': 621, 'n_words': 204}