<commit_before>require 'httparty'

module Utils
  # Please burn in hell dear rubocop
  # Best Regards
  # Your Mama
  # (fat)
  class AppdbReader
    APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'.freeze
    APPDB_REQUEST_ALL = 'https://appdb-pi.egi.eu/rest/1.0/sites?listmode=details&flt=%2B%3Dsite.supports%3A1%20'\
                        '%2B%3Dsite.hasinstances%3A1%0A'.freeze

    class << self
      def appdb_raw_request
        HTTParty.get(APPDB_REQUEST_ALL)
      end

      def all(options = {})
        response = options[:appdb_raw] || appdb_raw_request
        response.success? ? parse_appdb_response(response.parsed_response) : nil
      end

      private

      def parse_appdb_response(response)
        sites = response['appdb']['site'].collect
        sites.collect do |site|
          [site['service']].flatten.collect do |service|
            next unless service['type'] == 'occi'
            parse_service(site, service)
          end
        end.flatten.compact
      end

      def parse_service(site, service)
        {<commit_msg>COMMENT utils/appdb_reader.rb: fixed module comment<commit_after>require 'httparty'

module Utils
  # Utility class for connection to appdb and extracting iformation about sites/appliances/flavours
  class AppdbReader
    APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'.freeze
    APPDB_REQUEST_ALL = 'https://appdb-pi.egi.eu/rest/1.0/sites?listmode=details&flt=%2B%3Dsite.supports%3A1%20'\
                        '%2B%3Dsite.hasinstances%3A1%0A'.freeze

    class << self
      def appdb_raw_request
        HTTParty.get(APPDB_REQUEST_ALL)
      end

      def all(options = {})
        response = options[:appdb_raw] || appdb_raw_request
        response.success? ? parse_appdb_response(response.parsed_response) : nil
      end

      private

      def parse_appdb_response(response)
        sites = response['appdb']['site'].collect
        sites.collect do |site|
          [site['service']].flatten.collect do |service|
            next unless service['type'] == 'occi'
            parse_service(site, service)
          end
        end.flatten.compact
      end

      def parse_service(site, service)
        {
{'fraction_non_alphanumeric': 0.10795974382433669, 'fraction_numerical': 0.011893870082342177, 'mean_word_length': 2.5970394736842106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '3796322', 'n_tokens_mistral': 720, 'n_tokens_neox': 709, 'n_words': 124}