def get(key, options = {}, not_found = :reject, found = :return)
      key_subst = if key.start_with? '/'
                    key[1..-1]
                  else
                    key.freeze
                  end
      @key = key_subst
      @options = options
      custom_params = []
      custom_params << recurse_get(@options)
      custom_params << use_consistency(options)
      custom_params << dc(@options)
      custom_params << keys(@options)
      custom_params << separator(@options)

      return_nil_values = @options && @options[:nil_values]
      transformation = @options && @options[:transformation] && @options[:transformation].methods.find_index(:call) ? @options[:transformation] : nil

      raw = send_get_request(@conn_no_err, ["/v1/kv/#{@key}"], options, custom_params)
      if raw.status == 404
        case not_found
        when :reject
          raise Diplomat::KeyNotFound, key
        when :return
          return @value = ''
        when :wait
          index = raw.headers['x-consul-index']
        end
      elsif raw.status == 200
        case found
        when :reject
          raise Diplomat::KeyAlreadyExists, key
        when :return
          @raw = raw
          @raw = parse_body
          return @raw.first['ModifyIndex'] if @options && @options[:modify_index]
          return @raw.first['Session'] if @options && @options[:session]
          return decode_values if @options && @options[:decode_values]
          return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]

          return return_value(return_nil_values, transformation)
        when :wait
          index = raw.headers['x-consul-index']
        end
      else
        raise Diplomat::UnknownStatus, "status #{raw.status}: #{raw.body}"
      end

      # Wait for first/next value
      custom_params << use_named_parameter('index', index)
      if options.nil?
        options = { timeout: 86_400 }
      else
        options[:timeout] = 86_400
      end
      @raw = send_get_request(@conn, ["/v1/kv/#{@key}"], options, custom_params)
      @raw = parse_body
      return_value(return_nil_values, transformation)
    end
def get(key, options = {}, not_found = :reject, found = :return)
      key_subst = if key.start_with? '/'
                    key[1..-1]
                  else
                    key.freeze
                  end
      @key = key_subst
      @options = options
      custom_params = []
      custom_params << recurse_get(@options)
      custom_params << use_consistency(options)
      custom_params << dc(@options)
      custom_params << keys(@options)
      custom_params << separator(@options)

      return_nil_values = @options && @options[:nil_values]
      transformation = @options && @options[:transformation] && @options[:transformation].methods.find_index(:call) ? @options[:transformation] : nil

      raw = send_get_request(@conn_no_err, ["/v1/kv/#{@key}"], options, custom_params)
      if raw.status == 404
        case not_found
        when :reject
          raise Diplomat::KeyNotFound, key
        when :return
          return @value = ''
        when :wait
          index = raw.headers['x-consul-index']
        end
      elsif raw.status == 200
        case found
        when :reject
          raise Diplomat::KeyAlreadyExists, key
        when :return
          @raw = raw
          @raw = parse_body
          return @raw.first['ModifyIndex'] if @options && @options[:modify_index]
          return @raw.first['Session'] if @options && @options[:session]
          return decode_values if @options && @options[:decode_values]
          return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]

          return return_value(return_nil_values, transformation)
        when :wait
          index = raw.headers['x-consul-index']
        end
      else
        raise Diplomat::UnknownStatus, "status #{raw.status}: #{raw.body}"
      end

      # Wait for first/next value
      custom_params << use_named_parameter('index', index)
      if options.nil?
        options = { timeout: 86_400 }
      else
        options[:timeout] = 86_400
      end
      @raw = send_get_request(@conn, ["/v1/kv/#{@key}"], options, custom_params)
      @raw = parse_body
      return_value(return_nil_values, transformation)
    end
Get a value by its key, potentially blocking for the first or next value
 @param key [String] the key
 @param options [Hash] the query params
 @option options [Boolean] :recurse If to make recursive get or not
 @option options [String] :consistency The read consistency type
 @option options [String] :dc Target datacenter
 @option options [Boolean] :keys Only return key names.
 @option options [Boolean] :modify_index Only return ModifyIndex value.
 @option options [Boolean] :session Only return Session value.
 @option options [Boolean] :decode_values Return consul response with decoded values.
 @option options [String] :separator List only up to a given separator.
   Only applies when combined with :keys option.
 @option options [Boolean] :nil_values If to return keys/dirs with nil values
 @option options [Boolean] :convert_to_hash Take the data returned from consul and build a hash
 @option options [Callable] :transformation funnction to invoke on keys values
 @param not_found [Symbol] behaviour if the key doesn't exist;
   :reject with exception, :return degenerate value, or :wait for it to appear
 @param found [Symbol] behaviour if the key does exist;
   :reject with exception, :return its current value, or :wait for its next value
 @return [String] The base64-decoded value associated with the key
 @note
   When trying to access a key, there are two possibilites:
   - The key doesn't (yet) exist
   - The key exists. This may be its first value, there is no way to tell
   The combination of not_found and found behaviour gives maximum possible
   flexibility. For X: reject, R: return, W: wait
   - X X - meaningless; never return a value
   - X R - "normal" non-blocking get operation. Default
   - X W - get the next value only (must have a current value)
   - R X - meaningless; never return a meaningful value
   - R R - "safe" non-blocking, non-throwing get-or-default operation
   - R W - get the next value or a default
   - W X - get the first value only (must not have a current value)
   - W R - get the first or current value; always return something, but
           block only when necessary
   - W W - get the first or next value; wait until there is an update
 rubocop:disable PerceivedComplexity, MethodLength, LineLength, CyclomaticComplexity