Class: Kentico::Kontent::Delivery::QueryParameters::ParameterBase
- Inherits:
-
Object
- Object
- Kentico::Kontent::Delivery::QueryParameters::ParameterBase
- Defined in:
- lib/delivery/query_parameters/parameter_base.rb
Overview
Base class for all parameters added to a DeliveryQuery. All QueryParameters will appear in the query string.
Direct Known Subclasses
Constant Summary collapse
- SEPARATOR =
CGI.escape(',')
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key, operator, values) ⇒ ParameterBase
constructor
Constructor.
-
#provide_query_string_parameter ⇒ Object
Converts the object into a valid query string parameter for use in a request to Delivery.
Constructor Details
#initialize(key, operator, values) ⇒ ParameterBase
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
-
17 18 19 20 21 22 |
# File 'lib/delivery/query_parameters/parameter_base.rb', line 17 def initialize(key, operator, values) self.key = key values = [values] unless values.respond_to? :each @values = values @operator = operator end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/delivery/query_parameters/parameter_base.rb', line 8 def key @key end |
Instance Method Details
#provide_query_string_parameter ⇒ Object
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. ‘&’)
-
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/delivery/query_parameters/parameter_base.rb', line 30 def provide_query_string_parameter escaped_values = [] @values.each { |n| escaped_values << CGI.escape(n.to_s) } format( '%<k>s%<o>s=%<v>s', k: CGI.escape(key), o: CGI.escape(@operator), v: escaped_values.join(SEPARATOR) ) end |