<commit_before>module Splunk
  class Session
    attr_reader :site, :key

    def initialize
      @opts = YAML::load(File.open('config.yml'))
      @base_url = "https://#{@opts['host']}:#{@opts['port']}/services"
      @site = RestClient::Resource.new(@base_url, :timeout => 60, :open_timeout => 5)
      @key = authenticate_user
    end

    def authenticate_user
      @auth = @site['/auth/login']
      doc = @auth.post :username=>@opts['username'], :password => @opts['password']
      Result.new(doc).value_for('//sessionKey')
    end

    private :authenticate_user

    def search search_parameters
      search = CGI::escape search_parameters
      result = post "/search/jobs", "search=#{search}"
      Job.new(self, result.value_for('//sid'))
    end

    def post path, payload=nil
      if payload
        doc = @site[path].post payload, :authorization => "Splunk #{@key}"
      else
        doc = @site[path].post :authorization => "Splunk #{@key}"
      end
      Result.new(doc)
    end

    def get path
      doc = @site[path].get :authorization => "Splunk #{@key}"
      Result.new(doc)
    end

  end
end<commit_msg>let the user pass in a configuration file<commit_after>module Splunk
  class Session
    attr_reader :site, :key

    def initialize(file='config.yml')
      @opts = YAML::load(File.open(file))
      @base_url = "https://#{@opts['host']}:#{@opts['port']}/services"
      @site = RestClient::Resource.new(@base_url, :timeout => 60, :open_timeout => 5)
      @key = authenticate_user
    end

    def authenticate_user
      @auth = @site['/auth/login']
      doc = @auth.post :username=>@opts['username'], :password => @opts['password']
      Result.new(doc).value_for('//sessionKey')
    end

    private :authenticate_user

    def search search_parameters
      search = CGI::escape search_parameters
      result = post "/search/jobs", "search=#{search}"
      Job.new(self, result.value_for('//sid'))
    end

    def post path, payload=nil
      if payload
        doc = @site[path].post payload, :authorization => "Splunk #{@key}"
      else
        doc = @site[path].post :authorization => "Splunk #{@key}"
      end
      Result.new(doc)
    end

    def get path
      doc = @site[path].get :authorization => "Splunk #{@key}"
      Result.new(doc)
    end

  end
end
{'fraction_non_alphanumeric': 0.15534400692340977, 'fraction_numerical': 0.0025962786672436176, 'mean_word_length': 2.9054054054054053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '5368093', 'n_tokens_mistral': 761, 'n_tokens_neox': 724, 'n_words': 168}