<commit_before>module Intacct
  class Base < Struct.new(:object, :current_user)
    include Hooks
    define_hook :after_create, :after_update, :after_delete,
      :after_get, :after_send_xml
    after_create :set_intacct_system_id
    after_delete :delete_intacct_system_id
    after_send_xml :set_date_time

    attr_accessor :response, :data

    def initialize *params
      params[0] = OpenStruct.new(params[0]) if params[0].is_a? Hash
      super(*params)
    end

    protected

    def successful?
      if status = response.at('//result//status') and status.content == "success"
        true
      else
        false
      end
    end

    private

    def send_xml
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.request {
          xml.control {
            xml.senderid Intacct.xml_sender_id
            xml.password <PASSWORD>
            xml.controlid "INVOICE XML"
            xml.uniqueid "false"
            xml.dtdversion "2.1"
          }
          xml.operation(transaction: "false") {
            xml.authentication {
              xml.login {
                xml.userid Intacct.app_user_id
                xml.companyid Intacct.app_company_id
                xml.password <PASSWORD>
              }
            }
            xml.content {
              yield xml
            }
          }
        }
      end

      xml = builder.doc.root.to_xml

      url = "https://www.intacct.com/ia/xml/xmlgw.phtml"
      uri = URI(url)

      res = Net::HTTP.post_form(uri, 'xmlrequest' => xml)
      @response = Nokogiri::XML(res.body)
      if successful?
        function = response.at('//result//function').content
        if type = function[/(create|update|get|delete)/]
          run_hook :after_send_xml, type
          run_hook :"after_#{type}"
        end

        if key = response.at('//result//key')
          set_intacct_key key.content
        end
      end
      @response
    end

    def intacct_system_id
      intacct_object_id
    end

    def set_intacct_system_id
      object.intacct_system_id = intacct_object_id
    end

    def delete_intacct_system_id
      object.intacct_system_id = nil
    end

    def set_intacct_key key
      object.intacct_key = key if object.respond_to? :intacct_key
    end
<commit_msg>Move make to private<commit_after>module Intacct
  class Base < Struct.new(:object, :current_user)
    include Hooks
    define_hook :after_create, :after_update, :after_delete,
      :after_get, :after_send_xml
    after_create :set_intacct_system_id
    after_delete :delete_intacct_system_id
    after_send_xml :set_date_time

    attr_accessor :response, :data

    def initialize *params
      params[0] = OpenStruct.new(params[0]) if params[0].is_a? Hash
      super(*params)
    end

    private

    def send_xml
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.request {
          xml.control {
            xml.senderid Intacct.xml_sender_id
            xml.password <PASSWORD>
            xml.controlid "INVOICE XML"
            xml.uniqueid "false"
            xml.dtdversion "2.1"
          }
          xml.operation(transaction: "false") {
            xml.authentication {
              xml.login {
                xml.userid Intacct.app_user_id
                xml.companyid Intacct.app_company_id
                xml.password <PASSWORD>
              }
            }
            xml.content {
              yield xml
            }
          }
        }
      end

      xml = builder.doc.root.to_xml

      url = "https://www.intacct.com/ia/xml/xmlgw.phtml"
      uri = URI(url)

      res = Net::HTTP.post_form(uri, 'xmlrequest' => xml)
      @response = Nokogiri::XML(res.body)
      if successful?
        function = response.at('//result//function').content
        if type = function[/(create|update|get|delete)/]
          run_hook :after_send_xml, type
          run_hook :"after_#{type}"
        end

        if key = response.at('//result//key')
          set_intacct_key key.content
        end
      end
      @response
    end

    def successful?
      if status = response.at('//result//status') and status.content == "success"
        true
      else
        false
      end
    end

    def intacct_system_id
      intacct_object_id
    end

    def set_intacct_system_id
      object.intacct_system_id = intacct_object_id
    end

    def delete_intacct_system_id
      object.intacct_system_id = nil
    end

    def set_intacct_key key
      object.intacct_key = key if object.respond_to? :intacct_key
    end

{'fraction_non_alphanumeric': 0.08749447635881573, 'fraction_numerical': 0.002209456473707468, 'mean_word_length': 1.8688212927756653, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 54}, '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': '5481337', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1414, 'n_words': 278}