<commit_before>module Sepa
   class CertRequest
    def initialize(params)
      @command = params.fetch(:command)
      @sender_id = params.fetch(:customer_id)
      @ar = ApplicationRequest.new(params)

      template_path = File.expand_path('../xml_templates/soap/', __FILE__)

      @body = load_body_template(template_path, @command)
    end

    def to_xml
      construct(@body, @command, @sender_id, @ar).to_xml
    end

    private

      def construct(body, command, sender_id, ar)
        set_body_contents(body, ar, sender_id)
      end

      def load_body_template(template_path, command)
        case command
        when :get_certificate
          path = "#{template_path}/get_certificate.xml"
        else
          fail LoadError, "Could not load soap request template because the" \
            "command was unrecognised"
        end

        body_template = File.open(path)
        body = Nokogiri::XML(body_template)
        body_template.close

        body
      end

      def set_body_contents(body, ar, sender_id)
        set_node(body, 'cer|ApplicationRequest', ar)
        set_node(body, 'cer|SenderId', sender_id)
        set_node(body, 'cer|RequestId', SecureRandom.hex(17))
        set_node(body, 'cer|Timestamp', Time.now.iso8601)
        set_node(body, 'cer|UserAgent',
                 "Sepa Transfer Library version " + VERSION)
      end

      def set_node(doc, node, value)
        doc.at_css(node).content = value
      end
  end
end<commit_msg>Modified for a tight fit into master<commit_after>module Sepa
   class CertRequest
    def initialize(params)
      @command = params.fetch(:command)
      @sender_id = params.fetch(:customer_id)
      @ar = ApplicationRequest.new(params).get_as_base64

      template_path = File.expand_path('../xml_templates/soap/', __FILE__)

      @body = load_body_template(template_path, @command)
    end

    def to_xml
      construct(@body, @command, @sender_id, @ar).to_xml
    end

    private

      def construct(body, command, sender_id, ar)
        set_body_contents(body, ar, sender_id)
      end

      def load_body_template(template_path, command)
        case command
        when :get_certificate
          path = "#{template_path}/get_certificate.xml"
        else
          fail LoadError, "Could not load soap request template because the" \
            "command was unrecognised"
        end

        body_template = File.open(path)
        body = Nokogiri::XML(body_template)
        body_template.close

        body
      end

      def set_body_contents(body, ar, sender_id)
        set_node(body, 'cer|ApplicationRequest', ar)
        set_node(body, 'cer|SenderId', sender_id)
        set_node(body, 'cer|RequestId', SecureRandom.hex(17))
        set_node(body, 'cer|Timestamp', Time.now.iso8601)

        body
      end

      def set_node(doc, node, value)
        doc.at_css(node).content = value
      end
  end
end
{'fraction_non_alphanumeric': 0.09492803289924606, 'fraction_numerical': 0.004797806716929404, 'mean_word_length': 2.551094890510949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '6477667', 'n_tokens_mistral': 907, 'n_tokens_neox': 877, 'n_words': 199}