kontent-delivery-sdk-ruby 2.0.14 → 2.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -45
  3. data/lib/delivery/builders/url_builder.rb +3 -0
  4. data/lib/delivery/client/delivery_client.rb +21 -0
  5. data/lib/delivery/client/delivery_query.rb +23 -7
  6. data/lib/delivery/client/request_manager.rb +8 -4
  7. data/lib/delivery/query_parameters/filters.rb +45 -2
  8. data/lib/delivery/query_parameters/parameter_base.rb +17 -7
  9. data/lib/delivery/responses/delivery_item_listing_response.rb +3 -3
  10. data/lib/delivery/responses/delivery_item_response.rb +3 -3
  11. data/lib/delivery/responses/delivery_items_feed_response.rb +58 -0
  12. data/lib/delivery/responses/response_base.rb +2 -2
  13. data/lib/delivery/tests/fake_responder.rb +27 -6
  14. data/lib/delivery/tests/filtering/items_with_count.json +5241 -4842
  15. data/lib/delivery/tests/filtering/{pagination_about_us.json → pagination.json} +179 -64
  16. data/lib/delivery/tests/generic/items.json +1131 -732
  17. data/lib/delivery/tests/generic/items/about_us.json +76 -27
  18. data/lib/delivery/tests/generic/items/aeropress_filters.json +28 -11
  19. data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +409 -12
  20. data/lib/delivery/tests/generic/items/empty_rich_text.json +24 -0
  21. data/lib/delivery/tests/generic/items/rich_text_complex_tables.json +81 -0
  22. data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +396 -500
  23. data/lib/delivery/tests/generic/taxonomies.json +78 -1
  24. data/lib/delivery/tests/generic/types.json +808 -753
  25. data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -0
  26. data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -0
  27. data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -0
  28. data/lib/kontent-delivery-sdk-ruby.rb +1 -0
  29. metadata +50 -29
  30. data/lib/delivery/tests/filtering/items_gt.json +0 -566
  31. data/lib/delivery/tests/filtering/multiple.json +0 -283
  32. data/lib/delivery/version.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3715f7b1ba42111278c5846d6dec582b06a9397d1d1b189078db55f447467379
4
- data.tar.gz: 0c6ee03f3caf9fb19ec5c70ad3551ae1ed5c11f23dcafd171ead6c76ad2d07c9
3
+ metadata.gz: af3dcd9bd3ea7acae77b689d726beeb55f6956e82c77cebe84c18d0ef3ffb2a7
4
+ data.tar.gz: dd48c610c1366536ce9a643ae441446c4bb77059b904cbd0b96909b012ab93a3
5
5
  SHA512:
6
- metadata.gz: cca049daf6661cb2a9dc51fa8f8cdeca86c9a9c2077abb78d6c1ce1b035a4efee41a905a19a7bd17f91128d74ce4e964af71b88dc140097b9a557422bb329f1e
7
- data.tar.gz: 6ec4e5e25779e74d1739f5a5aae0ff4648e6a81db407cf44253a7a597e3e8a15072ef669fa51427eb00ea68d3d92e225225ee0fae66328d4746abf5623090e7b
6
+ metadata.gz: f7fa9688e3f1a456afee73041d40a11bf7be713a1dd44d01e07ba00abd96901781b33d9547859b4634049d3fe1afafb4908e3281de3aa54e3ca5f2d8843f2d5a
7
+ data.tar.gz: 2813f8cedba1c23a362b8cf030ce730f073fe1335f3587ba31585c89d765d1cb0deb40648d9cd879349655d018f130a24c5574f5d0fad855f74e577ee5c7a533
data/README.md CHANGED
@@ -1,36 +1,40 @@
1
- [![Build Status](https://api.travis-ci.com/Kentico/kontent-delivery-sdk-ruby.svg?branch=master)](https://travis-ci.com/Kentico/kontent-delivery-sdk-ruby)
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](https://github.com/Kentico/kontent-delivery-sdk-ruby/blob/master/banner.png)
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
- ## Demo Rails application
18
-
19
- This repository contains a very basic Rails application that you can run locally to see how the SDK can be used. To run the Dancing Goat demo application, clone this repository and open `/dancing_goat/app/controllers/application_controller.rb`. Add your project ID to the file here:
20
-
21
- ```ruby
22
- class ApplicationController < ActionController::Base
23
- PROJECT_ID = '<your-project-id>'.freeze
24
- ```
25
-
26
- If you don't have the sample project installed in Kentico Kontent, you can generate a new project [here](https://app.kontent.ai/sample-project-generator). Save the file, then open a terminal in the `/dancing_goat` directory and run the following commands:
27
-
28
- ```
29
- bundle install
30
- rails server
31
- ```
32
-
33
- The site should be accessible at localhost:3000. You can also follow a step-by-step guide to creating a basic Rails application on the [Kentico Kontent Blog](https://kontent.ai/blog/creating-a-kentico-cloud-ruby-on-rails-application).
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 [preview](https://developer.kenticocloud.com/docs/previewing-content-in-a-separate-environment "preview"), pass the Preview API Key to the constructor:
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 propogated to all queries created by the client, _or_ per-query by setting it's `use_preview` attribute:
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://developer.kenticocloud.com/docs/securing-public-access "Securing public access") to your project, you need to provide the DeliveryClient with the primary or secondary key:
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 the secure published content in your project. Be sure to not expose the key if the file(s) it appears in are publicly-available.
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://developer.kenticocloud.com/v1/reference#content-filtering "filtering") to retrieve particular items. The filtering methods are applied directly to a string and the available methods are:
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://developer.kenticocloud.com/v1/reference#content-ordering "order_by")|`order_by 'system.last_modified' '[desc]'`|?order=system.last_modified[desc]
175
- |[skip](https://developer.kenticocloud.com/v1/reference#listing-response-paging "skip")|`skip 5`|?skip=5
176
- |[limit](https://developer.kenticocloud.com/v1/reference#listing-response-paging "limit")|`limit 5`|?limit=5
177
- |[elements](https://developer.kenticocloud.com/v1/reference#projection "elements")|`elements %w[price product_name image]`|?elements=price,product_name,image
178
- |[depth](https://developer.kenticocloud.com/v1/reference#linked-content "depth")|`depth 0`|?depth=0
179
- |[language](https://developer.kenticocloud.com/docs/understanding-language-fallbacks "language")|`language 'en'`|?language=en
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://developer.kenticocloud.com/docs/webhooks) notifications, you might want to request the latest content from your Kentico Kontent project.
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
- ### Assets
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
- ### Linked items
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
- ### Pagination
303
+ ## Pagination
296
304
 
297
- The `DeliveryItemListingResponse` also contains a `pagination` attribute to access the [paging](https://developer.kenticocloud.com/v1/reference#listing-response-paging "paging") data for the Delivery query. This object contains the following attributes:
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://developer.kenticocloud.com/v1/reference#view-a-content-type-element) for obtaining details about a specific element of a content type. In the Ruby SDK, you can use the `.element` method:
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://developer.kenticocloud.com/v1/reference#custom-elements-api) using this approach and any other methods.
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://developer.kenticocloud.com/v1/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:
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,5 @@
1
1
  require 'delivery/builders/url_builder'
2
2
  require 'delivery/query_parameters/query_string'
3
- require 'delivery/version'
4
3
 
5
4
  module Kentico
6
5
  module Kontent
@@ -13,6 +12,9 @@ module Kentico
13
12
  'https://github.com/Kentico/kontent-delivery-sdk-ruby#previewing-unpublished-content'.freeze
14
13
  ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
15
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
16
18
  attr_accessor :use_preview,
17
19
  :preview_key,
18
20
  :project_id,
@@ -139,7 +141,7 @@ module Kentico
139
141
  # * *Returns*:
140
142
  # - +self+
141
143
  def skip(value)
142
- query_string.set_param('skip', value)
144
+ query_string.set_param('skip', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
143
145
  self
144
146
  end
145
147
 
@@ -167,7 +169,7 @@ module Kentico
167
169
  # * *Returns*:
168
170
  # - +self+
169
171
  def limit(value)
170
- query_string.set_param('limit', value)
172
+ query_string.set_param('limit', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
171
173
  self
172
174
  end
173
175
 
@@ -196,7 +198,7 @@ module Kentico
196
198
  # * *Returns*:
197
199
  # - +self+
198
200
  def depth(value)
199
- query_string.set_param('depth', value)
201
+ query_string.set_param('depth', value) unless query_type.eql? Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
200
202
  self
201
203
  end
202
204
 
@@ -207,7 +209,7 @@ module Kentico
207
209
  # * *Returns*:
208
210
  # - +self+
209
211
  def request_latest_content
210
- @headers['X-KC-Wait-For-Loading-New-Content'] = true
212
+ @headers[HEADER_WAIT_FOR_CONTENT] = true
211
213
  self
212
214
  end
213
215
 
@@ -238,6 +240,19 @@ module Kentico
238
240
  self
239
241
  end
240
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
+
241
256
  private
242
257
 
243
258
  # Returns request headers that are extended with custom headers.
@@ -247,7 +262,7 @@ module Kentico
247
262
  # - +Hash+
248
263
  def headers
249
264
  headers = @headers.clone
250
- headers['X-KC-SDKID'] = provide_sdk_header
265
+ headers[HEADER_SDK_ID] = provide_sdk_header
251
266
  headers['Authorization'] = "Bearer #{preview_key}" if should_preview
252
267
  headers['Authorization'] = "Bearer #{secure_key}" if !should_preview && secure_key
253
268
 
@@ -278,7 +293,8 @@ module Kentico
278
293
  end
279
294
 
280
295
  def provide_sdk_header
281
- "rubygems.org;kontent-delivery-sdk-ruby;#{Kentico::Kontent::Delivery::VERSION}"
296
+ spec = Gem::Specification::load('kontent-delivery-sdk-ruby.gemspec')
297
+ 'rubygems.org;kontent-delivery-sdk-ruby;' + spec.version.to_s
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.content_link_url_resolver,
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.content_link_url_resolver,
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
- def initialize(key, operator, values)
17
- super(key, operator, values)
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.