<commit_before>module Tuiter

  class Client
    include Tuiter::StatusMethods
    include Tuiter::UserMethods
    include Tuiter::DirectMessageMethods
    include Tuiter::FriendshipMethods
    include Tuiter::SocialGraphMethods
    include Tuiter::AccountMethods

    attr_accessor :username, :password
    
    def initialize(options = {})
      @pid = Process.pid
      @logger = options[:logger] || Logger.new('tuiter.log')
      @username = options[:username]
      @password = options[:password]
      @use_proxy = setup_a_proxy?
      log("initialize()")
    end

    private
    def request(url)
      http = nil
      status = Timeout::timeout(10) do
        log("request() query: #{url}")
        http = open(url, :http_basic_authentication=>[@username, @password])
        log("request() debug: http status is #{http.status.join(' ')}")
        if http.status == ["200", "OK"]
          res = http.read
          return res
        end
        return nil        
      end
    rescue Timeout::Error
      log("request() error: timeout error")
      return nil
    rescue OpenURI::HTTPError => e
      log("request() http error: #{e.message} in #{e.backtrace.first.to_s}")
      return nil
    rescue Exception => e
      log("request() error: #{e.message} in #{e.backtrace.first.to_s}")
      return nil
    end
   
    def parse_options(options)
      if options[:since]
        params = "?since=#{options[:since]}"
      elsif options[:since_id]
        params = "?since_id=#{options[:since_id]}"
      else
        params = ""
      end

      if options[:page]
        if params == ""
            params = "?page=#{options[:page]}"
        else
            params = params + "&" + "page=#{options[:page]}"
        end
      end

      return params
    end

    def setup_a_proxy?
      http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || nil
      
      if http_proxy
        proxy = URI.parse(http_proxy)

        @proxy_host = proxy.host<commit_msg>Improvements on parse_options<commit_after>module Tuiter

  class Client
    include Tuiter::StatusMethods
    include Tuiter::UserMethods
    include Tuiter::DirectMessageMethods
    include Tuiter::FriendshipMethods
    include Tuiter::SocialGraphMethods
    include Tuiter::AccountMethods

    attr_accessor :username, :password
    
    def initialize(options = {})
      @pid = Process.pid
      @logger = options[:logger] || Logger.new('tuiter.log')
      @username = options[:username]
      @password = options[:password]
      @use_proxy = setup_a_proxy?
      log("initialize()")
    end

    private
    def request(url)
      http = nil
      status = Timeout::timeout(10) do
        log("request() query: #{url}")
        http = open(url, :http_basic_authentication => [@username, @password])
        log("request() debug: http status is #{http.status.join(' ')}")
        if http.status == ["200", "OK"]
          res = http.read
          return res
        end
        return nil        
      end
    rescue Timeout::Error
      log("request() error: timeout error")
      return nil
    rescue OpenURI::HTTPError => e
      log("request() http error: #{e.message} in #{e.backtrace.first.to_s}")
      return nil
    rescue Exception => e
      log("request() error: #{e.message} in #{e.backtrace.first.to_s}")
      return nil
    end
   
    def parse_options(options)
      params = ""

      options.each do |k, v|
        unless params.empty?
          params = params + "&#{k}=#{v}"
        else  
          params = "?#{k}=#{v}"
        end
      end if (options && !options.empty?)

      return params
    end

    def setup_a_proxy?
      http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || nil
      
      if http_proxy
        proxy = URI.parse(http_proxy)

        @proxy_host = proxy.host
{'fraction_non_alphanumeric': 0.12625197680548234, 'fraction_numerical': 0.002635740643120717, 'mean_word_length': 2.3465608465608465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6159978', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1136, 'n_words': 271}