<commit_before>module Carbon
  class EmissionEstimate
    class Request
      attr_reader :parent

      def initialize(parent)
        @parent = parent
      end

      def body
        params.to_query
      end

      def params
        params = send "#{parent.mode}_params"
        validate(params)
        params
      end

      def validate(params_hash)
        unless params_hash.key? :key
          Carbon.warn 'You have not specified an API key. Please obtain a key from http://keys.brighterplanet.com.'
        end
      end

      def async_params # :nodoc:
        raise ::ArgumentError, "When using :callback you cannot specify :defer" if parent.defer? and parent.callback
        raise ::ArgumentError, "When using :defer => true you must specify :guid" if parent.defer? and parent.guid.blank?
        hash = _params
        hash[:emitter] = parent.emitter.class.carbon_base.emitter_common_name
        hash[:callback] = parent.callback if parent.callback
        hash[:callback_content_type] = parent.callback_content_type if parent.callback<commit_msg>Memoize params so that multiple requests aren't made needlessly<commit_after>module Carbon
  class EmissionEstimate
    class Request
      attr_reader :parent

      def initialize(parent)
        @parent = parent
      end

      def body
        params.to_query
      end

      def params
        return @params unless @params.nil?
        @params = send "#{parent.mode}_params"
        validate(@params)
        @params
      end

      def validate(params_hash)
        unless params_hash.key? :key
          Carbon.warn 'You have not specified an API key. Please obtain a key from http://keys.brighterplanet.com.'
        end
      end

      def async_params # :nodoc:
        raise ::ArgumentError, "When using :callback you cannot specify :defer" if parent.defer? and parent.callback
        raise ::ArgumentError, "When using :defer => true you must specify :guid" if parent.defer? and parent.guid.blank?
        hash = _params
        hash[:emitter] = parent.emitter.class.carbon_base.emitter_common_name
        hash[:callback] = parent.callback if parent.callback
        hash[:callback_content_type] = parent.callback_content_type if parent.callback
{'fraction_non_alphanumeric': 0.07616487455197132, 'fraction_numerical': 0.0, 'mean_word_length': 2.555732484076433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5614857', 'n_tokens_mistral': 603, 'n_tokens_neox': 581, 'n_words': 189}