delivery-sdk-ruby 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7029e71c762bf49c74c61390da58f7b47e502211cc5a502e1c017ca8b5dbe320
4
- data.tar.gz: 4bce2671a40fb2fc31e4038fd112cf722eb1bdd435b8d565eb1a5c98f22af151
3
+ metadata.gz: 699ce3c4f3fbb0ede944795f2062ca3f475959465a0da0768fb82f397af9e867
4
+ data.tar.gz: e1ae507b2a597758ee8902728305e101c255784bc46d8283c441bd613ea43ea6
5
5
  SHA512:
6
- metadata.gz: 978d43e11b2c242ddba7113c4e2593f5ade63790fce3ed91720406954fe0391db7dd5859d4a779e1a6fc6545bdd2a9372fabd64f6e4347442f9e96d9c71781d7
7
- data.tar.gz: 1d2d8938e1052b55df02f16ad324965b4c57077602e6449e17368e26751e8225d468e882ca5d2e0d15212bad506bc6ca80adcc65f5440f2f0959e46c6679750c
6
+ metadata.gz: b10106369fb1ec0eaa6a816d0f37961dba342e6b5450bf65e72fd8a7b2254444d63fbda027234685989b881d2179939349de3d7c2a076b8427dd9a3764b2b7eb
7
+ data.tar.gz: 543364d151630c4c0ffaedfbe493c72e7c6491b858127a2e75aae966ebbb83d00f449e3941ffc1cd07c5c6558257de0bbcd35f1498c95f32506a0cee8bc5459c
data/README.md CHANGED
@@ -304,6 +304,20 @@ delivery_client.taxonomy('personas').execute do |response|
304
304
  end
305
305
  ```
306
306
 
307
+ ## Retreiveing content type elements
308
+
309
+ Kentico Cloud 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:
310
+
311
+ ```ruby
312
+ delivery_client.element('brewer', 'product_status').execute do |response|
313
+ puts response.element.type # taxonomy
314
+ end
315
+ ```
316
+
317
+ This returns a `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.
318
+
319
+ The element will always contain __codename__, __type__, and __name__, but multiple choice elements will also contain __options__ and taxonomy elements will contain __taxonomy_group__.
320
+
307
321
  ## Resolving links
308
322
 
309
323
  If a rich text element contains links to other content items, you will need to generate the URLs to those items. You can do this by registering a `Delivery::Resolvers::ContentLinkResolver` when you instantiate the DeliveryClient. When you create a ContentLinkResolver, you must pass a method that will return the URL:
@@ -10,6 +10,7 @@ require File.dirname(__FILE__) + '/delivery/responses/delivery_type_listing_resp
10
10
  require File.dirname(__FILE__) + '/delivery/responses/delivery_type_response'
11
11
  require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_listing_response'
12
12
  require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_response'
13
+ require File.dirname(__FILE__) + '/delivery/responses/delivery_element_response'
13
14
  require File.dirname(__FILE__) + '/delivery/resolvers/content_link_resolver'
14
15
  require File.dirname(__FILE__) + '/delivery/resolvers/inline_content_item_resolver'
15
16
  require File.dirname(__FILE__) + '/delivery/builders/image_transformation_builder'
@@ -54,6 +54,8 @@ module Delivery
54
54
  else
55
55
  format(URL_TEMPLATE_TAXONOMY, query.code_name)
56
56
  end
57
+ when Delivery::QUERY_TYPE_ELEMENT
58
+ format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name)
57
59
  end
58
60
  end
59
61
 
@@ -7,6 +7,7 @@ module Delivery
7
7
  QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
8
8
  QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
9
9
  QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
10
+ QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
10
11
 
11
12
  # Executes requests against the Kentico Cloud Delivery API.
12
13
  class DeliveryClient
@@ -72,5 +73,13 @@ module Delivery
72
73
  code_name: code_name,
73
74
  query_type: QUERY_TYPE_TAXONOMIES
74
75
  end
76
+
77
+ def element(content_type, element)
78
+ DeliveryQuery.new project_id: @project_id,
79
+ secure_key: @secure_key,
80
+ code_name: element,
81
+ content_type: content_type,
82
+ query_type: QUERY_TYPE_ELEMENT
83
+ end
75
84
  end
76
85
  end
@@ -20,7 +20,8 @@ module Delivery
20
20
  :content_link_url_resolver,
21
21
  :inline_content_item_resolver,
22
22
  :query_type,
23
- :query_string
23
+ :query_string,
24
+ :content_type
24
25
 
25
26
  # Setter for url, returns self for chaining
26
27
  # .url represents *manually* configured urls, otherwise final url is
@@ -169,6 +170,8 @@ module Delivery
169
170
  else
170
171
  Delivery::Responses::DeliveryTaxonomyResponse.new JSON.parse(response)
171
172
  end
173
+ when Delivery::QUERY_TYPE_ELEMENT
174
+ Delivery::Responses::DeliveryElementResponse.new JSON.parse(response)
172
175
  end
173
176
  end
174
177
  end
@@ -0,0 +1,23 @@
1
+ require 'delivery/responses/response_base'
2
+
3
+ module Delivery
4
+ module Responses
5
+ # Returned by DeliveryClient.element containing a single element
6
+ class DeliveryElementResponse < ResponseBase
7
+ def element
8
+ @element unless @element.nil?
9
+ @element = JSON.parse(
10
+ JSON.generate(@response),
11
+ object_class: OpenStruct
12
+ )
13
+ end
14
+
15
+ def initialize(response)
16
+ @response = response
17
+ super 200,
18
+ "Success, '#{element.codename}' returned",
19
+ JSON.generate(@response)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Delivery
2
- VERSION = '0.13.0'.freeze
2
+ VERSION = '0.14.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delivery-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dugre
@@ -117,6 +117,7 @@ files:
117
117
  - lib/delivery/query_parameters/query_string.rb
118
118
  - lib/delivery/resolvers/content_link_resolver.rb
119
119
  - lib/delivery/resolvers/inline_content_item_resolver.rb
120
+ - lib/delivery/responses/delivery_element_response.rb
120
121
  - lib/delivery/responses/delivery_item_listing_response.rb
121
122
  - lib/delivery/responses/delivery_item_response.rb
122
123
  - lib/delivery/responses/delivery_taxonomy_listing_response.rb