kontent-delivery-sdk-ruby 2.0.19 → 2.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +21 -21
  3. data/README.md +583 -575
  4. data/bin/console +14 -14
  5. data/bin/setup +8 -8
  6. data/lib/delivery/builders/image_transformation_builder.rb +271 -271
  7. data/lib/delivery/builders/url_builder.rb +120 -120
  8. data/lib/delivery/client/delivery_client.rb +176 -176
  9. data/lib/delivery/client/delivery_query.rb +302 -302
  10. data/lib/delivery/client/request_manager.rb +125 -125
  11. data/lib/delivery/models/content_item.rb +153 -153
  12. data/lib/delivery/models/content_type.rb +41 -41
  13. data/lib/delivery/models/pagination.rb +22 -22
  14. data/lib/delivery/models/taxonomy_group.rb +39 -39
  15. data/lib/delivery/query_parameters/filters.rb +201 -158
  16. data/lib/delivery/query_parameters/parameter_base.rb +56 -46
  17. data/lib/delivery/query_parameters/query_string.rb +78 -78
  18. data/lib/delivery/resolvers/content_link_resolver.rb +102 -102
  19. data/lib/delivery/resolvers/inline_content_item_resolver.rb +75 -75
  20. data/lib/delivery/resolvers/linked_item_resolver.rb +37 -37
  21. data/lib/delivery/responses/delivery_element_response.rb +34 -34
  22. data/lib/delivery/responses/delivery_item_listing_response.rb +54 -54
  23. data/lib/delivery/responses/delivery_item_response.rb +40 -40
  24. data/lib/delivery/responses/delivery_items_feed_response.rb +58 -58
  25. data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +47 -47
  26. data/lib/delivery/responses/delivery_taxonomy_response.rb +33 -33
  27. data/lib/delivery/responses/delivery_type_listing_response.rb +46 -46
  28. data/lib/delivery/responses/delivery_type_response.rb +32 -32
  29. data/lib/delivery/responses/response_base.rb +39 -39
  30. data/lib/delivery/tests/401.json +5 -5
  31. data/lib/delivery/tests/429.json +4 -4
  32. data/lib/delivery/tests/fake_responder.rb +105 -110
  33. data/lib/delivery/tests/filtering/items_with_count.json +5385 -4986
  34. data/lib/delivery/tests/filtering/{pagination_about_us.json → pagination.json} +761 -646
  35. data/lib/delivery/tests/generic/items.json +5383 -4984
  36. data/lib/delivery/tests/generic/items/about_us.json +276 -227
  37. data/lib/delivery/tests/generic/items/aeropress_filters.json +155 -138
  38. data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +565 -168
  39. data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +517 -621
  40. data/lib/delivery/tests/generic/taxonomies.json +203 -126
  41. data/lib/delivery/tests/generic/types.json +836 -781
  42. data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +5 -5
  43. data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -39
  44. data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -78
  45. data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -104
  46. data/lib/kontent-delivery-sdk-ruby.rb +20 -20
  47. metadata +20 -24
  48. data/lib/delivery/tests/filtering/items_gt.json +0 -566
  49. data/lib/delivery/tests/filtering/multiple.json +0 -283
  50. data/lib/delivery/version.rb +0 -7
@@ -1,302 +1,302 @@
1
- require 'delivery/builders/url_builder'
2
- require 'delivery/query_parameters/query_string'
3
- require 'delivery/version'
4
-
5
- module Kentico
6
- module Kontent
7
- module Delivery
8
- # Responsible for executing REST requests to Kentico Kontent.
9
- class DeliveryQuery
10
- ERROR_PREVIEW = 'Preview is enabled for the query, but the key is null. '\
11
- 'You can set the preview_key attribute of the query, or '\
12
- 'when you initialize the client. See '\
13
- 'https://github.com/Kentico/kontent-delivery-sdk-ruby#previewing-unpublished-content'.freeze
14
- ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
15
- '. See https://github.com/Kentico/kontent-delivery-sdk-ruby#filtering'.freeze
16
- HEADER_WAIT_FOR_CONTENT = 'X-KC-Wait-For-Loading-New-Content'.freeze
17
- HEADER_SDK_ID = 'X-KC-SDKID'.freeze
18
- HEADER_CONTINUATION = 'X-Continuation'.freeze
19
- attr_accessor :use_preview,
20
- :preview_key,
21
- :project_id,
22
- :code_name,
23
- :secure_key,
24
- :content_link_url_resolver,
25
- :inline_content_item_resolver,
26
- :query_type,
27
- :query_string,
28
- :content_type,
29
- :with_retry_policy
30
-
31
- # Setter for a custom URL.
32
- #
33
- # * *Args*:
34
- # - *url* (+string+) _optional_ Custom URL to use for the query
35
- #
36
- # * *Returns*:
37
- # - +self+
38
- def url(url = nil)
39
- @url = url unless url.nil?
40
- self
41
- end
42
-
43
- # Constructor. Queries should not be instantiated using the constructor, but
44
- # using one of the Kentico::Kontent::Delivery::DeliveryClient methods instead.
45
- #
46
- # * *Args*:
47
- # - *config* (+Hash+) A hash in which each key automatically has its value paired with the corresponding attribute
48
- def initialize(config)
49
- @headers = {}
50
-
51
- # Map each hash value to attr with corresponding key
52
- # from https://stackoverflow.com/a/2681014/5656214
53
- config.each do |k, v|
54
- instance_variable_set("@#{k}", v) unless v.nil?
55
- end
56
- self.query_string = Kentico::Kontent::Delivery::QueryParameters::QueryString.new
57
- return if config.fetch(:qp, nil).nil?
58
-
59
- # Query parameters were passed, parse and validate
60
- validate_params config.fetch(:qp)
61
- end
62
-
63
- # Executes the REST request.
64
- #
65
- # * *Returns*:
66
- # - Kentico::Kontent::Delivery::Responses::ResponseBase or a class extending it
67
- def execute
68
- resp = Kentico::Kontent::Delivery::RequestManager.start self, headers
69
- yield resp if block_given?
70
- resp
71
- end
72
-
73
- # Determines whether the query should use preview mode.
74
- #
75
- # * *Returns*:
76
- # - +boolean+ Whether preview mode should be used for the query
77
- #
78
- # * *Raises*:
79
- # - +StandardError+ if +use_preview+ is true, but +preview_key+ is +nil+
80
- def should_preview
81
- raise ERROR_PREVIEW if use_preview && preview_key.nil?
82
-
83
- use_preview && !preview_key.nil?
84
- end
85
-
86
- # Enables the total_count attribute of the pagination object, which specifies
87
- # the total number of items returned by the query regardless of paging. See
88
- # https://docs.kontent.ai/reference/delivery-api#operation/list-content-items
89
- #
90
- # * *Returns*:
91
- # - +self+
92
- def include_total_count
93
- query_string.set_param('includeTotalCount', 1)
94
- self
95
- end
96
-
97
- # Sets a content link resolver to render links contained in rich text. See
98
- # https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-links
99
- #
100
- # * *Args*:
101
- # - *resolver* ( Kentico::Kontent::Delivery::Resolvers::ContentLinkResolver ) The resolver. Replaces a resolver registered during +DeliveryClient+ instantiation, for this query only.
102
- #
103
- # * *Returns*:
104
- # - +self+
105
- def with_link_resolver(resolver)
106
- self.content_link_url_resolver = resolver
107
- self
108
- end
109
-
110
- # Sets an inline content itme to render content items and components in rich text.
111
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-inline-content
112
- #
113
- # * *Args*:
114
- # - *resolver* ( Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver ) The resolver. Replaces a resolver registered during +DeliveryClient+ instantiation, for this query only.
115
- #
116
- # * *Returns*:
117
- # - +self+
118
- def with_inline_content_item_resolver(resolver)
119
- self.inline_content_item_resolver = resolver
120
- self
121
- end
122
-
123
- # Sets the 'order' query string parameter
124
- #
125
- # * *Args*:
126
- # - *value* (+string+) The value to order by
127
- # - *sort* (+string+) _optional_ The direction of the order, surrounded by brackets. The default value is '[asc]'
128
- #
129
- # * *Returns*:
130
- # - +self+
131
- def order_by(value, sort = '[asc]')
132
- query_string.set_param('order', value + sort)
133
- self
134
- end
135
-
136
- # Sets the 'skip' query string parameter for paging results.
137
- # See https://developer.kenticocloud.com/v1/reference#listing-response-paging
138
- #
139
- # * *Args*:
140
- # - *value* (+integer+) The number to skip by
141
- #
142
- # * *Returns*:
143
- # - +self+
144
- def skip(value)
145
- query_string.set_param('skip', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
146
- self
147
- end
148
-
149
- # Sets the 'language' query string parameter. Language fallbacks will be used
150
- # if untranslated content items are found.
151
- # See https://developer.kenticocloud.com/docs/localization#section-getting-localized-content-items
152
- #
153
- # * *Args*:
154
- # - *value* (+string+) The code name of the desired language
155
- #
156
- # * *Returns*:
157
- # - +self+
158
- def language(value)
159
- query_string.set_param('language', value)
160
- self
161
- end
162
-
163
- # Sets the 'limit' query string parameter for paging results, or just to
164
- # return a specific number of content items.
165
- # See https://developer.kenticocloud.com/v1/reference#listing-response-paging
166
- #
167
- # * *Args*:
168
- # - *value* (+integer+) The number of content items to return
169
- #
170
- # * *Returns*:
171
- # - +self+
172
- def limit(value)
173
- query_string.set_param('limit', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
174
- self
175
- end
176
-
177
- # Sets the 'elements' query string parameter to limit the elements returned
178
- # by the query.
179
- # See https://developer.kenticocloud.com/v1/reference#projection
180
- #
181
- # * *Args*:
182
- # - *value* (+Array+) A single string or array of strings specifying the desired elements, e.g. %w[price product_name image]
183
- #
184
- # * *Returns*:
185
- # - +self+
186
- def elements(value)
187
- query_string.set_param('elements', value)
188
- self
189
- end
190
-
191
- # Sets the 'depth' query string parameter to determine how many levels of
192
- # linked content items should be returned. By default, only 1 level of depth
193
- # is used.
194
- # See https://developer.kenticocloud.com/v1/reference#linked-content
195
- #
196
- # * *Args*:
197
- # - *value* (+integer+) Level of linked items to be returned
198
- #
199
- # * *Returns*:
200
- # - +self+
201
- def depth(value)
202
- query_string.set_param('depth', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
203
- self
204
- end
205
-
206
- # Allows the request to bypass caching and return the latest content
207
- # directly from Kentico Kontent.
208
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#requesting-the-latest-content
209
- #
210
- # * *Returns*:
211
- # - +self+
212
- def request_latest_content
213
- @headers[HEADER_WAIT_FOR_CONTENT] = true
214
- self
215
- end
216
-
217
- # Uses Kentico::Kontent::Delivery::Builders::UrlBuilder.provide_url to set
218
- # the URL for the query. The +UrlBuilder+ also validates the URL.
219
- #
220
- # * *Raises*:
221
- # - +UriFormatException+ if the URL is 65,519 characters or more
222
- #
223
- # * *Returns*:
224
- # - +string+ The full URL for this query
225
- def provide_url
226
- @url = Kentico::Kontent::Delivery::Builders::UrlBuilder.provide_url self if @url.nil?
227
- Kentico::Kontent::Delivery::Builders::UrlBuilder.validate_url @url
228
- @url
229
- end
230
-
231
- # Allows providing custom headers for client requests.
232
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#providing-custom-headers
233
- #
234
- # * *Args*:
235
- # - *headers* (+Hash+) A hash that corresponds to provided headers
236
- #
237
- # * *Returns*:
238
- # - +self+
239
- def custom_headers(headers)
240
- @custom_headers = headers
241
- self
242
- end
243
-
244
- def update_continuation(token)
245
- @headers[HEADER_CONTINUATION] = token
246
- self
247
- end
248
-
249
- def continuation_exists?
250
- !continuation_token.nil?
251
- end
252
-
253
- def continuation_token
254
- @headers[HEADER_CONTINUATION]
255
- end
256
-
257
- private
258
-
259
- # Returns request headers that are extended with custom headers.
260
- # Custom headers do not override existing headers.
261
- #
262
- # * *Returns*
263
- # - +Hash+
264
- def headers
265
- headers = @headers.clone
266
- headers[HEADER_SDK_ID] = provide_sdk_header
267
- headers['Authorization'] = "Bearer #{preview_key}" if should_preview
268
- headers['Authorization'] = "Bearer #{secure_key}" if !should_preview && secure_key
269
-
270
- if @custom_headers
271
- headers.merge!(@custom_headers) { |key, v1, v2| v1 }
272
- end
273
-
274
- headers
275
- end
276
-
277
- # Initializes the +query_string+ attribute with the passed array of
278
- # Kentico::Kontent::Delivery::QueryParameters::Filter objects.
279
- #
280
- # * *Raises*:
281
- # - +ArgumentError+ if one the passed objects is not a +Filter+
282
- def validate_params(query_parameters)
283
- params = if query_parameters.is_a? Array
284
- query_parameters
285
- else
286
- [query_parameters]
287
- end
288
- params.each do |p|
289
- query_string.set_param p
290
- unless p.is_a? Kentico::Kontent::Delivery::QueryParameters::Filter
291
- raise ArgumentError, ERROR_PARAMS
292
- end
293
- end
294
- end
295
-
296
- def provide_sdk_header
297
- "rubygems.org;kontent-delivery-sdk-ruby;#{Kentico::Kontent::Delivery::VERSION}"
298
- end
299
- end
300
- end
301
- end
302
- end
1
+ require 'delivery/builders/url_builder'
2
+ require 'delivery/query_parameters/query_string'
3
+
4
+ module Kentico
5
+ module Kontent
6
+ module Delivery
7
+ # Responsible for executing REST requests to Kentico Kontent.
8
+ class DeliveryQuery
9
+ ERROR_PREVIEW = 'Preview is enabled for the query, but the key is null. '\
10
+ 'You can set the preview_key attribute of the query, or '\
11
+ 'when you initialize the client. See '\
12
+ 'https://github.com/Kentico/kontent-delivery-sdk-ruby#previewing-unpublished-content'.freeze
13
+ ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
14
+ '. See https://github.com/Kentico/kontent-delivery-sdk-ruby#filtering'.freeze
15
+ HEADER_WAIT_FOR_CONTENT = 'X-KC-Wait-For-Loading-New-Content'.freeze
16
+ HEADER_SDK_ID = 'X-KC-SDKID'.freeze
17
+ HEADER_CONTINUATION = 'X-Continuation'.freeze
18
+ attr_accessor :use_preview,
19
+ :preview_key,
20
+ :project_id,
21
+ :code_name,
22
+ :secure_key,
23
+ :content_link_url_resolver,
24
+ :inline_content_item_resolver,
25
+ :query_type,
26
+ :query_string,
27
+ :content_type,
28
+ :with_retry_policy
29
+
30
+ # Setter for a custom URL.
31
+ #
32
+ # * *Args*:
33
+ # - *url* (+string+) _optional_ Custom URL to use for the query
34
+ #
35
+ # * *Returns*:
36
+ # - +self+
37
+ def url(url = nil)
38
+ @url = url unless url.nil?
39
+ self
40
+ end
41
+
42
+ # Constructor. Queries should not be instantiated using the constructor, but
43
+ # using one of the Kentico::Kontent::Delivery::DeliveryClient methods instead.
44
+ #
45
+ # * *Args*:
46
+ # - *config* (+Hash+) A hash in which each key automatically has its value paired with the corresponding attribute
47
+ def initialize(config)
48
+ @headers = {}
49
+
50
+ # Map each hash value to attr with corresponding key
51
+ # from https://stackoverflow.com/a/2681014/5656214
52
+ config.each do |k, v|
53
+ instance_variable_set("@#{k}", v) unless v.nil?
54
+ end
55
+ self.query_string = Kentico::Kontent::Delivery::QueryParameters::QueryString.new
56
+ return if config.fetch(:qp, nil).nil?
57
+
58
+ # Query parameters were passed, parse and validate
59
+ validate_params config.fetch(:qp)
60
+ end
61
+
62
+ # Executes the REST request.
63
+ #
64
+ # * *Returns*:
65
+ # - Kentico::Kontent::Delivery::Responses::ResponseBase or a class extending it
66
+ def execute
67
+ resp = Kentico::Kontent::Delivery::RequestManager.start self, headers
68
+ yield resp if block_given?
69
+ resp
70
+ end
71
+
72
+ # Determines whether the query should use preview mode.
73
+ #
74
+ # * *Returns*:
75
+ # - +boolean+ Whether preview mode should be used for the query
76
+ #
77
+ # * *Raises*:
78
+ # - +StandardError+ if +use_preview+ is true, but +preview_key+ is +nil+
79
+ def should_preview
80
+ raise ERROR_PREVIEW if use_preview && preview_key.nil?
81
+
82
+ use_preview && !preview_key.nil?
83
+ end
84
+
85
+ # Enables the total_count attribute of the pagination object, which specifies
86
+ # the total number of items returned by the query regardless of paging. See
87
+ # https://docs.kontent.ai/reference/delivery-api#operation/list-content-items
88
+ #
89
+ # * *Returns*:
90
+ # - +self+
91
+ def include_total_count
92
+ query_string.set_param('includeTotalCount', 1)
93
+ self
94
+ end
95
+
96
+ # Sets a content link resolver to render links contained in rich text. See
97
+ # https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-links
98
+ #
99
+ # * *Args*:
100
+ # - *resolver* ( Kentico::Kontent::Delivery::Resolvers::ContentLinkResolver ) The resolver. Replaces a resolver registered during +DeliveryClient+ instantiation, for this query only.
101
+ #
102
+ # * *Returns*:
103
+ # - +self+
104
+ def with_link_resolver(resolver)
105
+ self.content_link_url_resolver = resolver
106
+ self
107
+ end
108
+
109
+ # Sets an inline content itme to render content items and components in rich text.
110
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-inline-content
111
+ #
112
+ # * *Args*:
113
+ # - *resolver* ( Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver ) The resolver. Replaces a resolver registered during +DeliveryClient+ instantiation, for this query only.
114
+ #
115
+ # * *Returns*:
116
+ # - +self+
117
+ def with_inline_content_item_resolver(resolver)
118
+ self.inline_content_item_resolver = resolver
119
+ self
120
+ end
121
+
122
+ # Sets the 'order' query string parameter
123
+ #
124
+ # * *Args*:
125
+ # - *value* (+string+) The value to order by
126
+ # - *sort* (+string+) _optional_ The direction of the order, surrounded by brackets. The default value is '[asc]'
127
+ #
128
+ # * *Returns*:
129
+ # - +self+
130
+ def order_by(value, sort = '[asc]')
131
+ query_string.set_param('order', value + sort)
132
+ self
133
+ end
134
+
135
+ # Sets the 'skip' query string parameter for paging results.
136
+ # See https://developer.kenticocloud.com/v1/reference#listing-response-paging
137
+ #
138
+ # * *Args*:
139
+ # - *value* (+integer+) The number to skip by
140
+ #
141
+ # * *Returns*:
142
+ # - +self+
143
+ def skip(value)
144
+ query_string.set_param('skip', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
145
+ self
146
+ end
147
+
148
+ # Sets the 'language' query string parameter. Language fallbacks will be used
149
+ # if untranslated content items are found.
150
+ # See https://developer.kenticocloud.com/docs/localization#section-getting-localized-content-items
151
+ #
152
+ # * *Args*:
153
+ # - *value* (+string+) The code name of the desired language
154
+ #
155
+ # * *Returns*:
156
+ # - +self+
157
+ def language(value)
158
+ query_string.set_param('language', value)
159
+ self
160
+ end
161
+
162
+ # Sets the 'limit' query string parameter for paging results, or just to
163
+ # return a specific number of content items.
164
+ # See https://developer.kenticocloud.com/v1/reference#listing-response-paging
165
+ #
166
+ # * *Args*:
167
+ # - *value* (+integer+) The number of content items to return
168
+ #
169
+ # * *Returns*:
170
+ # - +self+
171
+ def limit(value)
172
+ query_string.set_param('limit', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
173
+ self
174
+ end
175
+
176
+ # Sets the 'elements' query string parameter to limit the elements returned
177
+ # by the query.
178
+ # See https://developer.kenticocloud.com/v1/reference#projection
179
+ #
180
+ # * *Args*:
181
+ # - *value* (+Array+) A single string or array of strings specifying the desired elements, e.g. %w[price product_name image]
182
+ #
183
+ # * *Returns*:
184
+ # - +self+
185
+ def elements(value)
186
+ query_string.set_param('elements', value)
187
+ self
188
+ end
189
+
190
+ # Sets the 'depth' query string parameter to determine how many levels of
191
+ # linked content items should be returned. By default, only 1 level of depth
192
+ # is used.
193
+ # See https://developer.kenticocloud.com/v1/reference#linked-content
194
+ #
195
+ # * *Args*:
196
+ # - *value* (+integer+) Level of linked items to be returned
197
+ #
198
+ # * *Returns*:
199
+ # - +self+
200
+ def depth(value)
201
+ query_string.set_param('depth', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
202
+ self
203
+ end
204
+
205
+ # Allows the request to bypass caching and return the latest content
206
+ # directly from Kentico Kontent.
207
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#requesting-the-latest-content
208
+ #
209
+ # * *Returns*:
210
+ # - +self+
211
+ def request_latest_content
212
+ @headers[HEADER_WAIT_FOR_CONTENT] = true
213
+ self
214
+ end
215
+
216
+ # Uses Kentico::Kontent::Delivery::Builders::UrlBuilder.provide_url to set
217
+ # the URL for the query. The +UrlBuilder+ also validates the URL.
218
+ #
219
+ # * *Raises*:
220
+ # - +UriFormatException+ if the URL is 65,519 characters or more
221
+ #
222
+ # * *Returns*:
223
+ # - +string+ The full URL for this query
224
+ def provide_url
225
+ @url = Kentico::Kontent::Delivery::Builders::UrlBuilder.provide_url self if @url.nil?
226
+ Kentico::Kontent::Delivery::Builders::UrlBuilder.validate_url @url
227
+ @url
228
+ end
229
+
230
+ # Allows providing custom headers for client requests.
231
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#providing-custom-headers
232
+ #
233
+ # * *Args*:
234
+ # - *headers* (+Hash+) A hash that corresponds to provided headers
235
+ #
236
+ # * *Returns*:
237
+ # - +self+
238
+ def custom_headers(headers)
239
+ @custom_headers = headers
240
+ self
241
+ end
242
+
243
+ def update_continuation(token)
244
+ @headers[HEADER_CONTINUATION] = token
245
+ self
246
+ end
247
+
248
+ def continuation_exists?
249
+ !continuation_token.nil?
250
+ end
251
+
252
+ def continuation_token
253
+ @headers[HEADER_CONTINUATION]
254
+ end
255
+
256
+ private
257
+
258
+ # Returns request headers that are extended with custom headers.
259
+ # Custom headers do not override existing headers.
260
+ #
261
+ # * *Returns*
262
+ # - +Hash+
263
+ def headers
264
+ headers = @headers.clone
265
+ headers[HEADER_SDK_ID] = provide_sdk_header
266
+ headers['Authorization'] = "Bearer #{preview_key}" if should_preview
267
+ headers['Authorization'] = "Bearer #{secure_key}" if !should_preview && secure_key
268
+
269
+ if @custom_headers
270
+ headers.merge!(@custom_headers) { |key, v1, v2| v1 }
271
+ end
272
+
273
+ headers
274
+ end
275
+
276
+ # Initializes the +query_string+ attribute with the passed array of
277
+ # Kentico::Kontent::Delivery::QueryParameters::Filter objects.
278
+ #
279
+ # * *Raises*:
280
+ # - +ArgumentError+ if one the passed objects is not a +Filter+
281
+ def validate_params(query_parameters)
282
+ params = if query_parameters.is_a? Array
283
+ query_parameters
284
+ else
285
+ [query_parameters]
286
+ end
287
+ params.each do |p|
288
+ query_string.set_param p
289
+ unless p.is_a? Kentico::Kontent::Delivery::QueryParameters::Filter
290
+ raise ArgumentError, ERROR_PARAMS
291
+ end
292
+ end
293
+ end
294
+
295
+ def provide_sdk_header
296
+ spec = Gem::Specification::load('kontent-delivery-sdk-ruby.gemspec')
297
+ 'rubygems.org;kontent-delivery-sdk-ruby;' + spec.version.to_s
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end