kontent-delivery-sdk-ruby 2.0.18 → 2.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -21
- data/README.md +603 -576
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/delivery/builders/image_transformation_builder.rb +272 -271
- data/lib/delivery/builders/url_builder.rb +123 -120
- data/lib/delivery/client/delivery_client.rb +184 -176
- data/lib/delivery/client/delivery_query.rb +302 -302
- data/lib/delivery/client/request_manager.rb +126 -125
- data/lib/delivery/models/content_item.rb +153 -153
- data/lib/delivery/models/content_type.rb +41 -41
- data/lib/delivery/models/language.rb +29 -0
- data/lib/delivery/models/pagination.rb +22 -22
- data/lib/delivery/models/taxonomy_group.rb +39 -39
- data/lib/delivery/query_parameters/filters.rb +201 -158
- data/lib/delivery/query_parameters/parameter_base.rb +56 -46
- 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 +43 -37
- data/lib/delivery/responses/delivery_element_response.rb +34 -34
- data/lib/delivery/responses/delivery_item_listing_response.rb +54 -54
- data/lib/delivery/responses/delivery_item_response.rb +40 -40
- data/lib/delivery/responses/delivery_items_feed_response.rb +58 -58
- data/lib/delivery/responses/delivery_language_listing_response.rb +44 -0
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +47 -47
- data/lib/delivery/responses/delivery_taxonomy_response.rb +33 -33
- data/lib/delivery/responses/delivery_type_listing_response.rb +46 -46
- data/lib/delivery/responses/delivery_type_response.rb +32 -32
- data/lib/delivery/responses/response_base.rb +39 -39
- data/lib/delivery/tests/401.json +5 -5
- data/lib/delivery/tests/429.json +4 -4
- data/lib/delivery/tests/fake_responder.rb +99 -110
- data/lib/delivery/tests/filtering/items_with_count.json +5385 -4986
- data/lib/delivery/tests/filtering/{pagination_about_us.json → pagination.json} +761 -646
- data/lib/delivery/tests/generic/items.json +5383 -4984
- data/lib/delivery/tests/generic/items/about_us.json +276 -227
- data/lib/delivery/tests/generic/items/aeropress_filters.json +155 -138
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +565 -168
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +599 -621
- data/lib/delivery/tests/generic/languages.json +24 -0
- data/lib/delivery/tests/generic/taxonomies.json +203 -126
- data/lib/delivery/tests/generic/taxonomies/manufacturer.json +30 -0
- data/lib/delivery/tests/generic/types.json +836 -781
- data/lib/delivery/tests/generic/types/brewer.json +89 -0
- data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +5 -5
- data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -39
- data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -78
- data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -104
- data/lib/kontent-delivery-sdk-ruby.rb +22 -20
- metadata +30 -29
- data/lib/delivery/tests/filtering/items_gt.json +0 -566
- data/lib/delivery/tests/filtering/multiple.json +0 -283
- data/lib/delivery/version.rb +0 -7
data/bin/console
CHANGED
@@ -1,14 +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__)
|
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
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
@@ -1,271 +1,272 @@
|
|
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 '
|
132
|
-
@query_string.
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
# - *
|
144
|
-
# - *
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
@query_string.
|
153
|
-
@query_string.set_param 'fp-
|
154
|
-
@query_string.set_param 'fp-
|
155
|
-
@query_string.set_param '
|
156
|
-
@query_string.set_param '
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
#
|
186
|
-
# *
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
# - +
|
213
|
-
# - +
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@query_string.set_param '
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
# - +
|
237
|
-
# - +
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
(
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
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 'fit'
|
132
|
+
@query_string.remove_param 'crop'
|
133
|
+
@query_string.set_param 'rect', "#{x},#{y},#{width},#{height}"
|
134
|
+
self
|
135
|
+
end
|
136
|
+
|
137
|
+
# Sets the point of interest when cropping the image.
|
138
|
+
# Setting this will remove the source rectangle region,
|
139
|
+
# as the two options are incompatible. It also automatically sets the
|
140
|
+
# crop to "focalpoint" and fit to "crop"
|
141
|
+
#
|
142
|
+
# * *Args*:
|
143
|
+
# - *x* (+float+) Percentage of the image's width between 0 and 1
|
144
|
+
# - *y* (+float+) Percentage of the image's height between 0 and 1
|
145
|
+
# - *z* (+integer+) Amount of zoom to apply. A value of 1 is the default zoom, and each step represents 100% additional zoom.
|
146
|
+
#
|
147
|
+
# * *Returns*:
|
148
|
+
# - +self+
|
149
|
+
def with_focal_point(x, y, z)
|
150
|
+
raise ArgumentError, INVALID_PARAMS unless valid_dims?(x, y, z)
|
151
|
+
|
152
|
+
@query_string.remove_param 'rect'
|
153
|
+
@query_string.set_param 'fp-x', x
|
154
|
+
@query_string.set_param 'fp-y', y
|
155
|
+
@query_string.set_param 'fp-z', z
|
156
|
+
@query_string.set_param 'fit', ImageTransformationBuilder::FIT_MODE_CROP
|
157
|
+
@query_string.set_param 'crop', 'focalpoint'
|
158
|
+
self
|
159
|
+
end
|
160
|
+
|
161
|
+
# Sets the background color of any transparent areas of the image.
|
162
|
+
#
|
163
|
+
# * *Args*:
|
164
|
+
# - *color* (+string+) A valid 3, 4, 6, or 8 digit hexadecimal color, without the # symbol
|
165
|
+
#
|
166
|
+
# * *Returns*:
|
167
|
+
# - +self+
|
168
|
+
def with_background_color(color)
|
169
|
+
@query_string.set_param 'bg', color
|
170
|
+
self
|
171
|
+
end
|
172
|
+
|
173
|
+
# Sets the output format of the request for the image.
|
174
|
+
#
|
175
|
+
# * *Args*:
|
176
|
+
# - *format* (+string+) Use constants from Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder
|
177
|
+
#
|
178
|
+
# * *Returns*:
|
179
|
+
# - +self+
|
180
|
+
def with_output_format(format)
|
181
|
+
@query_string.set_param 'fm', format
|
182
|
+
self
|
183
|
+
end
|
184
|
+
|
185
|
+
# Configure the amount of compression for lossy file formats. Lower quality
|
186
|
+
# images will have a smaller file size. Only affects *jpg*, *pjpg*, and
|
187
|
+
# *webp* files.
|
188
|
+
#
|
189
|
+
# When no quality is specified for an image transformation, the default
|
190
|
+
# value of 85 is used.
|
191
|
+
#
|
192
|
+
# * *Args*:
|
193
|
+
# - *quality* (+integer+) The quality of the image between 1 and 100
|
194
|
+
#
|
195
|
+
# * *Returns*:
|
196
|
+
# - +self+
|
197
|
+
#
|
198
|
+
# * *Raises*:
|
199
|
+
# - +ArgumentError+ if +quality+ is not between 1 and 100 inclusive
|
200
|
+
def with_quality(quality)
|
201
|
+
raise ArgumentError, ONE_TO_100 unless quality.to_i >= 1 && quality.to_i <= 100
|
202
|
+
|
203
|
+
@query_string.set_param 'q', quality
|
204
|
+
self
|
205
|
+
end
|
206
|
+
|
207
|
+
# Sets the lossless parameter. If +true+, automatically sets the format
|
208
|
+
# to WebP.
|
209
|
+
#
|
210
|
+
# * *Args*:
|
211
|
+
# - *lossless*
|
212
|
+
# - +integer+ Either 1 or 0
|
213
|
+
# - +bool+ Either +true+ or +false+
|
214
|
+
# - +string+ Either 'true' or 'false'
|
215
|
+
#
|
216
|
+
# * *Returns*:
|
217
|
+
# - +self+
|
218
|
+
#
|
219
|
+
# * *Raises*:
|
220
|
+
# - +ArgumentError+ if +lossless+ cannot be parsed as a boolean
|
221
|
+
def with_lossless(lossless)
|
222
|
+
lossless = lossless.to_s.downcase
|
223
|
+
raise ArgumentError, BOOLEAN_PARAM unless bool? lossless
|
224
|
+
|
225
|
+
@query_string.set_param 'lossless', lossless
|
226
|
+
@query_string.set_param 'fm', Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder::FORMAT_WEBP if %w[true 1].include? lossless
|
227
|
+
self
|
228
|
+
end
|
229
|
+
|
230
|
+
# Enables or disables automatic format selection. If enabled, it will
|
231
|
+
# override the format parameter and deliver WebP instead. If the browser
|
232
|
+
# does not support WebP, the value of the format parameter will be used.
|
233
|
+
#
|
234
|
+
# * *Args*:
|
235
|
+
# - *auto*
|
236
|
+
# - +integer+ Either 1 or 0
|
237
|
+
# - +bool+ Either +true+ or +false+
|
238
|
+
# - +string+ Either 'true' or 'false'
|
239
|
+
#
|
240
|
+
# * *Returns*:
|
241
|
+
# - +self+
|
242
|
+
#
|
243
|
+
# * *Raises*:
|
244
|
+
# - +ArgumentError+ if +auto+ cannot be parsed as a boolean
|
245
|
+
def with_auto_format_selection(auto)
|
246
|
+
auto = auto.to_s.downcase
|
247
|
+
raise ArgumentError, BOOLEAN_PARAM unless bool? auto
|
248
|
+
|
249
|
+
if %w[true 1].include? auto
|
250
|
+
@query_string.set_param 'auto', 'format'
|
251
|
+
else
|
252
|
+
@query_string.remove_param 'auto'
|
253
|
+
end
|
254
|
+
self
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
def valid_dims?(x, y, z)
|
260
|
+
(x.to_f >= 0.0 && x.to_f <= 1.0) &&
|
261
|
+
(y.to_f >= 0.0 && y.to_f <= 1.0) &&
|
262
|
+
(z.to_i >= 1)
|
263
|
+
end
|
264
|
+
|
265
|
+
def bool?(value)
|
266
|
+
%w[true false 0 1].include? value
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|