<commit_before>module TwentyfourSevenOffice
  module Services
    class ApiOperation
      include Virtus.model

      attribute :client, Savon::Client, required: true
      attribute :name, Symbol, required: true
      attribute :input_data_types, Hash[Symbol => Class]
      attribute :session_id, TwentyfourSevenOffice::DataTypes::SessionId

      def call(input_hash)
        opts = {}

        add_inputs(opts, input_hash)
        add_session_cookie(opts)

        response = client.call(name, opts)

        result = response.body["#{name}_response".to_sym]["#{name}_result".to_sym]

        transform_result(result)
      rescue Savon::SOAPFault => e
        raise TwentyfourSevenOffice::Errors::APIError.wrap(e, session_id: session_id, input: input)
      end

      private

      def add_inputs(opts, input_hash)
        if input_hash
          opts[:message] = InputTransformer.transform_input(input_data_types, input_hash)
        end
      end<commit_msg>Change Virtus coercion type for input_data_types<commit_after>module TwentyfourSevenOffice
  module Services
    class ApiOperation
      include Virtus.model

      attribute :client, Savon::Client, required: true
      attribute :name, Symbol, required: true
      attribute :input_data_types, Hash[Symbol => Object]
      attribute :session_id, TwentyfourSevenOffice::DataTypes::SessionId

      def call(input_hash)
        opts = {}

        add_inputs(opts, input_hash)
        add_session_cookie(opts)

        response = client.call(name, opts)

        result = response.body["#{name}_response".to_sym]["#{name}_result".to_sym]

        transform_result(result)
      rescue Savon::SOAPFault => e
        raise TwentyfourSevenOffice::Errors::APIError.wrap(e, session_id: session_id, input: input)
      end

      private

      def add_inputs(opts, input_hash)
        if input_hash
          opts[:message] = InputTransformer.transform_input(input_data_types, input_hash)
        end
      end
{'fraction_non_alphanumeric': 0.08823529411764706, 'fraction_numerical': 0.0, 'mean_word_length': 3.180084745762712, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4622508', 'n_tokens_mistral': 580, 'n_tokens_neox': 554, 'n_words': 120}