class Kentico::Kontent::Delivery::QueryParameters::QueryString

Represents the entire query string for a request to Delivery.

Public Class Methods

new() click to toggle source
# File lib/delivery/query_parameters/query_string.rb, line 9
def initialize
  @params = []
end

Public Instance Methods

empty?() click to toggle source

Checks whether there are any parameters defined.

  • Returns:

    • bool True if there are no parameters set.

# File lib/delivery/query_parameters/query_string.rb, line 60
def empty?
  @params.empty?
end
param(key) click to toggle source

Returns all parameters from the query string with a matching key.

# File lib/delivery/query_parameters/query_string.rb, line 52
def param(key)
  @params.select { |p| p.key.eql? key }
end
remove_param(key) click to toggle source

Removes all parameters from the query string with a matching key.

  • Args:

    • key (string) Parameter key

# File lib/delivery/query_parameters/query_string.rb, line 41
def remove_param(key)
  @params.delete_if { |i| i.key.eql? key }
end
set_param(param, values = '', operator = '') click to toggle source

Adds a parameter to the query string

# File lib/delivery/query_parameters/query_string.rb, line 19
def set_param(param, values = '', operator = '')
  parameter_base =
    if param.is_a? String
      Kentico::Kontent::Delivery::QueryParameters::ParameterBase.new(
        param,
        operator,
        values
      )
    else
      param
    end
  # Ensure we have a ParameterBase object
  return unless parameter_base.respond_to? 'provide_query_string_parameter'

  remove_param parameter_base.key
  @params << parameter_base
end
to_s() click to toggle source

Generates a full query string based on the set parameters, with the required '?' character at the start. Accomplished by calling the Kentico::Kontent::Delivery::QueryParameters::ParameterBase.provide_query_string_parameter method for each parameter.

  • Returns:

    • string A complete query string

# File lib/delivery/query_parameters/query_string.rb, line 71
def to_s
  '?' + @params.map(&:provide_query_string_parameter).join('&')
end