<commit_before>module SocialSnippet::Registry::RegistryResources

  require "rest_client"
  require "json"

  class Base

    attr_reader :social_snippet
    attr_reader :rest_client
    attr_reader :protocol
    attr_reader :host
    attr_reader :api_version
    attr_reader :end_point
    attr_reader :cookies
    attr_reader :default_headers

    def initialize(new_social_snippet)
      @social_snippet = new_social_snippet
      @host           = social_snippet.config.get(:sspm_host)
      @api_version    = social_snippet.config.get(:sspm_version)
      @protocol       = social_snippet.config.get(:sspm_protocol)
      @end_point      = "#{protocol}://#{host}/api/#{api_version}"
      @rest_client    = ::RestClient::Resource.new(end_point)
      @cookies        = {}
      @default_headers = {
        :accept => :json,
      }

      social_snippet.logger.debug "registry: end-point = #{end_point}"
    end

    def post(req_path, params, headers = {})
      social_snippet.logger.debug "registry: post: #{req_path}"
      social_snippet.logger.debug params
      csrf_token = fetch_csrf_token

      # set headers
      headers.merge! default_headers
      headers["Content-Type"] = "application/json"
      headers["X-CSRF-Token"] = csrf_token

      # debug output
      social_snippet.logger.debug "registry: post: csrf_token = #{csrf_token}"
      social_snippet.logger.debug "registry: post: headers:"
      social_snippet.logger.debug headers

      parse_response rest_client[req_path].post(params.to_json, headers)
    end

    def get(req_path, headers = {})
      social_snippet.logger.debug "registry: get #{req_path}"
      headers.merge! default_headers
      social_snippet.logger.debug "registry: headers:"
      social_snippet.logger.debug headers
      parse_response rest_client[req_path].get(headers)
    end

    private

    def fetch_csrf_token
      unless @csrf_token
        @csrf_token = get("token")
        default_headers.merge! :cookies => cookies
      end
      @csrf_token
    end

    def parse_response(res)
      cookies.merge! res.cookies
      s = res.to_s
      begin
        ::JSON.parse s
      rescue ::JSON::ParserError
        s
      end
    end

  end # Base

end
<commit_msg>registry_client: use config.sspm_url()<commit_after>module SocialSnippet::Registry::RegistryResources

  require "rest_client"
  require "json"

  class Base

    attr_reader :social_snippet
    attr_reader :rest_client
    attr_reader :end_point
    attr_reader :cookies
    attr_reader :default_headers

    def initialize(new_social_snippet)
      @social_snippet = new_social_snippet
      @end_point      = social_snippet.config.sspm_url
      @rest_client    = ::RestClient::Resource.new(end_point)
      @cookies        = {}
      @default_headers = {
        :accept => :json,
      }

      social_snippet.logger.debug "registry: end-point = #{end_point}"
    end

    def post(req_path, params, headers = {})
      social_snippet.logger.debug "registry: post: #{req_path}"
      social_snippet.logger.debug params
      csrf_token = fetch_csrf_token

      # set headers
      headers.merge! default_headers
      headers["Content-Type"] = "application/json"
      headers["X-CSRF-Token"] = csrf_token

      # debug output
      social_snippet.logger.debug "registry: post: csrf_token = #{csrf_token}"
      social_snippet.logger.debug "registry: post: headers:"
      social_snippet.logger.debug headers

      parse_response rest_client[req_path].post(params.to_json, headers)
    end

    def get(req_path, headers = {})
      social_snippet.logger.debug "registry: get #{req_path}"
      headers.merge! default_headers
      social_snippet.logger.debug "registry: headers:"
      social_snippet.logger.debug headers
      parse_response rest_client[req_path].get(headers)
    end

    private

    def fetch_csrf_token
      unless @csrf_token
        @csrf_token = get("token")
        default_headers.merge! :cookies => cookies
      end
      @csrf_token
    end

    def parse_response(res)
      cookies.merge! res.cookies
      s = res.to_s
      begin
        ::JSON.parse s
      rescue ::JSON::ParserError
        s
      end
    end

  end # Base

end

{'fraction_non_alphanumeric': 0.09451436713369746, 'fraction_numerical': 0.0, 'mean_word_length': 2.8221415607985483, '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': '2491596', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1297, 'n_words': 252}