kontent-ai / delivery-sdk-ruby Goto Github PK
View Code? Open in Web Editor NEWKontent.ai Delivery Ruby SDK.
Home Page: https://rubygems.org/gems/kontent-ai-delivery
License: MIT License
Kontent.ai Delivery Ruby SDK.
Home Page: https://rubygems.org/gems/kontent-ai-delivery
License: MIT License
Delivery API ensures that modular content has the same order of items as on the web UI.
Currently, the order is broken due to iterating over the common modular content source from get_links
and get_inline_items
.
I noticed that the SDK is published under a personal account. From a long-term perspective, it'd be better to have it published under an organizational account.
Create an organizational account (registered to [email protected]) and publish the gem using this account.
The Gem ID is being defined in 2 files:
kontent-ai-delivery
.delivery-sdk-ruby.gemspec
to kontent-ai-delivery-sdk.gemspec
Add any other context, screenshots, or reference links about the feature request here.
New Kontent feature - Asset renditions, will be released soon (beginning of December with) and it will be available through DeliveryAPI. We should have them covered in SDKs as well.
When the asset element is retrieved from Deliver, the referenced assets can now contain user-defined renditions and it is easy for the developer to apply the rendition query string to the URL of the original asset so that the customized image can be rendered in the UI.
This is the updated Deliver contract for referenced assets of asset element:
renditions
property is present and it is a dictionary with a single key (for now) equal to the "default" preset codename. Presets are not a real entity for now but are part of the long-term vision of asset renditions.
width
& height
properties set by the system)width
& height
in that case){
"name": "name-of-the-uploaded-file.jpg",
"type": "image/jpeg",
"size": 90895,
"description": "Description of what the asset represents.",
"url": "https://assets-us-01.kc-usercontent.com/975bf280-fd91-488c-994c-2f04416e5ee3/3e76909f-599f-4742-b472-77fd4b510e92/sources.jpg",
"width": 1000,
"height": 666,
"renditions": {
"default": {
{
"rendition_id": "d44a2887-74cc-4ab0-8376-ae96f3f534e5",
"preset_id": "a6d98cd5-8b2c-4e50-99c9-15192bce2490",
"width": 200,
"height": 150,
"query", "w=200&h=150&fit=clip&rect=7,23,300,200"
}
}
}
The deliver will soon support sending collection information within the item.system property.
Feature release ETA: 25.11
See .Net SDK solution here.
Example of system property with collection:
"system": {
"id": "f25f38d3-a453-41fe-bc2e-804258b5dbda",
"name": "My first item",
"codename": "my_first_item",
"language": "default",
"collection": "default",
"type": "article",
"sitemap_locations": [],
"last_modified": "2020-11-16T18:43:11.9212466Z"
}
Type of collection system property: string
Collection property is required with a default value default
.
Components and linked items in modular_content
property also have collection
in system
property.
I am trying to follow this tutorial: https://kontent.ai/blog/creating-a-kentico-cloud-ruby-on-rails-application to integrate Kentico Kontent into an existing Rails v6.0 application.
I have installed both of these gems:
gem 'delivery-sdk-ruby'
gem 'render_async'
I added the snippet below to my ApplicationController and replaced with my Delivery API Project ID.
PROJECT_ID = '<your-project-id>'.freeze
@@delivery_client = KenticoCloud::Delivery::DeliveryClient.new project_id: PROJECT_ID
At this point, I am receiving the following error message: 'NameError: uninitialized constant ApplicationController::KenticoCloud'.
I tried to dig into the dancing_goat example from this repo and noticed a few discrepancies:
What am I missing to get this integration up and running?
When the depth
is not correctly set and we try to access a linked_item
the gem raise a unhandled exception.
undefined method '[]' for nil:NilClass
that occurs in lib/delivery/resolvers/linked_item_resolver.rb
at
def resolve_item(codename)
item = @modular_content.values.find { |i| i['system']['codename'] == codename }
ContentItem.new JSON.parse(JSON.generate(item)), @content_link_url_resolver, @inline_content_item_resolver, self
end
The codename
is not inside the modular_content
so the find
method return nil
It's easily fix by increasing the depth
size of the request but that would be better to raise a custom exception.
Fix the failing builds in Travis:
elements
return an OpenStruct object which means all element codename keys are transformed to symbols. So if you iterate over them and eg want to get links or assets you need to convert the key to string yourself which is not intuitive and annoying.
The symbol can be easily converted to a string to work with the internal data structure.
Currently, this repository does contain E2E tests that depend on the testing project (faf446d2-0544-0039-bb43-5d6ef816661a).
Add an abstract layer between Rest Client and Kentico Cloud Delivery client. Use Rest client by default and also provide a way (as a part of the configuration/constructor) to be able to define the implementation for HTTP requests.
Rewrite all E2E tests to be Isolated (if possible even unit tests).
Create one E2E complex test that request data from the Sample Dancing Goat project (975bf280-fd91-488c-994c-2f04416e5ee3) to have a check when some data change in the sample project.
This allows having the data for the tests as a part of this repository and outside collaborators would be able to extend them + we would not be reliable on the
I am not sure if it is by design or just not thought of
My case
The link resolver returns this url {{ site.pages | where_exp: 'page', 'page.data.system.id == link_id' | map: 'url' | first | relative_url }}
Nokogiri escapes special characters
Result cannot be further processed by a templating language such as Liquid
Naive solution: Once the content/link is resolved, call doc.to_xhtml
instead of doc.inner_html
which is not escaping the anchor href attribute value.
https://github.com/Kentico/Home/wiki/Guidelines-for-SDK-developers#required-endpoints
/taxonomies
/taxonomies/{taxonomy_group_codename}
The feature exists in existing SDKs:
It helps circumvent intermittent network issues.
rest-client
doesn't seem to have this logic implemented, so it needs to be created from scratch, probably using some static class when querying
Allow users to render paging navigation for a list of content items.
When the item listing request URL includes the includeTotalCount
query string parameter, the response contains the total number of content items matching the search criteria. As a result, the client needs only one API call to fetch all information necessary to display a list of content items and the paging navigation.
To return the total number of content items, the includeTotalCount
parameter must have value 1
or true
or no value at all.
The total number of content items is returned in the pagination section
of the response in the total_count
property. Please note that if the user does not ask for the total item count, this property is not present.
Add support for the includeTotalCount
parameter and also provide the total number of content items, if available. Also, please provide a warning in documentation comments that asking for the total number of content items might increase the response time and, therefore, users should use it only when they need it.
For a reference implementation please have a look at https://github.com/Kentico/kontent-delivery-sdk-net/blob/master/Kentico.Kontent.Delivery/QueryParameters/Parameters/IncludeTotalCountParameter.cs
Define how to deploy a new version of GEM.
Extend Travis CI configuration of the Deploy step.
Use the tag release trigger.
That allows all people to create a new version to the gem.
Customers want to use their own domains in asset links instead of the default Kontent asset URL. This way the links on their webpage will look more trustworthy, and since the custom links will be visible in search engine results, it also helps SEO optimization.
We will implement the support for custom asset domains in the Kontent app BE and Deliver, but for the whole solution to work, we also need the support in the SDK.
We would like to add a new item to SDK configuration - custom asset domain. The customer would be able to set the domain. When the customer gets the item/variant that contains an asset (in Asset element or Rich text element), the custom domain will be used in the link instead of the default Kontent domain. The rest of the URL will stay the same.
Example: https://test15641652.assets.com/3727c9f0-9ea0-0068-2d4f-e6cdb4acff9d/1e040cde-e4be-4dac-a006-d406e40abf56/cat3.jpg instead of https://qa-assets-eu-01.freetls.fastly.net/3727c9f0-9ea0-0068-2d4f-e6cdb4acff9d/1e040cde-e4be-4dac-a006-d406e40abf56/cat3.jpg
Release date: the BE part of the solution is done, you can release the SDK changes as soon as they are ready.
Feel free to be inspired by already implemented JS SDK:
dotenv
is specified as a development dependency but it is being loaded during runtime from request_manager.rb
. This causes the app to crash.
Bundle-audit is flagging Nokogiri
to be too low of a version in my project. However, when attempting to upgrade to 1.11.0
, it fails because the kontent-delivery-sdk-ruby
is locking the version as seen below:
kontent-delivery-sdk-ruby (~> 2) was resolved to 2.0.12, which depends on
nokogiri (>= 1.8.4, ~> 1.10.0)
Can this be updated as Nokogiri has been updated?
Link to Nokogiri security issue: GHSA-vr8q-g5c7-m54m
Hello, I have noticed you are incorrectly parsing the modular content of content items queries.
The model of a listing response differs from the model of a single content item. Modular content is always on the first level of response, therefore if the list is queried it can no longer parse modular content from the level of the particular content item.
Currently, it is being parsed in the same way which results in incorrect behavior of retrieving links from such items.
To give an idea about the problem, I have fixed it on my branch. commit
Allow developers to fetch all content item variants from the new \items-feed
endpoint. This offers developers a way to export an entire project no matter the size.
The content is is provided in small chunks together with a continuation token for the next chunk. The continuation token is sent in X-Continuation
header both for request and response. Should the response from Delivery API contain the token, there are additional items to fetch. If the request does not contain the continuation header, Delivery API will return the first chunk.
Filtering parameters are same as for items
endpoint but paging and depth are not supported.
The response has also the similar structure to items
endpoint but paging object is missing and modular_content
contains only components.
Implementation details for consistency: (name casing should be adapted according to the rest of SDK)
Add a new method to DeliveryClient
with a name GetItemsFeed()
. The method should support the same filtering parameters as GetItems()
except for depth, skip and limit and return a content items variants feed.
The feed contains a bool property HasMoreResults
that is true if the first batch was not yet fetched or there are more items to fetch (indicated by a continuation header in the previous response). The feed also contains a method FetchNextBatch()
that would retrieve the next response from \items-feed
endpoint.
See .NET SDK for reference code
To improve response times Delivery API might provide stale content. Stale means that there is a more recent version, but it will become available later. This information is important for developers who implement caching because stale content should have a short TTL. Developers can inspect the value of the X-Stale-Content response header. 1 indicates that content is stale. If the header is not present or it has a different value, content is not stale.
Extend response models with information whether content is stale. For consistency it is recommended to use a has stale content bool property with the proper case type.
Currently, we don't have the status of the code coverage automatic way.
Set up the CI (Travis) to count the test coverage and submit them to the Code Climate.
Add the badge to the Readme.
https://github.com/Kentico/Home/wiki/Guidelines-for-SDK-developers#required-endpoints
/types/{type_codename}/elements/{element_codename}
From February 1st, 2020 Delivery API will start enforcing rate limits to ensure fair usage by as many clients as possible. These rate limits should be high enough to work for most clients by default. However, in particular cases Delivery API might respond with 429 Too many requests
. These responses will also contain the Retry-After
header indicating how long the client should wait before making a follow-up request.
Implement a retry policy that handles 429 Too many requests
and retries the HTTP call using information from an optional Retry-After
header. It can contain a date after which to retry or the seconds to delay after the response is received. We recommend a retry policy with exponential backoff and a jitter strategy to overcome peaks of similar retries coming from many clients. The retry policy should handle the following status codes:
Please note that both 429 Too many requests
and 503 Service Unavailable
responses might contain an optional Retry-After
header.
Introduces new system property 'workflow_step' representing codename of the workflow step, an item is assigned to. Items can be filtered out based on this property
Introduce new property to system object of items. Components should not contain this property.
Have the section in the official KenticoCloud documentation (as it is for i.e. PHP)
We would like to have the section filled for the Ruby SDK.
We need information/links to the page:
Feature is required thus, no method providing project languages is present. User can now get all his project languages.
Introduce a method providing all project languages
Should be released 01.25.2021
endpoint-{deliveryApi}/{projectId}/languages
{ "languages": [ { "system": { "id": "00000000-0000-0000-0000-000000000000", "name": "Default project language", "codename": "default" } }, { "system": { "id": "8fab3c4c-2ba4-47a9-8e53-df8e6154054f", "name": "First Lanugage", "codename": "first_language" } }, { "system": { "id": "24d5aaa6-a0db-4e20-8c11-6eb272bbe168", "name": "Second Language", "codename": "second_language" } } ], "pagination": { "skip": 0, "limit": 0, "count": 3, "next_page": "" } }
This SDK can be consumed from other Kontent solutions and it would be nice to be able to track and distinguish their usage. E.g., X-KC-SOURCE
header to determine the package and version.
class DeliveryQuery
having accessor for custom headers.
The reason for new filtering operators is to give the users of our API better tools for getting just the content they need.
Add the new filtering operators mentioned in the Kentico Kontent product changelog.
You may look at the implementation for .NET for a reference (i.e. EmptyFilter).
According to Kontent.ai documentation, the "project" is renamed to "environment" to correspond with the project/environment structure in Kontent.ai UI. So all, that is related to environments, should be also renamed in SDK.
Rename all mentions about "project" to "environment" (primarily projectId -> environmentId).
Currently, the resolved links don't contain the modular content and nested links cannot be resolved.
I understand that circular/too many levels of nesting might be problematic but I think that is a problem for the consumer to solve.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.