kontent-delivery-sdk-ruby 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -21
- data/README.md +511 -511
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/delivery/builders/image_transformation_builder.rb +271 -271
- data/lib/delivery/builders/url_builder.rb +117 -117
- data/lib/delivery/client/delivery_client.rb +155 -155
- data/lib/delivery/client/delivery_query.rb +249 -249
- data/lib/delivery/client/request_manager.rb +107 -107
- data/lib/delivery/models/content_item.rb +153 -153
- data/lib/delivery/models/content_type.rb +41 -41
- data/lib/delivery/models/pagination.rb +21 -21
- data/lib/delivery/models/taxonomy_group.rb +39 -39
- data/lib/delivery/query_parameters/filters.rb +158 -158
- data/lib/delivery/query_parameters/parameter_base.rb +44 -44
- data/lib/delivery/query_parameters/query_string.rb +78 -78
- data/lib/delivery/resolvers/content_link_resolver.rb +102 -102
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +75 -75
- data/lib/delivery/resolvers/linked_item_resolver.rb +37 -37
- data/lib/delivery/responses/delivery_element_response.rb +33 -33
- data/lib/delivery/responses/delivery_item_listing_response.rb +53 -53
- data/lib/delivery/responses/delivery_item_response.rb +39 -39
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +46 -46
- data/lib/delivery/responses/delivery_taxonomy_response.rb +32 -32
- data/lib/delivery/responses/delivery_type_listing_response.rb +45 -45
- data/lib/delivery/responses/delivery_type_response.rb +31 -31
- data/lib/delivery/responses/response_base.rb +36 -36
- data/lib/delivery/tests/401.json +5 -5
- data/lib/delivery/tests/fake_responder.rb +67 -67
- data/lib/delivery/tests/filtering/items_gt.json +565 -565
- data/lib/delivery/tests/filtering/multiple.json +282 -282
- data/lib/delivery/tests/filtering/pagination_about_us.json +646 -646
- data/lib/delivery/tests/generic/items/about_us.json +227 -227
- data/lib/delivery/tests/generic/items/aeropress_filters.json +138 -138
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +168 -168
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +620 -620
- data/lib/delivery/tests/generic/items.json +4984 -4984
- data/lib/delivery/tests/generic/taxonomies.json +126 -126
- data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +5 -5
- data/lib/delivery/tests/generic/types.json +780 -780
- data/lib/delivery/version.rb +7 -7
- data/lib/kontent-delivery-sdk-ruby.rb +19 -19
- metadata +12 -13
@@ -1,39 +1,39 @@
|
|
1
|
-
module Kentico
|
2
|
-
module Kontent
|
3
|
-
module Delivery
|
4
|
-
class TaxonomyGroup
|
5
|
-
# Parses the 'terms' JSON node as a dynamic OpenStruct object.
|
6
|
-
#
|
7
|
-
# * *Returns*:
|
8
|
-
# - +OpenStruct+ The terms of the taxonomy group as a dynamic object
|
9
|
-
def terms
|
10
|
-
@terms unless @terms.nil?
|
11
|
-
@terms = JSON.parse(
|
12
|
-
JSON.generate(@source['terms']),
|
13
|
-
object_class: OpenStruct
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Parses the 'system' JSON node as a dynamic OpenStruct object.
|
18
|
-
#
|
19
|
-
# * *Returns*:
|
20
|
-
# - +OpenStruct+ The system properties of the taxonomy group
|
21
|
-
def system
|
22
|
-
@system unless @system.nil?
|
23
|
-
@system = JSON.parse(
|
24
|
-
JSON.generate(@source['system']),
|
25
|
-
object_class: OpenStruct
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Constructor.
|
30
|
-
#
|
31
|
-
# * *Args*:
|
32
|
-
# - *json* (+JSON+) A JSON node representing a taxonomy group
|
33
|
-
def initialize(source)
|
34
|
-
@source = source
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
class TaxonomyGroup
|
5
|
+
# Parses the 'terms' JSON node as a dynamic OpenStruct object.
|
6
|
+
#
|
7
|
+
# * *Returns*:
|
8
|
+
# - +OpenStruct+ The terms of the taxonomy group as a dynamic object
|
9
|
+
def terms
|
10
|
+
@terms unless @terms.nil?
|
11
|
+
@terms = JSON.parse(
|
12
|
+
JSON.generate(@source['terms']),
|
13
|
+
object_class: OpenStruct
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parses the 'system' JSON node as a dynamic OpenStruct object.
|
18
|
+
#
|
19
|
+
# * *Returns*:
|
20
|
+
# - +OpenStruct+ The system properties of the taxonomy group
|
21
|
+
def system
|
22
|
+
@system unless @system.nil?
|
23
|
+
@system = JSON.parse(
|
24
|
+
JSON.generate(@source['system']),
|
25
|
+
object_class: OpenStruct
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Constructor.
|
30
|
+
#
|
31
|
+
# * *Args*:
|
32
|
+
# - *json* (+JSON+) A JSON node representing a taxonomy group
|
33
|
+
def initialize(source)
|
34
|
+
@source = source
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,158 +1,158 @@
|
|
1
|
-
require 'delivery/query_parameters/parameter_base'
|
2
|
-
|
3
|
-
module Kentico
|
4
|
-
module Kontent
|
5
|
-
module Delivery
|
6
|
-
module QueryParameters
|
7
|
-
# Provides the base class for filter implementations.
|
8
|
-
# See https://developer.kenticocloud.com/v1/reference#content-filtering
|
9
|
-
class Filter < ParameterBase
|
10
|
-
# Constructor.
|
11
|
-
#
|
12
|
-
# * *Args*:
|
13
|
-
# - *key* (+string+) The field to filter upon
|
14
|
-
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
15
|
-
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
16
|
-
def initialize(key, operator, values)
|
17
|
-
super(key, operator, values)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Extend String class to allow semantic typing of filters
|
26
|
-
class String
|
27
|
-
# Represents a filter that matches a content item if the specified content
|
28
|
-
# element or system attribute has a value that contains all the specified
|
29
|
-
# values. This filter is applicable to array values only, such as sitemap
|
30
|
-
# location or value of Linked Items, Taxonomy and Multiple choice content elements.
|
31
|
-
#
|
32
|
-
# * *Args*:
|
33
|
-
# - +Object+ One or more objects representing the values that must appear in the field
|
34
|
-
#
|
35
|
-
# * *Returns*:
|
36
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
37
|
-
def all(*args)
|
38
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[all]', *args)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Represents a filter that matches a content item if the specified content
|
42
|
-
# element or system attribute has a value that contains any the specified
|
43
|
-
# values. This filter is applicable to array values only, such as sitemap
|
44
|
-
# location or value of Linked Items, Taxonomy and Multiple choice content elements.
|
45
|
-
#
|
46
|
-
# * *Args*:
|
47
|
-
# - +Object+ One or more objects representing the values that may appear in the field
|
48
|
-
#
|
49
|
-
# * *Returns*:
|
50
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
51
|
-
def any(*args)
|
52
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[any]', *args)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Represents a filter that matches a content item if the specified content element
|
56
|
-
# or system attribute has a value that contains the specified value.
|
57
|
-
# This filter is applicable to array values only, such as sitemap location or value
|
58
|
-
# of Linked Items, Taxonomy and Multiple choice content elements.
|
59
|
-
#
|
60
|
-
# * *Args*:
|
61
|
-
# - +Object+ An object representing the value that must appear in the field
|
62
|
-
#
|
63
|
-
# * *Returns*:
|
64
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
65
|
-
def contains(*args)
|
66
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[contains]', *args)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Represents a filter that matches a content item if the specified
|
70
|
-
# content element or system attribute has the specified value.
|
71
|
-
#
|
72
|
-
# * *Args*:
|
73
|
-
# - +Object+ An object representing the value that must equal the value in the field
|
74
|
-
#
|
75
|
-
# * *Returns*:
|
76
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
77
|
-
def eq(*args)
|
78
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '', *args)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Represents a filter that matches a content item if the specified content
|
82
|
-
# element or system attribute has a value that is greater than the
|
83
|
-
# specified value.
|
84
|
-
#
|
85
|
-
# * *Args*:
|
86
|
-
# - +Object+ An object representing the lowest possible value of the field, non-inclusive
|
87
|
-
#
|
88
|
-
# * *Returns*:
|
89
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
90
|
-
def gt(*args)
|
91
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gt]', *args)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Represents a filter that matches a content item if the specified content
|
95
|
-
# element or system attribute has a value that is greater than or equal to
|
96
|
-
# the specified value.
|
97
|
-
#
|
98
|
-
# * *Args*:
|
99
|
-
# - +Object+ An object representing the lowest possible value of the field
|
100
|
-
#
|
101
|
-
# * *Returns*:
|
102
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
103
|
-
def gt_or_eq(*args)
|
104
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gte]', *args)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Represents a filter that matches a content item if the specified
|
108
|
-
# content element or system attribute has a value that matches a
|
109
|
-
# value in the specified list.
|
110
|
-
#
|
111
|
-
# * *Args*:
|
112
|
-
# - +Object+ One or more objects representing the required values of the field
|
113
|
-
#
|
114
|
-
# * *Returns*:
|
115
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
116
|
-
def in(*args)
|
117
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[in]', *args)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Represents a filter that matches a content item if the specified content
|
121
|
-
# element or system attribute has a value that is less than the
|
122
|
-
# specified value.
|
123
|
-
#
|
124
|
-
# * *Args*:
|
125
|
-
# - +Object+ An object representing the highest possible value of the field, non-inclusive
|
126
|
-
#
|
127
|
-
# * *Returns*:
|
128
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
129
|
-
def lt(*args)
|
130
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lt]', *args)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Represents a filter that matches a content item if the specified content
|
134
|
-
# element or system attribute has a value that is less than or equal to
|
135
|
-
# the specified value.
|
136
|
-
#
|
137
|
-
# * *Args*:
|
138
|
-
# - +Object+ An object representing the highest possible value of the field
|
139
|
-
#
|
140
|
-
# * *Returns*:
|
141
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
142
|
-
def lt_or_eq(*args)
|
143
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lte]', *args)
|
144
|
-
end
|
145
|
-
|
146
|
-
# Represents a filter that matches a content item if the specified
|
147
|
-
# content element or system attribute has a value that falls within
|
148
|
-
# the specified range of values (both inclusive).
|
149
|
-
#
|
150
|
-
# * *Args*:
|
151
|
-
# - +Object+ An object representing the lowest and highest possible values of the field
|
152
|
-
#
|
153
|
-
# * *Returns*:
|
154
|
-
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
155
|
-
def range(*args)
|
156
|
-
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[range]', *args)
|
157
|
-
end
|
158
|
-
end
|
1
|
+
require 'delivery/query_parameters/parameter_base'
|
2
|
+
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
module QueryParameters
|
7
|
+
# Provides the base class for filter implementations.
|
8
|
+
# See https://developer.kenticocloud.com/v1/reference#content-filtering
|
9
|
+
class Filter < ParameterBase
|
10
|
+
# Constructor.
|
11
|
+
#
|
12
|
+
# * *Args*:
|
13
|
+
# - *key* (+string+) The field to filter upon
|
14
|
+
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
15
|
+
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
16
|
+
def initialize(key, operator, values)
|
17
|
+
super(key, operator, values)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Extend String class to allow semantic typing of filters
|
26
|
+
class String
|
27
|
+
# Represents a filter that matches a content item if the specified content
|
28
|
+
# element or system attribute has a value that contains all the specified
|
29
|
+
# values. This filter is applicable to array values only, such as sitemap
|
30
|
+
# location or value of Linked Items, Taxonomy and Multiple choice content elements.
|
31
|
+
#
|
32
|
+
# * *Args*:
|
33
|
+
# - +Object+ One or more objects representing the values that must appear in the field
|
34
|
+
#
|
35
|
+
# * *Returns*:
|
36
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
37
|
+
def all(*args)
|
38
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[all]', *args)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Represents a filter that matches a content item if the specified content
|
42
|
+
# element or system attribute has a value that contains any the specified
|
43
|
+
# values. This filter is applicable to array values only, such as sitemap
|
44
|
+
# location or value of Linked Items, Taxonomy and Multiple choice content elements.
|
45
|
+
#
|
46
|
+
# * *Args*:
|
47
|
+
# - +Object+ One or more objects representing the values that may appear in the field
|
48
|
+
#
|
49
|
+
# * *Returns*:
|
50
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
51
|
+
def any(*args)
|
52
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[any]', *args)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Represents a filter that matches a content item if the specified content element
|
56
|
+
# or system attribute has a value that contains the specified value.
|
57
|
+
# This filter is applicable to array values only, such as sitemap location or value
|
58
|
+
# of Linked Items, Taxonomy and Multiple choice content elements.
|
59
|
+
#
|
60
|
+
# * *Args*:
|
61
|
+
# - +Object+ An object representing the value that must appear in the field
|
62
|
+
#
|
63
|
+
# * *Returns*:
|
64
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
65
|
+
def contains(*args)
|
66
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[contains]', *args)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Represents a filter that matches a content item if the specified
|
70
|
+
# content element or system attribute has the specified value.
|
71
|
+
#
|
72
|
+
# * *Args*:
|
73
|
+
# - +Object+ An object representing the value that must equal the value in the field
|
74
|
+
#
|
75
|
+
# * *Returns*:
|
76
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
77
|
+
def eq(*args)
|
78
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '', *args)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Represents a filter that matches a content item if the specified content
|
82
|
+
# element or system attribute has a value that is greater than the
|
83
|
+
# specified value.
|
84
|
+
#
|
85
|
+
# * *Args*:
|
86
|
+
# - +Object+ An object representing the lowest possible value of the field, non-inclusive
|
87
|
+
#
|
88
|
+
# * *Returns*:
|
89
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
90
|
+
def gt(*args)
|
91
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gt]', *args)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Represents a filter that matches a content item if the specified content
|
95
|
+
# element or system attribute has a value that is greater than or equal to
|
96
|
+
# the specified value.
|
97
|
+
#
|
98
|
+
# * *Args*:
|
99
|
+
# - +Object+ An object representing the lowest possible value of the field
|
100
|
+
#
|
101
|
+
# * *Returns*:
|
102
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
103
|
+
def gt_or_eq(*args)
|
104
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gte]', *args)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Represents a filter that matches a content item if the specified
|
108
|
+
# content element or system attribute has a value that matches a
|
109
|
+
# value in the specified list.
|
110
|
+
#
|
111
|
+
# * *Args*:
|
112
|
+
# - +Object+ One or more objects representing the required values of the field
|
113
|
+
#
|
114
|
+
# * *Returns*:
|
115
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
116
|
+
def in(*args)
|
117
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[in]', *args)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Represents a filter that matches a content item if the specified content
|
121
|
+
# element or system attribute has a value that is less than the
|
122
|
+
# specified value.
|
123
|
+
#
|
124
|
+
# * *Args*:
|
125
|
+
# - +Object+ An object representing the highest possible value of the field, non-inclusive
|
126
|
+
#
|
127
|
+
# * *Returns*:
|
128
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
129
|
+
def lt(*args)
|
130
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lt]', *args)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Represents a filter that matches a content item if the specified content
|
134
|
+
# element or system attribute has a value that is less than or equal to
|
135
|
+
# the specified value.
|
136
|
+
#
|
137
|
+
# * *Args*:
|
138
|
+
# - +Object+ An object representing the highest possible value of the field
|
139
|
+
#
|
140
|
+
# * *Returns*:
|
141
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
142
|
+
def lt_or_eq(*args)
|
143
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lte]', *args)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Represents a filter that matches a content item if the specified
|
147
|
+
# content element or system attribute has a value that falls within
|
148
|
+
# the specified range of values (both inclusive).
|
149
|
+
#
|
150
|
+
# * *Args*:
|
151
|
+
# - +Object+ An object representing the lowest and highest possible values of the field
|
152
|
+
#
|
153
|
+
# * *Returns*:
|
154
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
155
|
+
def range(*args)
|
156
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[range]', *args)
|
157
|
+
end
|
158
|
+
end
|
@@ -1,44 +1,44 @@
|
|
1
|
-
module Kentico
|
2
|
-
module Kontent
|
3
|
-
module Delivery
|
4
|
-
module QueryParameters
|
5
|
-
# Base class for all parameters added to a DeliveryQuery. All
|
6
|
-
# QueryParameters will appear in the query string.
|
7
|
-
class ParameterBase
|
8
|
-
attr_accessor :key
|
9
|
-
SEPARATOR = CGI.escape(',')
|
10
|
-
|
11
|
-
# Constructor.
|
12
|
-
#
|
13
|
-
# * *Args*:
|
14
|
-
# - *key* (+string+) The field to filter upon
|
15
|
-
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
16
|
-
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
17
|
-
def initialize(key, operator, values)
|
18
|
-
self.key = key
|
19
|
-
values = [values] unless values.respond_to? :each
|
20
|
-
@values = values
|
21
|
-
@operator = operator
|
22
|
-
end
|
23
|
-
|
24
|
-
# Converts the object into a valid query string parameter for use in
|
25
|
-
# a request to Delivery. The key, operator, and values are all escaped
|
26
|
-
# and if there are multiple values, they are joined with commas.
|
27
|
-
#
|
28
|
-
# * *Returns*:
|
29
|
-
# - +string+ A query string parameter without any additional characters (e.g. '&')
|
30
|
-
def provide_query_string_parameter
|
31
|
-
escaped_values = []
|
32
|
-
@values.each { |n| escaped_values << CGI.escape(n.to_s) }
|
33
|
-
format(
|
34
|
-
'%<k>s%<o>s=%<v>s',
|
35
|
-
k: CGI.escape(key),
|
36
|
-
o: CGI.escape(@operator),
|
37
|
-
v: escaped_values.join(SEPARATOR)
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
module QueryParameters
|
5
|
+
# Base class for all parameters added to a DeliveryQuery. All
|
6
|
+
# QueryParameters will appear in the query string.
|
7
|
+
class ParameterBase
|
8
|
+
attr_accessor :key
|
9
|
+
SEPARATOR = CGI.escape(',')
|
10
|
+
|
11
|
+
# Constructor.
|
12
|
+
#
|
13
|
+
# * *Args*:
|
14
|
+
# - *key* (+string+) The field to filter upon
|
15
|
+
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
16
|
+
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
17
|
+
def initialize(key, operator, values)
|
18
|
+
self.key = key
|
19
|
+
values = [values] unless values.respond_to? :each
|
20
|
+
@values = values
|
21
|
+
@operator = operator
|
22
|
+
end
|
23
|
+
|
24
|
+
# Converts the object into a valid query string parameter for use in
|
25
|
+
# a request to Delivery. The key, operator, and values are all escaped
|
26
|
+
# and if there are multiple values, they are joined with commas.
|
27
|
+
#
|
28
|
+
# * *Returns*:
|
29
|
+
# - +string+ A query string parameter without any additional characters (e.g. '&')
|
30
|
+
def provide_query_string_parameter
|
31
|
+
escaped_values = []
|
32
|
+
@values.each { |n| escaped_values << CGI.escape(n.to_s) }
|
33
|
+
format(
|
34
|
+
'%<k>s%<o>s=%<v>s',
|
35
|
+
k: CGI.escape(key),
|
36
|
+
o: CGI.escape(@operator),
|
37
|
+
v: escaped_values.join(SEPARATOR)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
require 'delivery/query_parameters/parameter_base'
|
2
|
-
|
3
|
-
module Kentico
|
4
|
-
module Kontent
|
5
|
-
module Delivery
|
6
|
-
module QueryParameters
|
7
|
-
# Represents the entire query string for a request to Delivery.
|
8
|
-
class QueryString
|
9
|
-
def initialize
|
10
|
-
@params = []
|
11
|
-
end
|
12
|
-
|
13
|
-
# Adds a parameter to the query string
|
14
|
-
#
|
15
|
-
# * *Args*:
|
16
|
-
# - *param* (+Object+) Either a string representing the key for the parameter, or a complete Kentico::Kontent::Delivery::QueryParameters::ParameterBase object
|
17
|
-
# - *values* (+string+) A string or array of strings representing the values for the parameter
|
18
|
-
# - *operator* (+string+) Kentico Kontent filtering parameter, placed after the key, before the equal sign
|
19
|
-
def set_param(param, values = '', operator = '')
|
20
|
-
parameter_base =
|
21
|
-
if param.is_a? String
|
22
|
-
Kentico::Kontent::Delivery::QueryParameters::ParameterBase.new(
|
23
|
-
param,
|
24
|
-
operator,
|
25
|
-
values
|
26
|
-
)
|
27
|
-
else
|
28
|
-
param
|
29
|
-
end
|
30
|
-
# Ensure we have a ParameterBase object
|
31
|
-
return unless parameter_base.respond_to? 'provide_query_string_parameter'
|
32
|
-
|
33
|
-
remove_param parameter_base.key
|
34
|
-
@params << parameter_base
|
35
|
-
end
|
36
|
-
|
37
|
-
# Removes all parameters from the query string with a matching key.
|
38
|
-
#
|
39
|
-
# * *Args*:
|
40
|
-
# - *key* (+string+) Parameter key
|
41
|
-
def remove_param(key)
|
42
|
-
@params.delete_if { |i| i.key.eql? key }
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns all parameters from the query string with a matching key.
|
46
|
-
#
|
47
|
-
# * *Args*:
|
48
|
-
# - *key* (+string+) Parameter key
|
49
|
-
#
|
50
|
-
# * *Returns*:
|
51
|
-
# - +Object+ One or more Kentico::Kontent::Delivery::QueryParameters::ParameterBase objects
|
52
|
-
def param(key)
|
53
|
-
@params.select { |p| p.key.eql? key }
|
54
|
-
end
|
55
|
-
|
56
|
-
# Checks whether there are any parameters defined.
|
57
|
-
#
|
58
|
-
# * *Returns*:
|
59
|
-
# - +bool+ True if there are no parameters set.
|
60
|
-
def empty?
|
61
|
-
@params.empty?
|
62
|
-
end
|
63
|
-
|
64
|
-
# Generates a full query string based on the set parameters, with the
|
65
|
-
# required '?' character at the start. Accomplished by calling the
|
66
|
-
# Kentico::Kontent::Delivery::QueryParameters::ParameterBase.provide_query_string_parameter
|
67
|
-
# method for each parameter.
|
68
|
-
#
|
69
|
-
# * *Returns*:
|
70
|
-
# - +string+ A complete query string
|
71
|
-
def to_s
|
72
|
-
'?' + @params.map(&:provide_query_string_parameter).join('&')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
require 'delivery/query_parameters/parameter_base'
|
2
|
+
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
module QueryParameters
|
7
|
+
# Represents the entire query string for a request to Delivery.
|
8
|
+
class QueryString
|
9
|
+
def initialize
|
10
|
+
@params = []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adds a parameter to the query string
|
14
|
+
#
|
15
|
+
# * *Args*:
|
16
|
+
# - *param* (+Object+) Either a string representing the key for the parameter, or a complete Kentico::Kontent::Delivery::QueryParameters::ParameterBase object
|
17
|
+
# - *values* (+string+) A string or array of strings representing the values for the parameter
|
18
|
+
# - *operator* (+string+) Kentico Kontent filtering parameter, placed after the key, before the equal sign
|
19
|
+
def set_param(param, values = '', operator = '')
|
20
|
+
parameter_base =
|
21
|
+
if param.is_a? String
|
22
|
+
Kentico::Kontent::Delivery::QueryParameters::ParameterBase.new(
|
23
|
+
param,
|
24
|
+
operator,
|
25
|
+
values
|
26
|
+
)
|
27
|
+
else
|
28
|
+
param
|
29
|
+
end
|
30
|
+
# Ensure we have a ParameterBase object
|
31
|
+
return unless parameter_base.respond_to? 'provide_query_string_parameter'
|
32
|
+
|
33
|
+
remove_param parameter_base.key
|
34
|
+
@params << parameter_base
|
35
|
+
end
|
36
|
+
|
37
|
+
# Removes all parameters from the query string with a matching key.
|
38
|
+
#
|
39
|
+
# * *Args*:
|
40
|
+
# - *key* (+string+) Parameter key
|
41
|
+
def remove_param(key)
|
42
|
+
@params.delete_if { |i| i.key.eql? key }
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns all parameters from the query string with a matching key.
|
46
|
+
#
|
47
|
+
# * *Args*:
|
48
|
+
# - *key* (+string+) Parameter key
|
49
|
+
#
|
50
|
+
# * *Returns*:
|
51
|
+
# - +Object+ One or more Kentico::Kontent::Delivery::QueryParameters::ParameterBase objects
|
52
|
+
def param(key)
|
53
|
+
@params.select { |p| p.key.eql? key }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Checks whether there are any parameters defined.
|
57
|
+
#
|
58
|
+
# * *Returns*:
|
59
|
+
# - +bool+ True if there are no parameters set.
|
60
|
+
def empty?
|
61
|
+
@params.empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
# Generates a full query string based on the set parameters, with the
|
65
|
+
# required '?' character at the start. Accomplished by calling the
|
66
|
+
# Kentico::Kontent::Delivery::QueryParameters::ParameterBase.provide_query_string_parameter
|
67
|
+
# method for each parameter.
|
68
|
+
#
|
69
|
+
# * *Returns*:
|
70
|
+
# - +string+ A complete query string
|
71
|
+
def to_s
|
72
|
+
'?' + @params.map(&:provide_query_string_parameter).join('&')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|