<commit_before>require 'base64'
require 'faraday'

module Diplomat
  class Service < Diplomat::RestClient

    # Get a service by it's key
    # @param key [String] the key
    # @param scope [Symbol] :first or :all results
    # @param options [Hash] :wait string for wait time and :index for index of last query
    # @param meta [Hash] output structure containing header information about the request (index)
    # @return [OpenStruct] all data associated with the service
    def get key, scope=:first, options=nil, meta=nil

      qs = ""
      sep = "?"
      if options and options[:wait]
        qs = "#{qs}#{sep}wait=#{options[:wait]}"
        sep = "&"
      end
      if options and options[:index]
        qs = "#{qs}#{sep}index=#{options[:index]}"
        sep = "&"
      end

      ret = @conn.get "/v1/catalog/service/#{key}#{qs}"

      if meta and ret.headers
        meta[:index] = ret.headers["x-consul-index"]
        meta[:knownleader] = ret.headers["x-consul-knownleader"]
        meta[:lastcontact] = ret.headers["x-consul-lastcontact"]
      end

      if scope == :all
        return JSON.parse(ret.body).map { |service| OpenStruct.new service }
      end
      return OpenStruct.new JSON.parse(ret.body).first
    end

    # @note This is sugar, see (#get)
    def self.get *args
      Diplomat::Service.new.get *args
    end<commit_msg>added tags into service options<commit_after>require 'base64'
require 'faraday'

module Diplomat
  class Service < Diplomat::RestClient

    # Get a service by it's key
    # @param key [String] the key
    # @param scope [Symbol] :first or :all results
    # @param options [Hash] :wait string for wait time and :index for index of last query
    # @param meta [Hash] output structure containing header information about the request (index)
    # @return [OpenStruct] all data associated with the service
    def get key, scope=:first, options=nil, meta=nil

      qs = ""
      sep = "?"
      if options and options[:wait]
        qs = "#{qs}#{sep}wait=#{options[:wait]}"
        sep = "&"
      end
      if options and options[:index]
        qs = "#{qs}#{sep}index=#{options[:index]}"
        sep = "&"
      end
      if options and options[:tags]
        tags = options[:tags].gsub(',','&tag=')
        qs = "#{qs}#{sep}tag=#{tags}"
        sep = "&"
      end

      ret = @conn.get "/v1/catalog/service/#{key}#{qs}"

      if meta and ret.headers
        meta[:index] = ret.headers["x-consul-index"]
        meta[:knownleader] = ret.headers["x-consul-knownleader"]
        meta[:lastcontact] = ret.headers["x-consul-lastcontact"]
      end

      if scope == :all
        return JSON.parse(ret.body).map { |service| OpenStruct.new service }
      end
      return OpenStruct.new JSON.parse(ret.body).first
    end

    # @note This is sugar, see (#get)
    def self.get *args
      Diplomat::Service.new.get *args
    end
{'fraction_non_alphanumeric': 0.13579820317899102, 'fraction_numerical': 0.002073255010366275, 'mean_word_length': 2.636934673366834, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2607501', 'n_tokens_mistral': 916, 'n_tokens_neox': 887, 'n_words': 263}