class Kentico::Kontent::Delivery::QueryParameters::QueryString
Represents the entire query string for a request to Delivery
.
Public Class Methods
# File lib/delivery/query_parameters/query_string.rb, line 9 def initialize @params = [] end
Public Instance Methods
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
Returns all parameters from the query string with a matching key.
-
Args:
-
key (
string
) Parameter key
-
-
Returns:
-
Object
One or moreKentico::Kontent::Delivery::QueryParameters::ParameterBase
objects
-
# File lib/delivery/query_parameters/query_string.rb, line 52 def param(key) @params.select { |p| p.key.eql? key } end
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
Adds a parameter to the query string
-
Args:
-
param (
Object
) Either a string representing the key for the parameter, or a completeKentico::Kontent::Delivery::QueryParameters::ParameterBase
object -
values (
string
) A string or array of strings representing the values for the parameter -
operator (
string
)Kentico
Kontent
filtering parameter, placed after the key, before the equal sign
-
# 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
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