kontent-delivery-sdk-ruby 2.0.15 → 2.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -45
- data/lib/delivery/builders/url_builder.rb +3 -0
- data/lib/delivery/client/delivery_client.rb +21 -0
- data/lib/delivery/client/delivery_query.rb +23 -7
- data/lib/delivery/client/request_manager.rb +8 -4
- data/lib/delivery/query_parameters/filters.rb +45 -2
- data/lib/delivery/query_parameters/parameter_base.rb +17 -7
- data/lib/delivery/responses/delivery_item_listing_response.rb +3 -3
- data/lib/delivery/responses/delivery_item_response.rb +3 -3
- data/lib/delivery/responses/delivery_items_feed_response.rb +58 -0
- data/lib/delivery/responses/response_base.rb +2 -2
- data/lib/delivery/tests/fake_responder.rb +27 -6
- data/lib/delivery/tests/filtering/items_with_count.json +5241 -4842
- data/lib/delivery/tests/filtering/{pagination_about_us.json → pagination.json} +179 -64
- data/lib/delivery/tests/generic/items.json +1131 -732
- data/lib/delivery/tests/generic/items/about_us.json +76 -27
- data/lib/delivery/tests/generic/items/aeropress_filters.json +28 -11
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +409 -12
- data/lib/delivery/tests/generic/items/empty_rich_text.json +24 -0
- data/lib/delivery/tests/generic/items/rich_text_complex_tables.json +81 -0
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +396 -500
- data/lib/delivery/tests/generic/taxonomies.json +78 -1
- data/lib/delivery/tests/generic/types.json +808 -753
- data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -0
- data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -0
- data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -0
- data/lib/kontent-delivery-sdk-ruby.rb +1 -0
- metadata +48 -27
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a50d5e5d2aeccb6c3c46776716ecada32555b335f60bffa29fa71e50e67ac13
|
4
|
+
data.tar.gz: c7f7ee90d20ffc94c82ec6696f2b3d041d9d9582634baaa83e57355151361498
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b622ce5287519b7cea0b7a93f27c66f80a677711c71a74ccc988fb901bdfb95348f8fedc1b5fa94b1c46992a82ffd16e72bf15dce75480ae6b7e8c65d7994e3a
|
7
|
+
data.tar.gz: 197b327d60da93856f53330ebf43488ea3f59087db90c52c7385dbbb293d57758689b214296943b9d924d2c2ddf1944a2c8a26475bd8790488bf15fa1b481d56
|
data/README.md
CHANGED
@@ -1,36 +1,40 @@
|
|
1
|
-
|
1
|
+
![build](https://github.com/Kentico/kontent-delivery-sdk-ruby/actions/workflows/build.yml/badge.svg)
|
2
2
|
[![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com)
|
3
3
|
[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-kontent)
|
4
4
|
[![Version](https://img.shields.io/gem/v/kontent-delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/kontent-delivery-sdk-ruby)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/maintainability)](https://codeclimate.com/github/Kentico/kontent-delivery-sdk-ruby/maintainability)
|
6
|
-
[![Test coverage](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/test_coverage)](https://codeclimate.com/github/Kentico/delivery-sdk-ruby/test_coverage)
|
7
5
|
|
8
6
|
# Delivery Ruby SDK
|
9
7
|
|
10
|
-
![Banner](
|
8
|
+
![Banner](/banner.png)
|
11
9
|
|
12
10
|
The Delivery Ruby SDK can be used in Ruby/Rails projects to retrieve content from Kentico Kontent. This is a community project and not an official Kentico SDK. If you find a bug in the SDK or have a feature request, please submit a GitHub issue.
|
13
11
|
|
14
|
-
See [How to setup a development environment on Windows](https://github.com/Kentico/kontent-delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
See [How to setup a development environment on Windows](https://github.com/Kentico/kontent-delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development, and check out the [Kentico Kontent Blog](https://kontent.ai/blog/creating-a-kentico-cloud-ruby-on-rails-application) for a tutorial on creating a Rails application.
|
13
|
+
|
14
|
+
## Table of contents
|
15
|
+
|
16
|
+
- [Installation](#installation)
|
17
|
+
- [Creating a client](#creating-a-client)
|
18
|
+
- [Previewing unpublished content](#previewing-unpublished-content)
|
19
|
+
- [Making secure requests](#making-secure-requests)
|
20
|
+
- [Retry policy](#retry-policy)
|
21
|
+
- [Listing items](#listing-items)
|
22
|
+
- [Filtering](#filtering)
|
23
|
+
- [Parameters](#parameters)
|
24
|
+
- [Responses](#responses)
|
25
|
+
- [Requesting the latest content](#requesting-the-latest-content)
|
26
|
+
- [Providing custom headers](#providing-custom-headers)
|
27
|
+
- [Custom URLs](#custom-urls)
|
28
|
+
- [Assets](#assets)
|
29
|
+
- [Linked items](#linked-items)
|
30
|
+
- [Pagination](#pagination)
|
31
|
+
- [Items feed](#items-feed)
|
32
|
+
- [Retrieving content types](#retrieving-content-types)
|
33
|
+
- [Taxonomy](#taxonomy)
|
34
|
+
- [Retrieving content type elements](#retrieving-content-type-elements)
|
35
|
+
- [Resolving links](#resolving-links)
|
36
|
+
- [Resolving inline content](#resolving-inline-content)
|
37
|
+
- [Image transformation](#image-transformation)
|
34
38
|
|
35
39
|
## Installation
|
36
40
|
|
@@ -40,7 +44,7 @@ To use the SDK in your own project, add the gem to your Gemfile:
|
|
40
44
|
gem 'kontent-delivery-sdk-ruby'
|
41
45
|
```
|
42
46
|
|
43
|
-
Then run `bundle install`. You can also download the gem from [RubyGems.org](https://rubygems.org/gems/delivery-sdk-ruby). To use the SDK in an `.rb` file, you need to require it:
|
47
|
+
Then run `bundle install`. You can also download the gem from [RubyGems.org](https://rubygems.org/gems/kontent-delivery-sdk-ruby). To use the SDK in an `.rb` file, you need to require it:
|
44
48
|
|
45
49
|
```ruby
|
46
50
|
require 'kontent-delivery-sdk-ruby'
|
@@ -63,14 +67,14 @@ delivery_client = KK::DeliveryClient.new project_id: '<your-project-id>'
|
|
63
67
|
|
64
68
|
### Previewing unpublished content
|
65
69
|
|
66
|
-
To enable
|
70
|
+
To [enable preview](https://docs.kontent.ai/tutorials/develop-apps/get-content/configuring-preview-for-content-items "See how to configure your app and Kontent project to enable content preview"), pass the Preview API Key to the constructor:
|
67
71
|
|
68
72
|
```ruby
|
69
73
|
delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: '<your-project-id>',
|
70
74
|
preview_key: '<your-preview-key>'
|
71
75
|
```
|
72
76
|
|
73
|
-
This enables preview, but you can toggle preview at any time by setting the `use_preview` attribute of DeliveryClient which is
|
77
|
+
This enables preview, but you can toggle preview at any time by setting the `use_preview` attribute of `DeliveryClient` which is propagated to all queries created by the client, _or_ per-query by setting its `use_preview` attribute:
|
74
78
|
|
75
79
|
```ruby
|
76
80
|
# For all queries created by client
|
@@ -86,14 +90,14 @@ end
|
|
86
90
|
|
87
91
|
### Making secure requests
|
88
92
|
|
89
|
-
If you've [secured access](https://
|
93
|
+
If you've [secured access](https://docs.kontent.ai/tutorials/develop-apps/get-content/securing-public-access "See how to enable secured access for your Kontent project") to your project, you need to provide the `DeliveryClient` with either the primary or secondary key:
|
90
94
|
|
91
95
|
```ruby
|
92
96
|
Kentico::Kontent::Delivery::DeliveryClient.new project_id: '<your-project-id>',
|
93
97
|
secure_key: '<your-secure-key>'
|
94
98
|
```
|
95
99
|
|
96
|
-
You can then request
|
100
|
+
You can then securely request published content in your project. Be sure to not expose the key if the file(s) it appears in are publicly available.
|
97
101
|
|
98
102
|
### Retry policy
|
99
103
|
|
@@ -137,7 +141,7 @@ response = delivery_client.items.execute
|
|
137
141
|
|
138
142
|
### Filtering
|
139
143
|
|
140
|
-
You can use [filtering](https://
|
144
|
+
You can use [filtering](https://docs.kontent.ai/reference/delivery-api#tag/Filtering-content "See content filtering options in Delivery API") to retrieve particular items. The filtering methods are applied directly to a string and the available methods are:
|
141
145
|
|
142
146
|
|Method|Example|REST equivalent|
|
143
147
|
|--|--|--|
|
@@ -145,12 +149,16 @@ You can use [filtering](https://developer.kenticocloud.com/v1/reference#content-
|
|
145
149
|
|any|`'elements.processing'.any %w[dry__natural_ semi_dry]`|?elements.processing[any]=dry__natural_,semi_dry|
|
146
150
|
|contains|`'elements.related_articles'.contains 'on_roasts'`|?elements.related_articles[contains]=on_roasts|
|
147
151
|
|eq|`'system.type'.eq 'grinder'`|?system.type=grinder|
|
152
|
+
|not_eq|`'elements.region'.not_eq 'USA'`|?elements.region[neq]=USA|
|
148
153
|
|gt|`'elements.price'.gt 20`|?elements.price[gt]=20|
|
149
154
|
|gt_or_eq|`'elements.price'.gt_or_eq 20`|?elements.price[gte]=20|
|
150
155
|
|in|`'system.type'.in %w[coffee brewer]`|?system.type[in]=coffee,brewer|
|
156
|
+
|not_in|`'elements.author'.not_in %w[mberry ericd anthonym]`|?elements.author[nin]=mberry,ericd,anthonym|
|
151
157
|
|lt|`'elements.price'.lt 20`|?elements.price[lt]=20|
|
152
158
|
|lt_or_eq|`'elements.price'.lt_or_eq 20`|?elements.price[lte]=20|
|
153
159
|
|range|`'system.last_modified'.range %w[2018-02-01 2018-03-31]`|?system.last_modified[range]=2018-02-01,2018-03-31|
|
160
|
+
|empty|`'elements.banned_reason'.empty`|?elements.banned_reason[empty]|
|
161
|
+
|not_empty|`'elements.status'.not_empty`|?elements.status[nempty]|
|
154
162
|
|
155
163
|
You can pass a single filter or multiple filters in the DeliveryClient methods. For example:
|
156
164
|
|
@@ -171,12 +179,12 @@ The `.item` and `.items` methods return a `Kentico::Kontent::Delivery::DeliveryQ
|
|
171
179
|
|
172
180
|
|Method|Example|REST equivalent
|
173
181
|
|--|--|--|
|
174
|
-
|[order_by](https://
|
175
|
-
|[skip](https://
|
176
|
-
|[limit](https://
|
177
|
-
|[elements](https://
|
178
|
-
|[depth](https://
|
179
|
-
|[language](https://
|
182
|
+
|[order_by](https://docs.kontent.ai/reference/delivery-api#operation/list-content-items "order_by")|`order_by 'system.last_modified' '[desc]'`|?order=system.last_modified[desc]
|
183
|
+
|[skip](https://docs.kontent.ai/reference/delivery-api#operation/list-content-items "skip")|`skip 5`|?skip=5
|
184
|
+
|[limit](https://docs.kontent.ai/reference/delivery-api#operation/list-content-items "limit")|`limit 5`|?limit=5
|
185
|
+
|[elements](https://docs.kontent.ai/reference/delivery-api#tag/Projection "elements")|`elements %w[price product_name image]`|?elements=price,product_name,image
|
186
|
+
|[depth](https://docs.kontent.ai/reference/delivery-api#tag/Linked-content-and-components/linked-content-depth "depth")|`depth 0`|?depth=0
|
187
|
+
|[language](https://docs.kontent.ai/tutorials/set-up-projects/set-up-languages/localization-in-kentico-kontent#a-understanding-language-fallbacks "language")|`language 'en'`|?language=en
|
180
188
|
|
181
189
|
For example:
|
182
190
|
|
@@ -224,7 +232,7 @@ price = response.item.elements.price.value
|
|
224
232
|
|
225
233
|
### Requesting the latest content
|
226
234
|
|
227
|
-
Kentico caches content using Fastly, so requests made to Kentico Kontent may not be up-to-date. In some cases, such as when reacting to [webhook](https://
|
235
|
+
Kentico caches content using Fastly, so requests made to Kentico Kontent may not be up-to-date. In some cases, such as when reacting to [webhook](https://docs.kontent.ai/tutorials/develop-apps/integrate/using-webhooks-for-automatic-updates) notifications, you might want to request the latest content from your Kentico Kontent project.
|
228
236
|
|
229
237
|
You can check the headers of the response for the **X-Stale-Content** header to check if the response was served from cache:
|
230
238
|
|
@@ -268,7 +276,7 @@ delivery_client.items
|
|
268
276
|
end
|
269
277
|
```
|
270
278
|
|
271
|
-
|
279
|
+
## Assets
|
272
280
|
|
273
281
|
You can use `.get_assets(code_name)` to get one or more assets from the specified element. This method will always return an array, so use `.first` to get the first asset:
|
274
282
|
|
@@ -276,7 +284,7 @@ You can use `.get_assets(code_name)` to get one or more assets from the specifie
|
|
276
284
|
url = response.item.get_assets('teaser_image').first.url
|
277
285
|
```
|
278
286
|
|
279
|
-
|
287
|
+
## Linked items
|
280
288
|
|
281
289
|
You can get a simple array of code names by accessing the element's value:
|
282
290
|
|
@@ -292,9 +300,9 @@ response.item.get_links('facts').each do |link|
|
|
292
300
|
end
|
293
301
|
```
|
294
302
|
|
295
|
-
|
303
|
+
## Pagination
|
296
304
|
|
297
|
-
The `DeliveryItemListingResponse` also contains a `pagination` attribute to access the [paging](https://
|
305
|
+
The `DeliveryItemListingResponse` also contains a `pagination` attribute to access the [paging](https://docs.kontent.ai/reference/delivery-api#operation/list-content-items "paging") data for the Delivery query. This object contains the following attributes:
|
298
306
|
|
299
307
|
- **skip**
|
300
308
|
- **limit**
|
@@ -316,6 +324,26 @@ delivery_client.items
|
|
316
324
|
|
317
325
|
:warning: Note that using the `include_total_count` method may increase the response time and should only be used if necessary.
|
318
326
|
|
327
|
+
## Items feed
|
328
|
+
|
329
|
+
Use the `items_feed` method to retrieve a dynamically paginated list of content items in your project. The result will have a `more_results?` method which indicates that more items can be retrieved from the feed, using the `next_result` method.
|
330
|
+
|
331
|
+
This method accepts all [filtering](#filtering) and [parameters](https://github.com/Kentico/kontent-delivery-sdk-ruby#parameters) except _depth_, _skip_, and _limit_. You can read more about the /items-feed endpoint in the [Kontent documentation](https://docs.kontent.ai/reference/delivery-api#operation/enumerate-content-items)
|
332
|
+
|
333
|
+
Below is an example that will load all content items of a project into a single array:
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
result = delivery_client.items_feed.execute
|
337
|
+
items = result.items
|
338
|
+
if result.more_results?
|
339
|
+
loop do
|
340
|
+
result = result.next_result
|
341
|
+
items.push *result.items
|
342
|
+
break unless result.more_results?
|
343
|
+
end
|
344
|
+
end
|
345
|
+
```
|
346
|
+
|
319
347
|
## Retrieving content types
|
320
348
|
|
321
349
|
You can use the `.type` and `.types` methods to request your content types from Kentico Kontent:
|
@@ -387,7 +415,7 @@ end
|
|
387
415
|
|
388
416
|
## Retrieving content type elements
|
389
417
|
|
390
|
-
Kentico Kontent provides an [endpoint](https://
|
418
|
+
Kentico Kontent provides an [endpoint](https://docs.kontent.ai/reference/delivery-api#operation/retrieve-a-content-element) for obtaining details about a specific element of a content type. In the Ruby SDK, you can use the `.element` method:
|
391
419
|
|
392
420
|
```ruby
|
393
421
|
delivery_client.element('brewer', 'product_status').execute do |response|
|
@@ -397,7 +425,7 @@ end
|
|
397
425
|
|
398
426
|
This returns a `Kentico::Kontent::Delivery::Responses::DeliveryElementResponse` where the `element` attribute is a dynamic OStruct representation of the JSON response. This means that you can access any property of the element by simply typing the name as in the above example.
|
399
427
|
|
400
|
-
The element will always contain __codename__, __type__, and __name__, but multiple choice elements will also contain __options__ and taxonomy elements will contain __taxonomy_group__. The Ruby SDK fully supports obtaining [custom elements](https://
|
428
|
+
The element will always contain __codename__, __type__, and __name__, but multiple choice elements will also contain __options__ and taxonomy elements will contain __taxonomy_group__. The Ruby SDK fully supports obtaining [custom elements](https://docs.kontent.ai/reference/custom-elements-js-api) using this approach and any other methods.
|
401
429
|
|
402
430
|
## Resolving links
|
403
431
|
|
@@ -501,9 +529,22 @@ delivery_client.items
|
|
501
529
|
.with_inline_content_item_resolver MyItemResolver.new
|
502
530
|
```
|
503
531
|
|
532
|
+
To resolve inline content in elements, you must call `get_string` similar to content item links:
|
533
|
+
|
534
|
+
```ruby
|
535
|
+
item_resolver = Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver.new(lambda do |item|
|
536
|
+
return "<div>$#{item.elements.price.value}</div>" if item.system.type.eql? 'brewer'
|
537
|
+
end)
|
538
|
+
delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: PROJECT_ID,
|
539
|
+
inline_content_item_resolver: item_resolver
|
540
|
+
delivery_client.item('our_brewers').execute do |response|
|
541
|
+
text = response.item.get_string 'body_copy'
|
542
|
+
end
|
543
|
+
```
|
544
|
+
|
504
545
|
## Image transformation
|
505
546
|
|
506
|
-
When you've obtained the URL for an asset, you can use our [Image Transformation API](https://
|
547
|
+
When you've obtained the URL for an asset, you can use our [Image Transformation API](https://docs.kontent.ai/reference/image-transformation) to make on-the-fly modifications to the image. To do this, use the static `.transform` method of `Kentico::Kontent::Delivery::Builders::ImageTransformationBuilder`, then call the transformation methods. When you're done, call the `.url` method to get the new URL:
|
507
548
|
|
508
549
|
```ruby
|
509
550
|
url = response.item.get_assets('teaser_image').first.url
|
@@ -540,4 +581,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
540
581
|
|
541
582
|
Everyone interacting in the Delivery project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Kentico/kontent-delivery-sdk-net/blob/master/CODE_OF_CONDUCT.md).
|
542
583
|
|
543
|
-
![Analytics](https://kentico-ga-beacon.azurewebsites.net/api/UA-69014260-4/Kentico/kontent-delivery-sdk-ruby?pixel)
|
@@ -13,6 +13,7 @@ module Kentico
|
|
13
13
|
URL_TEMPLATE_ELEMENTS = '/types/%s/elements/%s'.freeze
|
14
14
|
URL_TEMPLATE_TAXONOMY = '/taxonomies/%s'.freeze
|
15
15
|
URL_TEMPLATE_TAXONOMIES = '/taxonomies'.freeze
|
16
|
+
URL_TEMPLATE_ITEMS_FEED = '/items-feed'.freeze
|
16
17
|
|
17
18
|
URL_MAX_LENGTH = 65_519
|
18
19
|
MSG_LONG_QUERY = 'The request url is too long. Split your query into multiple calls.'.freeze
|
@@ -67,6 +68,8 @@ module Kentico
|
|
67
68
|
provide_taxonomy query
|
68
69
|
when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
|
69
70
|
format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name)
|
71
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
|
72
|
+
URL_TEMPLATE_ITEMS_FEED
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -10,6 +10,7 @@ module Kentico
|
|
10
10
|
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
11
11
|
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
12
12
|
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
13
|
+
QUERY_TYPE_ITEMS_FEED = 'QUERY_TYPE_ITEMS_FEED'.freeze
|
13
14
|
|
14
15
|
# Executes requests against the Kentico Kontent Delivery API.
|
15
16
|
class DeliveryClient
|
@@ -61,6 +62,26 @@ module Kentico
|
|
61
62
|
with_retry_policy: @with_retry_policy
|
62
63
|
end
|
63
64
|
|
65
|
+
# Return a paginated feed of all content items of the project
|
66
|
+
#
|
67
|
+
# * *Args*:
|
68
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
69
|
+
#
|
70
|
+
# * *Returns*:
|
71
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
72
|
+
def items_feed(query_parameters = [])
|
73
|
+
q = DeliveryQuery.new project_id: @project_id,
|
74
|
+
secure_key: @secure_key,
|
75
|
+
qp: query_parameters,
|
76
|
+
content_link_url_resolver: @content_link_url_resolver,
|
77
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
78
|
+
query_type: QUERY_TYPE_ITEMS_FEED,
|
79
|
+
with_retry_policy: @with_retry_policy
|
80
|
+
q.use_preview = use_preview
|
81
|
+
q.preview_key = @preview_key
|
82
|
+
q
|
83
|
+
end
|
84
|
+
|
64
85
|
# Return all content items of the project
|
65
86
|
#
|
66
87
|
# * *Args*:
|
@@ -1,6 +1,6 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'delivery/builders/url_builder'
|
2
3
|
require 'delivery/query_parameters/query_string'
|
3
|
-
require 'delivery/version'
|
4
4
|
|
5
5
|
module Kentico
|
6
6
|
module Kontent
|
@@ -13,6 +13,9 @@ module Kentico
|
|
13
13
|
'https://github.com/Kentico/kontent-delivery-sdk-ruby#previewing-unpublished-content'.freeze
|
14
14
|
ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
|
15
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
|
16
19
|
attr_accessor :use_preview,
|
17
20
|
:preview_key,
|
18
21
|
:project_id,
|
@@ -139,7 +142,7 @@ module Kentico
|
|
139
142
|
# * *Returns*:
|
140
143
|
# - +self+
|
141
144
|
def skip(value)
|
142
|
-
query_string.set_param('skip', value)
|
145
|
+
query_string.set_param('skip', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
|
143
146
|
self
|
144
147
|
end
|
145
148
|
|
@@ -167,7 +170,7 @@ module Kentico
|
|
167
170
|
# * *Returns*:
|
168
171
|
# - +self+
|
169
172
|
def limit(value)
|
170
|
-
query_string.set_param('limit', value)
|
173
|
+
query_string.set_param('limit', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
|
171
174
|
self
|
172
175
|
end
|
173
176
|
|
@@ -196,7 +199,7 @@ module Kentico
|
|
196
199
|
# * *Returns*:
|
197
200
|
# - +self+
|
198
201
|
def depth(value)
|
199
|
-
query_string.set_param('depth', value)
|
202
|
+
query_string.set_param('depth', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
|
200
203
|
self
|
201
204
|
end
|
202
205
|
|
@@ -207,7 +210,7 @@ module Kentico
|
|
207
210
|
# * *Returns*:
|
208
211
|
# - +self+
|
209
212
|
def request_latest_content
|
210
|
-
@headers[
|
213
|
+
@headers[HEADER_WAIT_FOR_CONTENT] = true
|
211
214
|
self
|
212
215
|
end
|
213
216
|
|
@@ -238,6 +241,19 @@ module Kentico
|
|
238
241
|
self
|
239
242
|
end
|
240
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
|
+
|
241
257
|
private
|
242
258
|
|
243
259
|
# Returns request headers that are extended with custom headers.
|
@@ -247,7 +263,7 @@ module Kentico
|
|
247
263
|
# - +Hash+
|
248
264
|
def headers
|
249
265
|
headers = @headers.clone
|
250
|
-
headers[
|
266
|
+
headers[HEADER_SDK_ID] = provide_sdk_header
|
251
267
|
headers['Authorization'] = "Bearer #{preview_key}" if should_preview
|
252
268
|
headers['Authorization'] = "Bearer #{secure_key}" if !should_preview && secure_key
|
253
269
|
|
@@ -278,7 +294,7 @@ module Kentico
|
|
278
294
|
end
|
279
295
|
|
280
296
|
def provide_sdk_header
|
281
|
-
|
297
|
+
'rubygems.org;kontent-delivery-sdk-ruby;'
|
282
298
|
end
|
283
299
|
end
|
284
300
|
end
|
@@ -71,6 +71,12 @@ module Kentico
|
|
71
71
|
# - An object derived from the Kentico::Kontent::Delivery::Responses::ResponseBase class
|
72
72
|
def make_response(response)
|
73
73
|
case @query.query_type
|
74
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
|
75
|
+
Kentico::Kontent::Delivery::Responses::DeliveryItemsFeedResponse.new(
|
76
|
+
response.headers,
|
77
|
+
response.body,
|
78
|
+
@query
|
79
|
+
)
|
74
80
|
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS
|
75
81
|
respond_item response
|
76
82
|
when Kentico::Kontent::Delivery::QUERY_TYPE_TYPES
|
@@ -103,15 +109,13 @@ module Kentico
|
|
103
109
|
Kentico::Kontent::Delivery::Responses::DeliveryItemListingResponse.new(
|
104
110
|
response.headers,
|
105
111
|
response.body,
|
106
|
-
@query
|
107
|
-
@query.inline_content_item_resolver
|
112
|
+
@query
|
108
113
|
)
|
109
114
|
else
|
110
115
|
Kentico::Kontent::Delivery::Responses::DeliveryItemResponse.new(
|
111
116
|
response.headers,
|
112
117
|
response.body,
|
113
|
-
@query
|
114
|
-
@query.inline_content_item_resolver
|
118
|
+
@query
|
115
119
|
)
|
116
120
|
end
|
117
121
|
end
|
@@ -13,8 +13,9 @@ module Kentico
|
|
13
13
|
# - *key* (+string+) The field to filter upon
|
14
14
|
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
15
15
|
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
16
|
-
|
17
|
-
|
16
|
+
# - *eq_sign* (+boolean+) If false, the equals sign is not generated in the parameter
|
17
|
+
def initialize(key, operator, values, eq_sign = true)
|
18
|
+
super(key, operator, values, eq_sign)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -78,6 +79,48 @@ class String
|
|
78
79
|
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '', *args)
|
79
80
|
end
|
80
81
|
|
82
|
+
# Represents a filter that matches a content item if the specified
|
83
|
+
# content element or system attribute does not have the specified value.
|
84
|
+
#
|
85
|
+
# * *Args*:
|
86
|
+
# - +Object+ An object representing the value that cannot exist in the element
|
87
|
+
#
|
88
|
+
# * *Returns*:
|
89
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
90
|
+
def not_eq(*args)
|
91
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[neq]', *args)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Represents a filter that matches a content item if the specified
|
95
|
+
# content element or system attribute does not have any value.
|
96
|
+
#
|
97
|
+
# * *Returns*:
|
98
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
99
|
+
def empty
|
100
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[empty]', nil, false)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Represents a filter that matches a content item if the specified
|
104
|
+
# content element or system attribute has any value.
|
105
|
+
#
|
106
|
+
# * *Returns*:
|
107
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
108
|
+
def not_empty
|
109
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[nempty]', nil, false)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Represents a filter that matches a content item if the specified
|
113
|
+
# content element or system attribute does not have the specified value.
|
114
|
+
#
|
115
|
+
# * *Args*:
|
116
|
+
# - +Object+ An object representing the value that cannot exist in the element
|
117
|
+
#
|
118
|
+
# * *Returns*:
|
119
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
120
|
+
def not_in(*args)
|
121
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[nin]', *args)
|
122
|
+
end
|
123
|
+
|
81
124
|
# Represents a filter that matches a content item if the specified content
|
82
125
|
# element or system attribute has a value that is greater than the
|
83
126
|
# specified value.
|