delivery-sdk-ruby 0.12.1 → 0.13.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: 1b0f167bc8a460612e4ab4b68a799ba17d16c9fb66c23d23a666302f97ae8c06
4
- data.tar.gz: 9465cc7835bdf6e14fd562b2aa55d073ed6147806e718e7e31403328674b463f
3
+ metadata.gz: 7029e71c762bf49c74c61390da58f7b47e502211cc5a502e1c017ca8b5dbe320
4
+ data.tar.gz: 4bce2671a40fb2fc31e4038fd112cf722eb1bdd435b8d565eb1a5c98f22af151
5
5
  SHA512:
6
- metadata.gz: 7a2e54efd94331a7fe1264064fcb44c3b5ba01b5663cf4aa4e224026b5a1ebdea4adae7a82156a325d9c4d8f68dcd578bc3ccc61598c4b932ada63c687738585
7
- data.tar.gz: 4e5d2fade9a324f1b2e7b63fd887a64d09508a448a7ee83951748ef76cb3ced252165cc095dce48ec4d5ba59dfb1b2acbdfa3a66c10e10fe22c49ef8adb6cbd1
6
+ metadata.gz: 978d43e11b2c242ddba7113c4e2593f5ade63790fce3ed91720406954fe0391db7dd5859d4a779e1a6fc6545bdd2a9372fabd64f6e4347442f9e96d9c71781d7
7
+ data.tar.gz: 1d2d8938e1052b55df02f16ad324965b4c57077602e6449e17368e26751e8225d468e882ca5d2e0d15212bad506bc6ca80adcc65f5440f2f0959e46c6679750c
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
-
2
- [![Forums](https://img.shields.io/badge/chat-on%20forums-orange.svg)](https://forums.kenticocloud.com) [![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com) [![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
1
+ [![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com) [![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
3
2
 
4
3
  # Delivery Ruby SDK
5
4
 
@@ -260,8 +259,50 @@ delivery_client.type('coffee').execute do |response|
260
259
  field_type = response.type.elements.product_status.type # taxonomy
261
260
  end
262
261
  ```
262
+ The DeliveryTypeListingResponse also contains pagination data, similar to DeliveryItemListingResponse.
263
+
264
+ ## Taxonomy
265
+
266
+ Use the `.taxonomies` and `.taxonomy(code_name)` endpoints to get information about the taxonomy in your project:
267
+
268
+ ```ruby
269
+ # Get all taxonomies
270
+ delivery_client.taxonomies.execute do |response|
271
+ response.taxonomies.each do |tax|
272
+ puts "#{tax.system.name} (#{tax.terms.length})"
273
+ end
274
+ end
275
+
276
+ # Get terms of specific taxonomy
277
+ delivery_client.taxonomy('personas').execute do |response|
278
+ puts response.taxonomy.terms.length
279
+ end
280
+ ```
281
+
282
+ Each response will return either a single `Delivery::TaxonomyGroup` or an array of groups. The taxonomy group(s) are accessible at `.taxonomy` and `.taxonomies` for single and multiple queries, respectively.
263
283
 
264
- The DeliveryTypeListingResponse also contains pagination data, similar to DeliveryItemListingResponse.
284
+ The `TaxonomyGroup` object contains two attributes `.system` and `.terms` which are dynamic OStruct objects containing the same elements as a standard JSON reponse. For example, given a successful query you could access information about the first term of a group using:
285
+
286
+ ```ruby
287
+ taxonomy_group.terms[0].codename
288
+ ```
289
+
290
+ Note that the terms of a taxonomy group may also contain terms, for example in Dancing Goat's __Personas__ taxonomy group, which looks like this:
291
+
292
+ - Coffee expert
293
+ - Barista
294
+ - Cafe owner
295
+ - Coffee enthusiast
296
+ - Coffee lover
297
+ - Coffee blogger
298
+
299
+ To get the code name of the first term under the "Coffee expert" term, you could do this:
300
+
301
+ ```ruby
302
+ delivery_client.taxonomy('personas').execute do |response|
303
+ puts response.taxonomy.terms[0].terms[0].codename
304
+ end
305
+ ```
265
306
 
266
307
  ## Resolving links
267
308
 
@@ -2,11 +2,14 @@ require File.dirname(__FILE__) + '/delivery/client/delivery_client'
2
2
  require File.dirname(__FILE__) + '/delivery/client/delivery_query'
3
3
  require File.dirname(__FILE__) + '/delivery/models/content_item'
4
4
  require File.dirname(__FILE__) + '/delivery/models/content_type'
5
+ require File.dirname(__FILE__) + '/delivery/models/taxonomy_group'
5
6
  require File.dirname(__FILE__) + '/delivery/query_parameters/filters'
6
7
  require File.dirname(__FILE__) + '/delivery/responses/delivery_item_listing_response'
7
8
  require File.dirname(__FILE__) + '/delivery/responses/delivery_item_response'
8
9
  require File.dirname(__FILE__) + '/delivery/responses/delivery_type_listing_response'
9
10
  require File.dirname(__FILE__) + '/delivery/responses/delivery_type_response'
11
+ require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_listing_response'
12
+ require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_response'
10
13
  require File.dirname(__FILE__) + '/delivery/resolvers/content_link_resolver'
11
14
  require File.dirname(__FILE__) + '/delivery/resolvers/inline_content_item_resolver'
12
15
  require File.dirname(__FILE__) + '/delivery/builders/image_transformation_builder'
@@ -48,6 +48,12 @@ module Delivery
48
48
  else
49
49
  format(URL_TEMPLATE_TYPE, query.code_name)
50
50
  end
51
+ when Delivery::QUERY_TYPE_TAXONOMIES
52
+ if query.code_name.nil?
53
+ URL_TEMPLATE_TAXONOMIES
54
+ else
55
+ format(URL_TEMPLATE_TAXONOMY, query.code_name)
56
+ end
51
57
  end
52
58
  end
53
59
 
@@ -6,7 +6,8 @@ require 'json'
6
6
  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
+
10
11
  # Executes requests against the Kentico Cloud Delivery API.
11
12
  class DeliveryClient
12
13
  attr_accessor :use_preview
@@ -57,5 +58,19 @@ module Delivery
57
58
  q.preview_key = @preview_key
58
59
  q
59
60
  end
61
+
62
+ def taxonomies(query_parameters = [])
63
+ DeliveryQuery.new project_id: @project_id,
64
+ secure_key: @secure_key,
65
+ qp: query_parameters,
66
+ query_type: QUERY_TYPE_TAXONOMIES
67
+ end
68
+
69
+ def taxonomy(code_name)
70
+ DeliveryQuery.new project_id: @project_id,
71
+ secure_key: @secure_key,
72
+ code_name: code_name,
73
+ query_type: QUERY_TYPE_TAXONOMIES
74
+ end
60
75
  end
61
76
  end
@@ -163,6 +163,12 @@ module Delivery
163
163
  else
164
164
  Delivery::Responses::DeliveryTypeResponse.new JSON.parse(response)
165
165
  end
166
+ when Delivery::QUERY_TYPE_TAXONOMIES
167
+ if code_name.nil?
168
+ Delivery::Responses::DeliveryTaxonomyListingResponse.new JSON.parse(response)
169
+ else
170
+ Delivery::Responses::DeliveryTaxonomyResponse.new JSON.parse(response)
171
+ end
166
172
  end
167
173
  end
168
174
  end
@@ -0,0 +1,24 @@
1
+ module Delivery
2
+ # JSON data of a taxonomy group parsed as OpenStruct objects for dynamic use
3
+ class TaxonomyGroup
4
+ def terms
5
+ @terms unless @terms.nil?
6
+ @terms = JSON.parse(
7
+ JSON.generate(@source['terms']),
8
+ object_class: OpenStruct
9
+ )
10
+ end
11
+
12
+ def system
13
+ @system unless @system.nil?
14
+ @system = JSON.parse(
15
+ JSON.generate(@source['system']),
16
+ object_class: OpenStruct
17
+ )
18
+ end
19
+
20
+ def initialize(source)
21
+ @source = source
22
+ end
23
+ end
24
+ end
@@ -30,8 +30,7 @@ module Delivery
30
30
  @content_link_url_resolver = content_link_url_resolver
31
31
  @inline_content_item_resolver = inline_content_item_resolver
32
32
  super 200,
33
- "Success,
34
- #{items.length} items returned",
33
+ "Success, #{items.length} items returned",
35
34
  JSON.generate(@response)
36
35
  end
37
36
  end
@@ -19,8 +19,7 @@ module Delivery
19
19
  @content_link_url_resolver = content_link_url_resolver
20
20
  @inline_content_item_resolver = inline_content_item_resolver
21
21
  super 200,
22
- "Success,
23
- '#{item.system.code_name}' returned",
22
+ "Success, '#{item.system.code_name}' returned",
24
23
  JSON.generate(@response)
25
24
  end
26
25
  end
@@ -0,0 +1,32 @@
1
+ require 'delivery/models/taxonomy_group'
2
+ require 'delivery/models/pagination'
3
+ require 'delivery/responses/response_base'
4
+
5
+ module Delivery
6
+ module Responses
7
+ # Returned by DeliveryClient.taxonomies with an enumerable of TaxonomyGroups
8
+ class DeliveryTaxonomyListingResponse < ResponseBase
9
+ def pagination
10
+ @pagination unless @pagination.nil?
11
+ @pagination = Pagination.new @response['pagination']
12
+ end
13
+
14
+ def taxonomies
15
+ @taxonomies unless @taxonomies.nil?
16
+ taxonomies = []
17
+ @response['taxonomies'].each do |n|
18
+ taxonomies << Delivery::TaxonomyGroup.new(n)
19
+ end
20
+ @taxonomies = taxonomies
21
+ end
22
+
23
+ def initialize(response)
24
+ @response = response
25
+
26
+ super 200,
27
+ "Success, #{taxonomies.length} taxonomies returned",
28
+ JSON.generate(@response)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'delivery/models/taxonomy_group'
2
+ require 'delivery/responses/response_base'
3
+
4
+ module Delivery
5
+ module Responses
6
+ # Returned by DeliveryClient.taxonomy containing a single TaxonomyGroup
7
+ class DeliveryTaxonomyResponse < ResponseBase
8
+ def taxonomy
9
+ @taxonomy unless @taxonomy.nil?
10
+ @taxonomy = Delivery::TaxonomyGroup.new(@response)
11
+ end
12
+
13
+ def initialize(response)
14
+ @response = response
15
+
16
+ super 200,
17
+ "Success, '#{taxonomy.system.codename}' returned",
18
+ JSON.generate(@response)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -22,7 +22,9 @@ module Delivery
22
22
 
23
23
  def initialize(response)
24
24
  @response = response
25
- super 200, "Success, #{types.length} types returned"
25
+ super 200,
26
+ "Success, #{types.length} types returned",
27
+ JSON.generate(@response)
26
28
  end
27
29
  end
28
30
  end
@@ -12,7 +12,9 @@ module Delivery
12
12
 
13
13
  def initialize(response)
14
14
  @response = response
15
- super 200, "Success, type '#{type.system.codename}' returned"
15
+ super 200,
16
+ "Success, type '#{type.system.codename}' returned",
17
+ JSON.generate(@response)
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Delivery
2
- VERSION = '0.12.1'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delivery-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dugre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-20 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -111,6 +111,7 @@ files:
111
111
  - lib/delivery/models/content_item.rb
112
112
  - lib/delivery/models/content_type.rb
113
113
  - lib/delivery/models/pagination.rb
114
+ - lib/delivery/models/taxonomy_group.rb
114
115
  - lib/delivery/query_parameters/filters.rb
115
116
  - lib/delivery/query_parameters/parameter_base.rb
116
117
  - lib/delivery/query_parameters/query_string.rb
@@ -118,6 +119,8 @@ files:
118
119
  - lib/delivery/resolvers/inline_content_item_resolver.rb
119
120
  - lib/delivery/responses/delivery_item_listing_response.rb
120
121
  - lib/delivery/responses/delivery_item_response.rb
122
+ - lib/delivery/responses/delivery_taxonomy_listing_response.rb
123
+ - lib/delivery/responses/delivery_taxonomy_response.rb
121
124
  - lib/delivery/responses/delivery_type_listing_response.rb
122
125
  - lib/delivery/responses/delivery_type_response.rb
123
126
  - lib/delivery/responses/response_base.rb