<commit_before>class Twitter::Client
  alias :old_inspect :inspect

  def inspect
    s = old_inspect
    s.gsub!(/@password=".*?"/, '@password="<PASSWORD>"')
    s.gsub!(/"secret"=>".*?"/, '"secret"=>"XXXX"')
    s
  end

  protected
    attr_accessor :login, :oauth_consumer, :oauth_access

    # Returns the response of the OAuth/HTTP(s) request for REST API requests (not Search)
    def rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
      atoken = rest_access_token
      uri = rest_request_uri(path, params)
      if [:get, :delete].include?(method)
        response = atoken.send(method, uri, http_header.merge(headers))
      else
        response = atoken.send(method, uri, params, http_header.merge(headers))
      end
    	handle_rest_response(response)
    	response
    end

    # Returns the response of the OAuth/HTTP(s) request for Search API requests (not REST)
    def search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
      atoken = search_access_token
      uri = search_request_uri(path, params)
      if method == :get
        response = atoken.send(method, uri, http_header.merge(headers))
      end
    	handle_rest_response(response)
    	response
    end

    # "Blesses" model object with client information
    def bless_model(model)
    	model.bless(self) if model
    end
    
    def bless_models(list)
      return bless_model(list) if list.respond_to?(:client=)
    	list.collect { |model| bless_model(model) } if list.respond_to?(:collect)
    end
    
  private
  @@http_header = nil

    def rest_consumer
      unless @rest_consumer
        consumer = @oauth_consumer
        if consumer
          key = consumer[:key] || consumer["key"]
          secret = consumer[:secret] || consumer["secret"]
        end
        cfg = self.class.config
        key ||= cfg.oauth_consumer_token
        secret ||= cfg.oauth_consumer_secret
        @rest_consumer = OAuth::Consumer.new(key, secret, 
                                             :site => construct_site_url,
                                             :proxy => construct_proxy_url)
        http = @rest_consumer.http
        http.read_timeout = cfg.timeout
      end
      @rest_consumer
    end

    def rest_access_token
      unless @rest_access_token
        access = @oauth_access
        if access
          key = access[:key] || access["key"]
          secret = access[:secret] || access["secret"]
        else
          key = ""
          secret = ""
        end
        @rest_access_token = OAuth::AccessToken.new(rest_consumer, key, secret)
      end<commit_msg>Raise error when no access token/secret pair set<commit_after>class Twitter::Client
  alias :old_inspect :inspect

  def inspect
    s = old_inspect
    s.gsub!(/@password=".*?"/, '@password="<PASSWORD>"')
    s.gsub!(/"secret"=>".*?"/, '"secret"=>"XXXX"')
    s
  end

  protected
    attr_accessor :login, :oauth_consumer, :oauth_access

    # Returns the response of the OAuth/HTTP(s) request for REST API requests (not Search)
    def rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
      atoken = rest_access_token
      uri = rest_request_uri(path, params)
      if [:get, :delete].include?(method)
        response = atoken.send(method, uri, http_header.merge(headers))
      else
        response = atoken.send(method, uri, params, http_header.merge(headers))
      end
    	handle_rest_response(response)
    	response
    end

    # Returns the response of the OAuth/HTTP(s) request for Search API requests (not REST)
    def search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
      atoken = search_access_token
      uri = search_request_uri(path, params)
      if method == :get
        response = atoken.send(method, uri, http_header.merge(headers))
      end
    	handle_rest_response(response)
    	response
    end

    # "Blesses" model object with client information
    def bless_model(model)
    	model.bless(self) if model
    end
    
    def bless_models(list)
      return bless_model(list) if list.respond_to?(:client=)
    	list.collect { |model| bless_model(model) } if list.respond_to?(:collect)
    end
    
  private
  @@http_header = nil

    def rest_consumer
      unless @rest_consumer
        consumer = @oauth_consumer
        if consumer
          key = consumer[:key] || consumer["key"]
          secret = consumer[:secret] || consumer["secret"]
        end
        cfg = self.class.config
        key ||= cfg.oauth_consumer_token
        secret ||= cfg.oauth_consumer_secret
        @rest_consumer = OAuth::Consumer.new(key, secret, 
                                             :site => construct_site_url,
                                             :proxy => construct_proxy_url)
        http = @rest_consumer.http
        http.read_timeout = cfg.timeout
      end
      @rest_consumer
    end

    def rest_access_token
      unless @rest_access_token
        access = @oauth_access
        if access
          key = access[:key] || access["key"]
          secret = access[:secret] || access["secret"]
        else
          raise Error, "No access tokens are set"
        end
        @rest_access_token = OAuth::AccessToken.new(rest_consumer, key, secret)
      end
{'fraction_non_alphanumeric': 0.104787033546928, 'fraction_numerical': 0.0, 'mean_word_length': 2.437176165803109, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217972', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1534, 'n_words': 377}