<commit_before>module ActiveZuora

  class Connection

    attr_reader :soap_client

    def initialize(configuration)
      # Store login credentials and create SOAP client.
      @username = configuration[:username]
      @password = configuration[:password]
      @session_timeout = configuration[:session_timeout] || 15.minutes
      @soap_client = Savon::Client.new do
        wsdl.document = configuration[:wsdl_document]
      end
    end

    def start_session
      # instance variables aren't available within the soap request block for some reason.
      body = { :username => @username, :password => <PASSWORD> }
      response = @soap_client.request(:login) do
        soap.body = body
      end
      if response.success?
        @session_expires_at = Time.now + @session_timeout
        @session_id = response.to_hash[:login_response][:result][:session]
      end
      response
    end

    def session_expired?
      @session_id.nil? || @session_expires_at <= Time.now
    end

    def request *args
      # Login if we know ahead of time that our session has timed out.
      if session_expired?
        start_session_response = start_session
        # Return the error response if the start_session failed.
        return start_session_response.to_hash unless start_session_response.success?
      end<commit_msg>Added a default wsdl file if not specified<commit_after>module ActiveZuora

  class Connection

    attr_reader :soap_client

    WSDL = File.expand_path('../../../wsdl/zuora.wsdl', __FILE__)

    def initialize(configuration={})
      # Store login credentials and create SOAP client.
      @username = configuration[:username]
      @password = configuration[:password]
      @session_timeout = configuration[:session_timeout] || 15.minutes
      @soap_client = Savon::Client.new do
        wsdl.document = configuration[:wsdl] || WSDL
      end
    end

    def start_session
      # instance variables aren't available within the soap request block for some reason.
      body = { :username => @username, :password => <PASSWORD> }
      response = @soap_client.request(:login) do
        soap.body = body
      end
      if response.success?
        @session_expires_at = Time.now + @session_timeout
        @session_id = response.to_hash[:login_response][:result][:session]
      end
      response
    end

    def session_expired?
      @session_id.nil? || @session_expires_at <= Time.now
    end

    def request *args
      # Login if we know ahead of time that our session has timed out.
      if session_expired?
        start_session_response = start_session
        # Return the error response if the start_session failed.
        return start_session_response.to_hash unless start_session_response.success?
      end
{'fraction_non_alphanumeric': 0.08001448225923244, 'fraction_numerical': 0.001448225923244026, 'mean_word_length': 2.8970380818053596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1184774', 'n_tokens_mistral': 766, 'n_tokens_neox': 733, 'n_words': 216}