<commit_before>require "net/http"
require "lolsoap"

module ChromeData
  class BaseRequest
    def initialize(attrs={})
      attrs.each do |k, v|
        send "#{k}=", v
      end
    end

    class << self
      # Builds request, sets additional data on request element, makes request,
      # and returns array of child elements wrapped in instances of this class
      def request(data)
        request = build_request

        request.body do |b|
          # Set configured account info on builder
          b.accountInfo(
            number: ChromeData.config.account_number,
            secret: ChromeData.config.account_secret,
            country: ChromeData.config.country,
            language: ChromeData.config.language
          )

          # Set additional elements on builder
          data.each do |k, v|
            # Add the key/value pair as an attribute to the request element if that's what it should be,
            # otherwise add it as a sub-element
            # NOTE: This basically mirrors LolSoap::Builder#method_missing
            #       because Builder undefines most methods, including #send
            if b.__type__.has_attribute?(k)
              b.__attribute__ k, v
            else
              b.__tag__ k, v
            end
          end
        end

        # Make the request
        response = make_request(request)
<commit_msg>Allow param values to be arrays, to enable passing multiple switch values to the describeVehicle call.<commit_after>require "net/http"
require "lolsoap"

module ChromeData
  class BaseRequest
    def initialize(attrs={})
      attrs.each do |k, v|
        send "#{k}=", v
      end
    end

    class << self
      # Builds request, sets additional data on request element, makes request,
      # and returns array of child elements wrapped in instances of this class
      def request(data)
        request = build_request

        request.body do |b|
          # Set configured account info on builder
          b.accountInfo(
            number: ChromeData.config.account_number,
            secret: ChromeData.config.account_secret,
            country: ChromeData.config.country,
            language: ChromeData.config.language
          )

          # Set additional elements on builder
          data.each do |k, v|
            # Add the key/value pair as an attribute to the request element if that's what it should be,
            # otherwise add it as a sub-element
            # NOTE: This basically mirrors LolSoap::Builder#method_missing
            #       because Builder undefines most methods, including #send

            ((v.kind_of? Array) ? v : Array(v)).each do |single_v|
              if b.__type__.has_attribute?(k)
                b.__attribute__ k, single_v
              else
                b.__tag__ k, single_v
              end
            end
          end
        end

        # Make the request
        response = make_request(request)

{'fraction_non_alphanumeric': 0.06481167288768239, 'fraction_numerical': 0.0, 'mean_word_length': 1.8760975609756096, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4602750', 'n_tokens_mistral': 740, 'n_tokens_neox': 729, 'n_words': 274}