class Kentico::Kontent::Delivery::QueryParameters::ParameterBase

Base class for all parameters added to a DeliveryQuery. All QueryParameters will appear in the query string.

Constants

SEPARATOR

Attributes

key[RW]

Public Class Methods

new(key, operator, values, eq_sign = true) click to toggle source

Constructor.

  • Args:

    • key (string) The field to filter upon

    • operator (string) The Kentico Kontent filter being applied to the field, in brackets

    • values (Object) One or more values which will appear as the value of the query string parameter

    • eq_sign (boolean) If false, the equals sign is not generated in the parameter

# File lib/delivery/query_parameters/parameter_base.rb, line 20
def initialize(key, operator, values, eq_sign = true)
  self.key = key
  values = [values] unless values.respond_to? :each
  @values = values
  @operator = operator
  @eq_sign = eq_sign
end

Public Instance Methods

provide_query_string_parameter() click to toggle source

Converts the object into a valid query string parameter for use in a request to Delivery. The key, operator, and values are all escaped and if there are multiple values, they are joined with commas.

  • Returns:

    • string A query string parameter without any additional characters (e.g. '&')

# File lib/delivery/query_parameters/parameter_base.rb, line 34
def provide_query_string_parameter
  escaped_values = []
  @values.each { |n| escaped_values << CGI.escape(n.to_s) }
  if @eq_sign 
    format(
      '%<k>s%<o>s=%<v>s',
      k: CGI.escape(key),
      o: CGI.escape(@operator),
      v: escaped_values.join(SEPARATOR)
    )
  else
    format(
      '%<k>s%<o>s',
      k: CGI.escape(key),
      o: CGI.escape(@operator)
    )
  end
end