kontent-delivery-sdk-ruby 2.0.6
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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +511 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/delivery/builders/image_transformation_builder.rb +271 -0
- data/lib/delivery/builders/url_builder.rb +117 -0
- data/lib/delivery/client/delivery_client.rb +155 -0
- data/lib/delivery/client/delivery_query.rb +249 -0
- data/lib/delivery/client/request_manager.rb +108 -0
- data/lib/delivery/models/content_item.rb +153 -0
- data/lib/delivery/models/content_type.rb +41 -0
- data/lib/delivery/models/pagination.rb +21 -0
- data/lib/delivery/models/taxonomy_group.rb +39 -0
- data/lib/delivery/query_parameters/filters.rb +158 -0
- data/lib/delivery/query_parameters/parameter_base.rb +44 -0
- data/lib/delivery/query_parameters/query_string.rb +78 -0
- data/lib/delivery/resolvers/content_link_resolver.rb +102 -0
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +75 -0
- data/lib/delivery/resolvers/linked_item_resolver.rb +37 -0
- data/lib/delivery/responses/delivery_element_response.rb +33 -0
- data/lib/delivery/responses/delivery_item_listing_response.rb +53 -0
- data/lib/delivery/responses/delivery_item_response.rb +39 -0
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +46 -0
- data/lib/delivery/responses/delivery_taxonomy_response.rb +32 -0
- data/lib/delivery/responses/delivery_type_listing_response.rb +45 -0
- data/lib/delivery/responses/delivery_type_response.rb +31 -0
- data/lib/delivery/responses/response_base.rb +36 -0
- data/lib/delivery/tests/401.json +6 -0
- data/lib/delivery/tests/fake_responder.rb +67 -0
- data/lib/delivery/tests/filtering/items_gt.json +566 -0
- data/lib/delivery/tests/filtering/multiple.json +283 -0
- data/lib/delivery/tests/filtering/pagination_about_us.json +647 -0
- data/lib/delivery/tests/generic/items.json +4985 -0
- data/lib/delivery/tests/generic/items/about_us.json +228 -0
- data/lib/delivery/tests/generic/items/aeropress_filters.json +139 -0
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +169 -0
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +621 -0
- data/lib/delivery/tests/generic/taxonomies.json +127 -0
- data/lib/delivery/tests/generic/types.json +781 -0
- data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +6 -0
- data/lib/delivery/version.rb +7 -0
- data/lib/kontent-delivery-sdk-ruby.rb +19 -0
- metadata +200 -0
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "delivery"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
require 'delivery/query_parameters/query_string'
|
2
|
+
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
module Builders
|
7
|
+
# Provides methods for manipulating the URL of an asset to adjust the image's
|
8
|
+
# size, cropping behavior, background color, output format, and quality.
|
9
|
+
#
|
10
|
+
# See https://developer.kenticocloud.com/v1/reference#image-transformation and
|
11
|
+
# https://github.com/Kentico/kontent-delivery-sdk-ruby#image-transformation.
|
12
|
+
class ImageTransformationBuilder
|
13
|
+
FIT_MODE_CLIP = 'clip'.freeze
|
14
|
+
FIT_MODE_SCALE = 'scale'.freeze
|
15
|
+
FIT_MODE_CROP = 'crop'.freeze
|
16
|
+
FORMAT_GIF = 'gif'.freeze
|
17
|
+
FORMAT_PNG = 'png'.freeze
|
18
|
+
FORMAT_PNG8 = 'png8'.freeze
|
19
|
+
FORMAT_JPG = 'jpg'.freeze
|
20
|
+
FORMAT_PJPG = 'pjpg'.freeze
|
21
|
+
FORMAT_WEBP = 'webp'.freeze
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def transform(url)
|
25
|
+
AssetURL.new url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class AssetURL
|
31
|
+
INVALID_PARAMS = 'One or more of the parameters is invalid. '\
|
32
|
+
'See https://developer.kenticocloud.com/v1/reference#focal-point-crop'\
|
33
|
+
'for more information.'.freeze
|
34
|
+
ONE_TO_100 = 'Quality parameter must be between 1 and 100.'.freeze
|
35
|
+
BOOLEAN_PARAM = 'The parameter must be a boolean, 0, or 1.'.freeze
|
36
|
+
|
37
|
+
# Constructor. Generally, you obtain an +AssetURL+ object by calling
|
38
|
+
# Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder.transform
|
39
|
+
# instead of using this constructor.
|
40
|
+
def initialize(url)
|
41
|
+
@url = url
|
42
|
+
@query_string = Kentico::Kontent::Delivery::QueryParameters::QueryString.new
|
43
|
+
end
|
44
|
+
|
45
|
+
# Applies all transformation options to the asset URL.
|
46
|
+
#
|
47
|
+
# * *Returns*:
|
48
|
+
# - +string+ The full URL to the asset with all query string parameters set
|
49
|
+
def url
|
50
|
+
@url + @query_string.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
# Sets the width of the image
|
54
|
+
#
|
55
|
+
# * *Args*:
|
56
|
+
# - *width*
|
57
|
+
# - +integer+ Width in pixels, between 1 and 8192.
|
58
|
+
# - +float+ Width in percentage, between 0 and 1.
|
59
|
+
#
|
60
|
+
# * *Returns*:
|
61
|
+
# - +self+
|
62
|
+
def with_width(width)
|
63
|
+
@query_string.set_param 'w', width
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# Sets the height of the image
|
68
|
+
#
|
69
|
+
# * *Args*:
|
70
|
+
# - *height*
|
71
|
+
# - +integer+ Height in pixels, between 1 and 8192.
|
72
|
+
# - +float+ Height in percentage, between 0 and 1.
|
73
|
+
#
|
74
|
+
# * *Returns* :
|
75
|
+
# - +self+
|
76
|
+
def with_height(height)
|
77
|
+
@query_string.set_param 'h', height
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
# Sets the device pixel ratio. Either width or height
|
82
|
+
# (or both) must be set.
|
83
|
+
#
|
84
|
+
# * *Args*:
|
85
|
+
# - *dpr* (+float+) Pixel ratio between 0 and 5.
|
86
|
+
#
|
87
|
+
# * *Returns*:
|
88
|
+
# - +self+
|
89
|
+
def with_pixel_ratio(dpr)
|
90
|
+
@query_string.set_param 'dpr', dpr
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
# Defines how the image is constrained while resizing. Either width
|
95
|
+
# or height (or both) must be set.
|
96
|
+
#
|
97
|
+
# * *Args*:
|
98
|
+
# - *fit* (+string+) Use constants from Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder
|
99
|
+
#
|
100
|
+
# * *Returns*:
|
101
|
+
# - +self+
|
102
|
+
def with_fit_mode(fit)
|
103
|
+
@query_string.set_param 'fit', fit
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
# Selects a region of the image to perform transformations on.
|
108
|
+
# Setting this will remove focal point cropping from the image,
|
109
|
+
# as the two options are incompatible.
|
110
|
+
#
|
111
|
+
# * *Args*:
|
112
|
+
# - *x*
|
113
|
+
# - +integer+ The left border of the rect in pixels
|
114
|
+
# - +float+ The left border of the rect as a percentage between 0 and 1
|
115
|
+
# - *y*
|
116
|
+
# - +integer+ The top border of the rect in pixels
|
117
|
+
# - +float+ The top border of the rect as a percentage between 0 and 1
|
118
|
+
# - *width*
|
119
|
+
# - +integer+ The width of the rect in pixels
|
120
|
+
# - +float+ The width of the rect as a percentage between 0 and 1
|
121
|
+
# - *height*
|
122
|
+
# - +integer+ The height of the rect in pixels
|
123
|
+
# - +float+ The height of the rect as a percentage between 0 and 1
|
124
|
+
#
|
125
|
+
# * *Returns*:
|
126
|
+
# - +self+
|
127
|
+
def with_rect(x, y, width, height)
|
128
|
+
@query_string.remove_param 'fp-x'
|
129
|
+
@query_string.remove_param 'fp-y'
|
130
|
+
@query_string.remove_param 'fp-z'
|
131
|
+
@query_string.remove_param 'crop'
|
132
|
+
@query_string.set_param 'rect', "#{x},#{y},#{width},#{height}"
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
# Sets the point of interest when cropping the image.
|
137
|
+
# Setting this will remove the source rectangle region,
|
138
|
+
# as the two options are incompatible. It also automatically sets the
|
139
|
+
# crop to "focalpoint" and fit to "crop"
|
140
|
+
#
|
141
|
+
# * *Args*:
|
142
|
+
# - *x* (+float+) Percentage of the image's width between 0 and 1
|
143
|
+
# - *y* (+float+) Percentage of the image's height between 0 and 1
|
144
|
+
# - *z* (+integer+) Amount of zoom to apply. A value of 1 is the default zoom, and each step represents 100% additional zoom.
|
145
|
+
#
|
146
|
+
# * *Returns*:
|
147
|
+
# - +self+
|
148
|
+
def with_focal_point(x, y, z)
|
149
|
+
raise ArgumentError, INVALID_PARAMS unless valid_dims?(x, y, z)
|
150
|
+
|
151
|
+
@query_string.remove_param 'rect'
|
152
|
+
@query_string.set_param 'fp-x', x
|
153
|
+
@query_string.set_param 'fp-y', y
|
154
|
+
@query_string.set_param 'fp-z', z
|
155
|
+
@query_string.set_param 'fit', ImageTransformationBuilder::FIT_MODE_CROP
|
156
|
+
@query_string.set_param 'crop', 'focalpoint'
|
157
|
+
self
|
158
|
+
end
|
159
|
+
|
160
|
+
# Sets the background color of any transparent areas of the image.
|
161
|
+
#
|
162
|
+
# * *Args*:
|
163
|
+
# - *color* (+string+) A valid 3, 4, 6, or 8 digit hexadecimal color, without the # symbol
|
164
|
+
#
|
165
|
+
# * *Returns*:
|
166
|
+
# - +self+
|
167
|
+
def with_background_color(color)
|
168
|
+
@query_string.set_param 'bg', color
|
169
|
+
self
|
170
|
+
end
|
171
|
+
|
172
|
+
# Sets the output format of the request for the image.
|
173
|
+
#
|
174
|
+
# * *Args*:
|
175
|
+
# - *format* (+string+) Use constants from Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder
|
176
|
+
#
|
177
|
+
# * *Returns*:
|
178
|
+
# - +self+
|
179
|
+
def with_output_format(format)
|
180
|
+
@query_string.set_param 'fm', format
|
181
|
+
self
|
182
|
+
end
|
183
|
+
|
184
|
+
# Configure the amount of compression for lossy file formats. Lower quality
|
185
|
+
# images will have a smaller file size. Only affects *jpg*, *pjpg*, and
|
186
|
+
# *webp* files.
|
187
|
+
#
|
188
|
+
# When no quality is specified for an image transformation, the default
|
189
|
+
# value of 85 is used.
|
190
|
+
#
|
191
|
+
# * *Args*:
|
192
|
+
# - *quality* (+integer+) The quality of the image between 1 and 100
|
193
|
+
#
|
194
|
+
# * *Returns*:
|
195
|
+
# - +self+
|
196
|
+
#
|
197
|
+
# * *Raises*:
|
198
|
+
# - +ArgumentError+ if +quality+ is not between 1 and 100 inclusive
|
199
|
+
def with_quality(quality)
|
200
|
+
raise ArgumentError, ONE_TO_100 unless quality.to_i >= 1 && quality.to_i <= 100
|
201
|
+
|
202
|
+
@query_string.set_param 'q', quality
|
203
|
+
self
|
204
|
+
end
|
205
|
+
|
206
|
+
# Sets the lossless parameter. If +true+, automatically sets the format
|
207
|
+
# to WebP.
|
208
|
+
#
|
209
|
+
# * *Args*:
|
210
|
+
# - *lossless*
|
211
|
+
# - +integer+ Either 1 or 0
|
212
|
+
# - +bool+ Either +true+ or +false+
|
213
|
+
# - +string+ Either 'true' or 'false'
|
214
|
+
#
|
215
|
+
# * *Returns*:
|
216
|
+
# - +self+
|
217
|
+
#
|
218
|
+
# * *Raises*:
|
219
|
+
# - +ArgumentError+ if +lossless+ cannot be parsed as a boolean
|
220
|
+
def with_lossless(lossless)
|
221
|
+
lossless = lossless.to_s.downcase
|
222
|
+
raise ArgumentError, BOOLEAN_PARAM unless bool? lossless
|
223
|
+
|
224
|
+
@query_string.set_param 'lossless', lossless
|
225
|
+
@query_string.set_param 'fm', Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder::FORMAT_WEBP if %w[true 1].include? lossless
|
226
|
+
self
|
227
|
+
end
|
228
|
+
|
229
|
+
# Enables or disables automatic format selection. If enabled, it will
|
230
|
+
# override the format parameter and deliver WebP instead. If the browser
|
231
|
+
# does not support WebP, the value of the format parameter will be used.
|
232
|
+
#
|
233
|
+
# * *Args*:
|
234
|
+
# - *auto*
|
235
|
+
# - +integer+ Either 1 or 0
|
236
|
+
# - +bool+ Either +true+ or +false+
|
237
|
+
# - +string+ Either 'true' or 'false'
|
238
|
+
#
|
239
|
+
# * *Returns*:
|
240
|
+
# - +self+
|
241
|
+
#
|
242
|
+
# * *Raises*:
|
243
|
+
# - +ArgumentError+ if +auto+ cannot be parsed as a boolean
|
244
|
+
def with_auto_format_selection(auto)
|
245
|
+
auto = auto.to_s.downcase
|
246
|
+
raise ArgumentError, BOOLEAN_PARAM unless bool? auto
|
247
|
+
|
248
|
+
if %w[true 1].include? auto
|
249
|
+
@query_string.set_param 'auto', 'format'
|
250
|
+
else
|
251
|
+
@query_string.remove_param 'auto'
|
252
|
+
end
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
256
|
+
private
|
257
|
+
|
258
|
+
def valid_dims?(x, y, z)
|
259
|
+
(x.to_f >= 0.0 && x.to_f <= 1.0) &&
|
260
|
+
(y.to_f >= 0.0 && y.to_f <= 1.0) &&
|
261
|
+
(z.to_i >= 1)
|
262
|
+
end
|
263
|
+
|
264
|
+
def bool?(value)
|
265
|
+
%w[true false 0 1].include? value
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
module Builders
|
5
|
+
# Internal class which generates the URL required for Delivery REST API
|
6
|
+
class UrlBuilder
|
7
|
+
URL_TEMPLATE_BASE = 'https://deliver.kontent.ai/%s'.freeze
|
8
|
+
URL_TEMPLATE_PREVIEW = 'https://preview-deliver.kontent.ai/%s'.freeze
|
9
|
+
URL_TEMPLATE_ITEM = '/items/%s'.freeze
|
10
|
+
URL_TEMPLATE_ITEMS = '/items'.freeze
|
11
|
+
URL_TEMPLATE_TYPE = '/types/%s'.freeze
|
12
|
+
URL_TEMPLATE_TYPES = '/types'.freeze
|
13
|
+
URL_TEMPLATE_ELEMENTS = '/types/%s/elements/%s'.freeze
|
14
|
+
URL_TEMPLATE_TAXONOMY = '/taxonomies/%s'.freeze
|
15
|
+
URL_TEMPLATE_TAXONOMIES = '/taxonomies'.freeze
|
16
|
+
|
17
|
+
URL_MAX_LENGTH = 65_519
|
18
|
+
MSG_LONG_QUERY = 'The request url is too long. Split your query into multiple calls.'.freeze
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# Returns the proper domain for the request along with the
|
22
|
+
# query string parameters configured by the +DeliveryQuery+.
|
23
|
+
#
|
24
|
+
# * *Args*:
|
25
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
26
|
+
#
|
27
|
+
# * *Returns*:
|
28
|
+
# - +string+ The full URL for a Delivery request
|
29
|
+
def provide_url(query)
|
30
|
+
url = provide_base_url(query)
|
31
|
+
url += provide_path_part(query)
|
32
|
+
|
33
|
+
if query.query_string.empty?
|
34
|
+
url
|
35
|
+
else
|
36
|
+
url + query.query_string.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Checks whether the provided URL is too long and raises an error if so.
|
41
|
+
#
|
42
|
+
# * *Args*:
|
43
|
+
# - *url* (+string+) A full Delivery URL
|
44
|
+
#
|
45
|
+
# * *Raises*:
|
46
|
+
# - +UriFormatException+ if the URL is 65,519 characters or more
|
47
|
+
def validate_url(url)
|
48
|
+
raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Returns relative path part of URL depending on query type.
|
54
|
+
#
|
55
|
+
# * *Args*:
|
56
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
57
|
+
#
|
58
|
+
# * *Returns*:
|
59
|
+
# - +string+ The URL path part (without protocol or domain)
|
60
|
+
def provide_path_part(query)
|
61
|
+
case query.query_type
|
62
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS
|
63
|
+
provide_item query
|
64
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_TYPES
|
65
|
+
provide_type query
|
66
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_TAXONOMIES
|
67
|
+
provide_taxonomy query
|
68
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
|
69
|
+
format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def provide_item(query)
|
74
|
+
if query.code_name.nil?
|
75
|
+
URL_TEMPLATE_ITEMS
|
76
|
+
else
|
77
|
+
format(URL_TEMPLATE_ITEM, query.code_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def provide_taxonomy(query)
|
82
|
+
if query.code_name.nil?
|
83
|
+
URL_TEMPLATE_TAXONOMIES
|
84
|
+
else
|
85
|
+
format(URL_TEMPLATE_TAXONOMY, query.code_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def provide_type(query)
|
90
|
+
if query.code_name.nil?
|
91
|
+
URL_TEMPLATE_TYPES
|
92
|
+
else
|
93
|
+
format(URL_TEMPLATE_TYPE, query.code_name)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns the protocol and domain with project ID. Domain changes
|
98
|
+
# according to the query's +use_preview+ attribute.
|
99
|
+
#
|
100
|
+
# * *Args*:
|
101
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
102
|
+
#
|
103
|
+
# * *Returns*:
|
104
|
+
# - +string+ The URL with the project ID
|
105
|
+
def provide_base_url(query)
|
106
|
+
if query.use_preview
|
107
|
+
format(URL_TEMPLATE_PREVIEW, query.project_id)
|
108
|
+
else
|
109
|
+
format(URL_TEMPLATE_BASE, query.project_id)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'delivery/client/delivery_query'
|
2
|
+
require 'delivery/responses/delivery_item_listing_response'
|
3
|
+
require 'delivery/responses/delivery_item_response'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Kentico
|
7
|
+
module Kontent
|
8
|
+
module Delivery
|
9
|
+
QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
|
10
|
+
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
11
|
+
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
12
|
+
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
13
|
+
|
14
|
+
# Executes requests against the Kentico Kontent Delivery API.
|
15
|
+
class DeliveryClient
|
16
|
+
attr_accessor :use_preview
|
17
|
+
|
18
|
+
# Constructor. Accepts a hash with the options for client.
|
19
|
+
#
|
20
|
+
# * *Args*:
|
21
|
+
# - *config* (+Hash+) May contain the following keys:
|
22
|
+
# - project_id (+string+) _required_
|
23
|
+
# - preview_key (+string+)
|
24
|
+
# - secure_key (+string+)
|
25
|
+
# - content_link_url_resolver ( Kentico::Kontent::Delivery::Resolvers::ContentLinkResolver )
|
26
|
+
# - inline_content_item_resolver ( Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver )
|
27
|
+
# - with_retry_policy (+bool+)
|
28
|
+
def initialize(config)
|
29
|
+
@project_id = config.fetch(:project_id)
|
30
|
+
@preview_key = config.fetch(:preview_key, nil)
|
31
|
+
@secure_key = config.fetch(:secure_key, nil)
|
32
|
+
@content_link_url_resolver = config.fetch(:content_link_url_resolver, nil)
|
33
|
+
@inline_content_item_resolver = config.fetch(:inline_content_item_resolver, nil)
|
34
|
+
@with_retry_policy = config.fetch(:with_retry_policy, true)
|
35
|
+
self.use_preview = !@preview_key.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return all content types of the project
|
39
|
+
#
|
40
|
+
# * *Returns*:
|
41
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
42
|
+
def types
|
43
|
+
DeliveryQuery.new project_id: @project_id,
|
44
|
+
secure_key: @secure_key,
|
45
|
+
query_type: QUERY_TYPE_TYPES,
|
46
|
+
with_retry_policy: @with_retry_policy
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return a single content type of the project
|
50
|
+
#
|
51
|
+
# * *Args*:
|
52
|
+
# - *code_name* (+string+) Code name of the desired content type
|
53
|
+
#
|
54
|
+
# * *Returns*:
|
55
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
56
|
+
def type(code_name)
|
57
|
+
DeliveryQuery.new project_id: @project_id,
|
58
|
+
secure_key: @secure_key,
|
59
|
+
code_name: code_name,
|
60
|
+
query_type: QUERY_TYPE_TYPES,
|
61
|
+
with_retry_policy: @with_retry_policy
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return all content items of the project
|
65
|
+
#
|
66
|
+
# * *Args*:
|
67
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
68
|
+
#
|
69
|
+
# * *Returns*:
|
70
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
71
|
+
def items(query_parameters = [])
|
72
|
+
q = DeliveryQuery.new project_id: @project_id,
|
73
|
+
secure_key: @secure_key,
|
74
|
+
qp: query_parameters,
|
75
|
+
content_link_url_resolver: @content_link_url_resolver,
|
76
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
77
|
+
query_type: QUERY_TYPE_ITEMS,
|
78
|
+
with_retry_policy: @with_retry_policy
|
79
|
+
q.use_preview = use_preview
|
80
|
+
q.preview_key = @preview_key
|
81
|
+
q
|
82
|
+
end
|
83
|
+
|
84
|
+
# Return a single content item of the project
|
85
|
+
#
|
86
|
+
# * *Args*:
|
87
|
+
# - *code_name* (+string+) The code name of the desired content item
|
88
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
89
|
+
#
|
90
|
+
# * *Returns*:
|
91
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
92
|
+
def item(code_name, query_parameters = [])
|
93
|
+
q = DeliveryQuery.new project_id: @project_id,
|
94
|
+
secure_key: @secure_key,
|
95
|
+
code_name: code_name,
|
96
|
+
qp: query_parameters,
|
97
|
+
content_link_url_resolver: @content_link_url_resolver,
|
98
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
99
|
+
query_type: QUERY_TYPE_ITEMS,
|
100
|
+
with_retry_policy: @with_retry_policy
|
101
|
+
q.use_preview = use_preview
|
102
|
+
q.preview_key = @preview_key
|
103
|
+
q
|
104
|
+
end
|
105
|
+
|
106
|
+
# Return all taxonomy groups of the project
|
107
|
+
#
|
108
|
+
# * *Args*:
|
109
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
110
|
+
#
|
111
|
+
# * *Returns*:
|
112
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
113
|
+
def taxonomies(query_parameters = [])
|
114
|
+
DeliveryQuery.new project_id: @project_id,
|
115
|
+
secure_key: @secure_key,
|
116
|
+
qp: query_parameters,
|
117
|
+
query_type: QUERY_TYPE_TAXONOMIES,
|
118
|
+
with_retry_policy: @with_retry_policy
|
119
|
+
end
|
120
|
+
|
121
|
+
# Return a single taxonomy group of the project
|
122
|
+
#
|
123
|
+
# * *Args*:
|
124
|
+
# - *code_name* (+string+) The code name of the desired taxonomy group
|
125
|
+
#
|
126
|
+
# * *Returns*:
|
127
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
128
|
+
def taxonomy(code_name)
|
129
|
+
DeliveryQuery.new project_id: @project_id,
|
130
|
+
secure_key: @secure_key,
|
131
|
+
code_name: code_name,
|
132
|
+
query_type: QUERY_TYPE_TAXONOMIES,
|
133
|
+
with_retry_policy: @with_retry_policy
|
134
|
+
end
|
135
|
+
|
136
|
+
# Return a single element of a content type
|
137
|
+
#
|
138
|
+
# * *Args*:
|
139
|
+
# - *content_type* (+string+) The code name of the content type containing the element
|
140
|
+
# - *element* (+string+) The code name of the desired element
|
141
|
+
#
|
142
|
+
# * *Returns*:
|
143
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
144
|
+
def element(content_type, element)
|
145
|
+
DeliveryQuery.new project_id: @project_id,
|
146
|
+
secure_key: @secure_key,
|
147
|
+
code_name: element,
|
148
|
+
content_type: content_type,
|
149
|
+
query_type: QUERY_TYPE_ELEMENT,
|
150
|
+
with_retry_policy: @with_retry_policy
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|