<commit_before>require 'net/https'
require 'rexml/document'
require 'logger'

module FreshBooks
  class Connection
    attr_reader :account_url, :auth_token, :utc_offset, :request_headers
    
    @@logger = Logger.new(STDOUT)
    def logger
      @@logger
    end

    def self.log_level=(level)
      @@logger.level = level
    end
    self.log_level = Logger::WARN
    
    def initialize(account_url, auth_token, request_headers = {}, options = {})
      raise InvalidAccountUrlError.new unless account_url =~ /^[0-9a-zA-Z\-_]+\.freshbooks\.com$/
      
      @account_url = account_url
      @auth_token = <PASSWORD>_token
      @request_headers = request_headers
      @utc_offset = options[:utc_offset] || -4
      @start_session_count = 0
    end
    
    def call_api(method, elements = [])
      request = create_request(method, elements)
      result = post(request)
      Response.new(result)
    end
    
    def start_session(&block)
      @connection = obtain_connection if @start_session_count == 0
      @start_session_count = @start_session_count + 1
      
      begin<commit_msg>Added method to directly post xml if necessary<commit_after>require 'net/https'
require 'rexml/document'
require 'logger'

module FreshBooks
  class Connection
    attr_reader :account_url, :auth_token, :utc_offset, :request_headers
    
    @@logger = Logger.new(STDOUT)
    def logger
      @@logger
    end

    def self.log_level=(level)
      @@logger.level = level
    end
    self.log_level = Logger::WARN
    
    def initialize(account_url, auth_token, request_headers = {}, options = {})
      raise InvalidAccountUrlError.new unless account_url =~ /^[0-9a-zA-Z\-_]+\.freshbooks\.com$/
      
      @account_url = account_url
      @auth_token = <PASSWORD>_token
      @request_headers = request_headers
      @utc_offset = options[:utc_offset] || -4
      @start_session_count = 0
    end
    
    def call_api(method, elements = [])
      request = create_request(method, elements)
      result = post(request)
      Response.new(result)
    end
    
    def direct_post(xml)
      result = post(xml)
      Response.new(result)
    end
    
    def start_session(&block)
      @connection = obtain_connection if @start_session_count == 0
      @start_session_count = @start_session_count + 1
      
      begin
{'fraction_non_alphanumeric': 0.1016803102111159, 'fraction_numerical': 0.005170185264971995, 'mean_word_length': 2.83801652892562, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '1334482', 'n_tokens_mistral': 744, 'n_tokens_neox': 717, 'n_words': 154}