<commit_before>module Barometer
  module Utils
    class PayloadRequest
      def initialize(api)
        @api = api
      end

      def get
        response = make_request
        output = parse_response(response)
        Payload.new(output, api.current_query)
      end

      private

      def make_request
        Get.call(api.url, api.params)
      end

      def parse_response(response)
        using_around_filters(response) do
          XmlReader.parse(response, *api.unwrap_nodes)
        end
      end

      private

      attr_reader :api

      def using_around_filters(response)
        api.before_parse(response) if api.respond_to?(:before_parse)
        output = yield
        api.after_parse(output) if api.respond_to?(:after_parse)
        output
      end
    end
  end
end<commit_msg>Payload request now supports xml or json api<commit_after>module Barometer
  module Utils
    class PayloadRequest
      def initialize(api)
        @api = api
      end

      def get
        response = make_request
        output = parse_response(response)
        Payload.new(output, api.current_query)
      end

      private

      def make_request
        Get.call(api.url, api.params)
      end

      def parse_response(response)
        using_around_filters(response) do
          reader.parse(response, *api.unwrap_nodes)
        end
      end

      private

      attr_reader :api

      def using_around_filters(response)
        api.before_parse(response) if api.respond_to?(:before_parse)
        output = yield
        api.after_parse(output) if api.respond_to?(:after_parse)
        output
      end

      def reader
        json? ? JsonReader : XmlReader
      end

      def json?
        api.respond_to?(:format) && api.format == :json
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06640625, 'fraction_numerical': 0.0, 'mean_word_length': 2.038983050847458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '7471893', 'n_tokens_mistral': 526, 'n_tokens_neox': 507, 'n_words': 122}