<commit_before>require "savon"

module Vindicia

  # = Vindicia::Model
  #
  # Model for SOAP service oriented applications.
  module Model

    VERSION = "0.0.0"

    module ClassMethods

      def self.extend_object(base)
        super
        base.init_vindicia_model
      end

      def init_vindicia_model
        class_action_module
      end

      def client(&block)
        @client ||= Savon::Client.new &block
      end

      def endpoint(uri)
        client.wsdl.endpoint = uri
      end

      def namespace(uri)
        client.wsdl.namespace = uri
      end

      # Accepts one or more SOAP actions and generates both class and instance methods named
      # after the given actions. Each generated method accepts an optional SOAP body Hash and
      # a block to be passed to <tt>Savon::Client#request</tt> and executes a SOAP request.
      def actions(*actions)
        actions.each do |action|
          define_class_action action
        end
      end

    private
    
      def define_class_action(action)
        escaped_action = !action.to_s.start_with?('_') ? action.to_s : action[1..-1] #chomp leading _, if present
        class_action_module.module_eval <<-CODE
          def #{action.to_s.underscore}(body = {}, &block)
            client.request :tns, #{escaped_action.inspect} do
              soap.namespaces["xmlns:tns"] = vindicia_target_namespace
              http.headers["SOAPAction"] = vindicia_soap_action('#{escaped_action}')
              soap.body = {
                :auth => vindicia_auth_credentials
              }.merge(body)
              block.call(soap, wsdl, http, wsse) if block
            end
          rescue Exception => e
            rescue_exception(:#{action.to_s.underscore}, e)
          end
        CODE<commit_msg>fixed spurious .to_s on escaped action causes savon exception, SOAPAction shall match 'uri#method' if present<commit_after>require "savon"

module Vindicia

  # = Vindicia::Model
  #
  # Model for SOAP service oriented applications.
  module Model

    VERSION = "0.0.0"

    module ClassMethods

      def self.extend_object(base)
        super
        base.init_vindicia_model
      end

      def init_vindicia_model
        class_action_module
      end

      def client(&block)
        @client ||= Savon::Client.new &block
      end

      def endpoint(uri)
        client.wsdl.endpoint = uri
      end

      def namespace(uri)
        client.wsdl.namespace = uri
      end

      # Accepts one or more SOAP actions and generates both class and instance methods named
      # after the given actions. Each generated method accepts an optional SOAP body Hash and
      # a block to be passed to <tt>Savon::Client#request</tt> and executes a SOAP request.
      def actions(*actions)
        actions.each do |action|
          define_class_action action
        end
      end

    private
    
      def define_class_action(action)
        escaped_action = !action.to_s.start_with?('_') ? action : action[1..-1] #chomp leading _, if present
        class_action_module.module_eval <<-CODE
          def #{action.to_s.underscore}(body = {}, &block)
            client.request :tns, #{escaped_action.inspect} do
              soap.namespaces["xmlns:tns"] = vindicia_target_namespace
              http.headers["SOAPAction"] = vindicia_soap_action('#{escaped_action}')
              soap.body = {
                :auth => vindicia_auth_credentials
              }.merge(body)
              block.call(soap, wsdl, http, wsse) if block
            end
          rescue Exception => e
            rescue_exception(:#{action.to_s.underscore}, e)
          end
        CODE
{'fraction_non_alphanumeric': 0.08440668676349684, 'fraction_numerical': 0.0027404768429706767, 'mean_word_length': 2.16017316017316, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2091828', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1031, 'n_words': 279}