<commit_before>module AuthOpenApi
  LOGIN_URL = "/api/rest/login"
  LOGOUT_URL = "/api/rest/logout"

  class AuthSession
    def raise_handled_error(code, desc)
      raise OpenApiError::ApiError.new("Auth error: #{code} - #{desc}")
    end

    def initialize(user, pass, base_url)
      @base_url = base_url
      @user = user
      @pass = pass
    end

    def session
      @session ||= login
    end

    def login
      params = {
        user: @user,
        pass: <PASSWORD>,
        output: "json"
      }
      uri = URI("#{@base_url}#{LOGIN_URL}")

      response = Net::HTTP.start(uri.host, uri.port,
                      :use_ssl => uri.scheme == 'https') do |http|

        request = Net::HTTP::Post.new uri.to_s

        http.request request # Net::HTTPResponse object
      end

      if error = OpenApiError::ERROR_CODES[response.code.to_s]
        raise_handled_error(response.code, error)
      elsif %w{0 200}.include?(response.code.to_s)

        data = JSON.parse(response.body)<commit_msg>fix login regression<commit_after>module AuthOpenApi
  LOGIN_URL = "/api/rest/login"
  LOGOUT_URL = "/api/rest/logout"

  class AuthSession
    def raise_handled_error(code, desc)
      raise OpenApiError::ApiError.new("Auth error: #{code} - #{desc}")
    end

    def initialize(user, pass, base_url)
      @base_url = base_url
      @user = user
      @pass = <PASSWORD>
    end

    def session
      @session ||= login
    end

    def login
      params = {
        user: @user,
        pass: <PASSWORD>,
        output: "json"
      }
      uri = URI("#{@base_url}#{LOGIN_URL}")

      response = Net::HTTP.start(uri.host, uri.port,
                      :use_ssl => uri.scheme == 'https') do |http|

        request = Net::HTTP::Post.new uri.to_s
        request.set_form_data(params)

        http.request request # Net::HTTPResponse object
      end

      if error = OpenApiError::ERROR_CODES[response.code.to_s]
        raise_handled_error(response.code, error)
      elsif %w{0 200}.include?(response.code.to_s)

        data = JSON.parse(response.body)
{'fraction_non_alphanumeric': 0.12554112554112554, 'fraction_numerical': 0.003848003848003848, 'mean_word_length': 2.360258481421648, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '1673770', 'n_tokens_mistral': 695, 'n_tokens_neox': 676, 'n_words': 142}