kontent-delivery-sdk-ruby 2.0.18 → 2.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -21
- data/README.md +575 -576
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/delivery/builders/image_transformation_builder.rb +271 -271
- data/lib/delivery/builders/url_builder.rb +120 -120
- data/lib/delivery/client/delivery_client.rb +176 -176
- data/lib/delivery/client/delivery_query.rb +302 -302
- data/lib/delivery/client/request_manager.rb +125 -125
- data/lib/delivery/models/content_item.rb +153 -153
- data/lib/delivery/models/content_type.rb +41 -41
- data/lib/delivery/models/pagination.rb +22 -22
- data/lib/delivery/models/taxonomy_group.rb +39 -39
- data/lib/delivery/query_parameters/filters.rb +158 -158
- data/lib/delivery/query_parameters/parameter_base.rb +46 -46
- data/lib/delivery/query_parameters/query_string.rb +78 -78
- data/lib/delivery/resolvers/content_link_resolver.rb +102 -102
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +75 -75
- data/lib/delivery/resolvers/linked_item_resolver.rb +37 -37
- data/lib/delivery/responses/delivery_element_response.rb +34 -34
- data/lib/delivery/responses/delivery_item_listing_response.rb +54 -54
- data/lib/delivery/responses/delivery_item_response.rb +40 -40
- data/lib/delivery/responses/delivery_items_feed_response.rb +58 -58
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +47 -47
- data/lib/delivery/responses/delivery_taxonomy_response.rb +33 -33
- data/lib/delivery/responses/delivery_type_listing_response.rb +46 -46
- data/lib/delivery/responses/delivery_type_response.rb +32 -32
- data/lib/delivery/responses/response_base.rb +39 -39
- data/lib/delivery/tests/401.json +5 -5
- data/lib/delivery/tests/429.json +4 -4
- data/lib/delivery/tests/fake_responder.rb +110 -110
- data/lib/delivery/tests/filtering/items_gt.json +565 -565
- data/lib/delivery/tests/filtering/items_with_count.json +4985 -4985
- data/lib/delivery/tests/filtering/multiple.json +282 -282
- data/lib/delivery/tests/filtering/pagination_about_us.json +646 -646
- data/lib/delivery/tests/generic/items.json +4984 -4984
- data/lib/delivery/tests/generic/items/about_us.json +227 -227
- data/lib/delivery/tests/generic/items/aeropress_filters.json +138 -138
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +168 -168
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +620 -620
- data/lib/delivery/tests/generic/taxonomies.json +126 -126
- data/lib/delivery/tests/generic/types.json +780 -780
- data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +5 -5
- data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -39
- data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -78
- data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -104
- data/lib/delivery/version.rb +7 -7
- data/lib/kontent-delivery-sdk-ruby.rb +20 -20
- metadata +30 -11
@@ -1,120 +1,120 @@
|
|
1
|
-
module Kentico
|
2
|
-
module Kontent
|
3
|
-
module Delivery
|
4
|
-
module Builders
|
5
|
-
# Internal class which generates the URL required for Delivery REST API
|
6
|
-
class UrlBuilder
|
7
|
-
URL_TEMPLATE_BASE = 'https://deliver.kontent.ai/%s'.freeze
|
8
|
-
URL_TEMPLATE_PREVIEW = 'https://preview-deliver.kontent.ai/%s'.freeze
|
9
|
-
URL_TEMPLATE_ITEM = '/items/%s'.freeze
|
10
|
-
URL_TEMPLATE_ITEMS = '/items'.freeze
|
11
|
-
URL_TEMPLATE_TYPE = '/types/%s'.freeze
|
12
|
-
URL_TEMPLATE_TYPES = '/types'.freeze
|
13
|
-
URL_TEMPLATE_ELEMENTS = '/types/%s/elements/%s'.freeze
|
14
|
-
URL_TEMPLATE_TAXONOMY = '/taxonomies/%s'.freeze
|
15
|
-
URL_TEMPLATE_TAXONOMIES = '/taxonomies'.freeze
|
16
|
-
URL_TEMPLATE_ITEMS_FEED = '/items-feed'.freeze
|
17
|
-
|
18
|
-
URL_MAX_LENGTH = 65_519
|
19
|
-
MSG_LONG_QUERY = 'The request url is too long. Split your query into multiple calls.'.freeze
|
20
|
-
|
21
|
-
class << self
|
22
|
-
# Returns the proper domain for the request along with the
|
23
|
-
# query string parameters configured by the +DeliveryQuery+.
|
24
|
-
#
|
25
|
-
# * *Args*:
|
26
|
-
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
27
|
-
#
|
28
|
-
# * *Returns*:
|
29
|
-
# - +string+ The full URL for a Delivery request
|
30
|
-
def provide_url(query)
|
31
|
-
url = provide_base_url(query)
|
32
|
-
url += provide_path_part(query)
|
33
|
-
|
34
|
-
if query.query_string.empty?
|
35
|
-
url
|
36
|
-
else
|
37
|
-
url + query.query_string.to_s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Checks whether the provided URL is too long and raises an error if so.
|
42
|
-
#
|
43
|
-
# * *Args*:
|
44
|
-
# - *url* (+string+) A full Delivery URL
|
45
|
-
#
|
46
|
-
# * *Raises*:
|
47
|
-
# - +UriFormatException+ if the URL is 65,519 characters or more
|
48
|
-
def validate_url(url)
|
49
|
-
raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Returns relative path part of URL depending on query type.
|
55
|
-
#
|
56
|
-
# * *Args*:
|
57
|
-
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
58
|
-
#
|
59
|
-
# * *Returns*:
|
60
|
-
# - +string+ The URL path part (without protocol or domain)
|
61
|
-
def provide_path_part(query)
|
62
|
-
case query.query_type
|
63
|
-
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS
|
64
|
-
provide_item query
|
65
|
-
when Kentico::Kontent::Delivery::QUERY_TYPE_TYPES
|
66
|
-
provide_type query
|
67
|
-
when Kentico::Kontent::Delivery::QUERY_TYPE_TAXONOMIES
|
68
|
-
provide_taxonomy query
|
69
|
-
when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
|
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
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def provide_item(query)
|
77
|
-
if query.code_name.nil?
|
78
|
-
URL_TEMPLATE_ITEMS
|
79
|
-
else
|
80
|
-
format(URL_TEMPLATE_ITEM, query.code_name)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def provide_taxonomy(query)
|
85
|
-
if query.code_name.nil?
|
86
|
-
URL_TEMPLATE_TAXONOMIES
|
87
|
-
else
|
88
|
-
format(URL_TEMPLATE_TAXONOMY, query.code_name)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def provide_type(query)
|
93
|
-
if query.code_name.nil?
|
94
|
-
URL_TEMPLATE_TYPES
|
95
|
-
else
|
96
|
-
format(URL_TEMPLATE_TYPE, query.code_name)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Returns the protocol and domain with project ID. Domain changes
|
101
|
-
# according to the query's +use_preview+ attribute.
|
102
|
-
#
|
103
|
-
# * *Args*:
|
104
|
-
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
105
|
-
#
|
106
|
-
# * *Returns*:
|
107
|
-
# - +string+ The URL with the project ID
|
108
|
-
def provide_base_url(query)
|
109
|
-
if query.use_preview
|
110
|
-
format(URL_TEMPLATE_PREVIEW, query.project_id)
|
111
|
-
else
|
112
|
-
format(URL_TEMPLATE_BASE, query.project_id)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
module Builders
|
5
|
+
# Internal class which generates the URL required for Delivery REST API
|
6
|
+
class UrlBuilder
|
7
|
+
URL_TEMPLATE_BASE = 'https://deliver.kontent.ai/%s'.freeze
|
8
|
+
URL_TEMPLATE_PREVIEW = 'https://preview-deliver.kontent.ai/%s'.freeze
|
9
|
+
URL_TEMPLATE_ITEM = '/items/%s'.freeze
|
10
|
+
URL_TEMPLATE_ITEMS = '/items'.freeze
|
11
|
+
URL_TEMPLATE_TYPE = '/types/%s'.freeze
|
12
|
+
URL_TEMPLATE_TYPES = '/types'.freeze
|
13
|
+
URL_TEMPLATE_ELEMENTS = '/types/%s/elements/%s'.freeze
|
14
|
+
URL_TEMPLATE_TAXONOMY = '/taxonomies/%s'.freeze
|
15
|
+
URL_TEMPLATE_TAXONOMIES = '/taxonomies'.freeze
|
16
|
+
URL_TEMPLATE_ITEMS_FEED = '/items-feed'.freeze
|
17
|
+
|
18
|
+
URL_MAX_LENGTH = 65_519
|
19
|
+
MSG_LONG_QUERY = 'The request url is too long. Split your query into multiple calls.'.freeze
|
20
|
+
|
21
|
+
class << self
|
22
|
+
# Returns the proper domain for the request along with the
|
23
|
+
# query string parameters configured by the +DeliveryQuery+.
|
24
|
+
#
|
25
|
+
# * *Args*:
|
26
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
27
|
+
#
|
28
|
+
# * *Returns*:
|
29
|
+
# - +string+ The full URL for a Delivery request
|
30
|
+
def provide_url(query)
|
31
|
+
url = provide_base_url(query)
|
32
|
+
url += provide_path_part(query)
|
33
|
+
|
34
|
+
if query.query_string.empty?
|
35
|
+
url
|
36
|
+
else
|
37
|
+
url + query.query_string.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Checks whether the provided URL is too long and raises an error if so.
|
42
|
+
#
|
43
|
+
# * *Args*:
|
44
|
+
# - *url* (+string+) A full Delivery URL
|
45
|
+
#
|
46
|
+
# * *Raises*:
|
47
|
+
# - +UriFormatException+ if the URL is 65,519 characters or more
|
48
|
+
def validate_url(url)
|
49
|
+
raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Returns relative path part of URL depending on query type.
|
55
|
+
#
|
56
|
+
# * *Args*:
|
57
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
58
|
+
#
|
59
|
+
# * *Returns*:
|
60
|
+
# - +string+ The URL path part (without protocol or domain)
|
61
|
+
def provide_path_part(query)
|
62
|
+
case query.query_type
|
63
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS
|
64
|
+
provide_item query
|
65
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_TYPES
|
66
|
+
provide_type query
|
67
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_TAXONOMIES
|
68
|
+
provide_taxonomy query
|
69
|
+
when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
|
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
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def provide_item(query)
|
77
|
+
if query.code_name.nil?
|
78
|
+
URL_TEMPLATE_ITEMS
|
79
|
+
else
|
80
|
+
format(URL_TEMPLATE_ITEM, query.code_name)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def provide_taxonomy(query)
|
85
|
+
if query.code_name.nil?
|
86
|
+
URL_TEMPLATE_TAXONOMIES
|
87
|
+
else
|
88
|
+
format(URL_TEMPLATE_TAXONOMY, query.code_name)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def provide_type(query)
|
93
|
+
if query.code_name.nil?
|
94
|
+
URL_TEMPLATE_TYPES
|
95
|
+
else
|
96
|
+
format(URL_TEMPLATE_TYPE, query.code_name)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns the protocol and domain with project ID. Domain changes
|
101
|
+
# according to the query's +use_preview+ attribute.
|
102
|
+
#
|
103
|
+
# * *Args*:
|
104
|
+
# - *query* ( Kentico::Kontent::Delivery::DeliveryQuery )
|
105
|
+
#
|
106
|
+
# * *Returns*:
|
107
|
+
# - +string+ The URL with the project ID
|
108
|
+
def provide_base_url(query)
|
109
|
+
if query.use_preview
|
110
|
+
format(URL_TEMPLATE_PREVIEW, query.project_id)
|
111
|
+
else
|
112
|
+
format(URL_TEMPLATE_BASE, query.project_id)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,176 +1,176 @@
|
|
1
|
-
require 'delivery/client/delivery_query'
|
2
|
-
require 'delivery/responses/delivery_item_listing_response'
|
3
|
-
require 'delivery/responses/delivery_item_response'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module Kentico
|
7
|
-
module Kontent
|
8
|
-
module Delivery
|
9
|
-
QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
|
10
|
-
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
11
|
-
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
12
|
-
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
13
|
-
QUERY_TYPE_ITEMS_FEED = 'QUERY_TYPE_ITEMS_FEED'.freeze
|
14
|
-
|
15
|
-
# Executes requests against the Kentico Kontent Delivery API.
|
16
|
-
class DeliveryClient
|
17
|
-
attr_accessor :use_preview
|
18
|
-
|
19
|
-
# Constructor. Accepts a hash with the options for client.
|
20
|
-
#
|
21
|
-
# * *Args*:
|
22
|
-
# - *config* (+Hash+) May contain the following keys:
|
23
|
-
# - project_id (+string+) _required_
|
24
|
-
# - preview_key (+string+)
|
25
|
-
# - secure_key (+string+)
|
26
|
-
# - content_link_url_resolver ( Kentico::Kontent::Delivery::Resolvers::ContentLinkResolver )
|
27
|
-
# - inline_content_item_resolver ( Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver )
|
28
|
-
# - with_retry_policy (+bool+)
|
29
|
-
def initialize(config)
|
30
|
-
@project_id = config.fetch(:project_id)
|
31
|
-
@preview_key = config.fetch(:preview_key, nil)
|
32
|
-
@secure_key = config.fetch(:secure_key, nil)
|
33
|
-
@content_link_url_resolver = config.fetch(:content_link_url_resolver, nil)
|
34
|
-
@inline_content_item_resolver = config.fetch(:inline_content_item_resolver, nil)
|
35
|
-
@with_retry_policy = config.fetch(:with_retry_policy, true)
|
36
|
-
self.use_preview = !@preview_key.nil?
|
37
|
-
end
|
38
|
-
|
39
|
-
# Return all content types of the project
|
40
|
-
#
|
41
|
-
# * *Returns*:
|
42
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
43
|
-
def types
|
44
|
-
DeliveryQuery.new project_id: @project_id,
|
45
|
-
secure_key: @secure_key,
|
46
|
-
query_type: QUERY_TYPE_TYPES,
|
47
|
-
with_retry_policy: @with_retry_policy
|
48
|
-
end
|
49
|
-
|
50
|
-
# Return a single content type of the project
|
51
|
-
#
|
52
|
-
# * *Args*:
|
53
|
-
# - *code_name* (+string+) Code name of the desired content type
|
54
|
-
#
|
55
|
-
# * *Returns*:
|
56
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
57
|
-
def type(code_name)
|
58
|
-
DeliveryQuery.new project_id: @project_id,
|
59
|
-
secure_key: @secure_key,
|
60
|
-
code_name: code_name,
|
61
|
-
query_type: QUERY_TYPE_TYPES,
|
62
|
-
with_retry_policy: @with_retry_policy
|
63
|
-
end
|
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
|
-
|
85
|
-
# Return all content items of the project
|
86
|
-
#
|
87
|
-
# * *Args*:
|
88
|
-
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
89
|
-
#
|
90
|
-
# * *Returns*:
|
91
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
92
|
-
def items(query_parameters = [])
|
93
|
-
q = DeliveryQuery.new project_id: @project_id,
|
94
|
-
secure_key: @secure_key,
|
95
|
-
qp: query_parameters,
|
96
|
-
content_link_url_resolver: @content_link_url_resolver,
|
97
|
-
inline_content_item_resolver: @inline_content_item_resolver,
|
98
|
-
query_type: QUERY_TYPE_ITEMS,
|
99
|
-
with_retry_policy: @with_retry_policy
|
100
|
-
q.use_preview = use_preview
|
101
|
-
q.preview_key = @preview_key
|
102
|
-
q
|
103
|
-
end
|
104
|
-
|
105
|
-
# Return a single content item of the project
|
106
|
-
#
|
107
|
-
# * *Args*:
|
108
|
-
# - *code_name* (+string+) The code name of the desired content item
|
109
|
-
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
110
|
-
#
|
111
|
-
# * *Returns*:
|
112
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
113
|
-
def item(code_name, query_parameters = [])
|
114
|
-
q = DeliveryQuery.new project_id: @project_id,
|
115
|
-
secure_key: @secure_key,
|
116
|
-
code_name: code_name,
|
117
|
-
qp: query_parameters,
|
118
|
-
content_link_url_resolver: @content_link_url_resolver,
|
119
|
-
inline_content_item_resolver: @inline_content_item_resolver,
|
120
|
-
query_type: QUERY_TYPE_ITEMS,
|
121
|
-
with_retry_policy: @with_retry_policy
|
122
|
-
q.use_preview = use_preview
|
123
|
-
q.preview_key = @preview_key
|
124
|
-
q
|
125
|
-
end
|
126
|
-
|
127
|
-
# Return all taxonomy groups of the project
|
128
|
-
#
|
129
|
-
# * *Args*:
|
130
|
-
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
131
|
-
#
|
132
|
-
# * *Returns*:
|
133
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
134
|
-
def taxonomies(query_parameters = [])
|
135
|
-
DeliveryQuery.new project_id: @project_id,
|
136
|
-
secure_key: @secure_key,
|
137
|
-
qp: query_parameters,
|
138
|
-
query_type: QUERY_TYPE_TAXONOMIES,
|
139
|
-
with_retry_policy: @with_retry_policy
|
140
|
-
end
|
141
|
-
|
142
|
-
# Return a single taxonomy group of the project
|
143
|
-
#
|
144
|
-
# * *Args*:
|
145
|
-
# - *code_name* (+string+) The code name of the desired taxonomy group
|
146
|
-
#
|
147
|
-
# * *Returns*:
|
148
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
149
|
-
def taxonomy(code_name)
|
150
|
-
DeliveryQuery.new project_id: @project_id,
|
151
|
-
secure_key: @secure_key,
|
152
|
-
code_name: code_name,
|
153
|
-
query_type: QUERY_TYPE_TAXONOMIES,
|
154
|
-
with_retry_policy: @with_retry_policy
|
155
|
-
end
|
156
|
-
|
157
|
-
# Return a single element of a content type
|
158
|
-
#
|
159
|
-
# * *Args*:
|
160
|
-
# - *content_type* (+string+) The code name of the content type containing the element
|
161
|
-
# - *element* (+string+) The code name of the desired element
|
162
|
-
#
|
163
|
-
# * *Returns*:
|
164
|
-
# - Kentico::Kontent::Delivery::DeliveryQuery
|
165
|
-
def element(content_type, element)
|
166
|
-
DeliveryQuery.new project_id: @project_id,
|
167
|
-
secure_key: @secure_key,
|
168
|
-
code_name: element,
|
169
|
-
content_type: content_type,
|
170
|
-
query_type: QUERY_TYPE_ELEMENT,
|
171
|
-
with_retry_policy: @with_retry_policy
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
1
|
+
require 'delivery/client/delivery_query'
|
2
|
+
require 'delivery/responses/delivery_item_listing_response'
|
3
|
+
require 'delivery/responses/delivery_item_response'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Kentico
|
7
|
+
module Kontent
|
8
|
+
module Delivery
|
9
|
+
QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
|
10
|
+
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
11
|
+
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
12
|
+
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
13
|
+
QUERY_TYPE_ITEMS_FEED = 'QUERY_TYPE_ITEMS_FEED'.freeze
|
14
|
+
|
15
|
+
# Executes requests against the Kentico Kontent Delivery API.
|
16
|
+
class DeliveryClient
|
17
|
+
attr_accessor :use_preview
|
18
|
+
|
19
|
+
# Constructor. Accepts a hash with the options for client.
|
20
|
+
#
|
21
|
+
# * *Args*:
|
22
|
+
# - *config* (+Hash+) May contain the following keys:
|
23
|
+
# - project_id (+string+) _required_
|
24
|
+
# - preview_key (+string+)
|
25
|
+
# - secure_key (+string+)
|
26
|
+
# - content_link_url_resolver ( Kentico::Kontent::Delivery::Resolvers::ContentLinkResolver )
|
27
|
+
# - inline_content_item_resolver ( Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver )
|
28
|
+
# - with_retry_policy (+bool+)
|
29
|
+
def initialize(config)
|
30
|
+
@project_id = config.fetch(:project_id)
|
31
|
+
@preview_key = config.fetch(:preview_key, nil)
|
32
|
+
@secure_key = config.fetch(:secure_key, nil)
|
33
|
+
@content_link_url_resolver = config.fetch(:content_link_url_resolver, nil)
|
34
|
+
@inline_content_item_resolver = config.fetch(:inline_content_item_resolver, nil)
|
35
|
+
@with_retry_policy = config.fetch(:with_retry_policy, true)
|
36
|
+
self.use_preview = !@preview_key.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return all content types of the project
|
40
|
+
#
|
41
|
+
# * *Returns*:
|
42
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
43
|
+
def types
|
44
|
+
DeliveryQuery.new project_id: @project_id,
|
45
|
+
secure_key: @secure_key,
|
46
|
+
query_type: QUERY_TYPE_TYPES,
|
47
|
+
with_retry_policy: @with_retry_policy
|
48
|
+
end
|
49
|
+
|
50
|
+
# Return a single content type of the project
|
51
|
+
#
|
52
|
+
# * *Args*:
|
53
|
+
# - *code_name* (+string+) Code name of the desired content type
|
54
|
+
#
|
55
|
+
# * *Returns*:
|
56
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
57
|
+
def type(code_name)
|
58
|
+
DeliveryQuery.new project_id: @project_id,
|
59
|
+
secure_key: @secure_key,
|
60
|
+
code_name: code_name,
|
61
|
+
query_type: QUERY_TYPE_TYPES,
|
62
|
+
with_retry_policy: @with_retry_policy
|
63
|
+
end
|
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
|
+
|
85
|
+
# Return all content items of the project
|
86
|
+
#
|
87
|
+
# * *Args*:
|
88
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
89
|
+
#
|
90
|
+
# * *Returns*:
|
91
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
92
|
+
def items(query_parameters = [])
|
93
|
+
q = DeliveryQuery.new project_id: @project_id,
|
94
|
+
secure_key: @secure_key,
|
95
|
+
qp: query_parameters,
|
96
|
+
content_link_url_resolver: @content_link_url_resolver,
|
97
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
98
|
+
query_type: QUERY_TYPE_ITEMS,
|
99
|
+
with_retry_policy: @with_retry_policy
|
100
|
+
q.use_preview = use_preview
|
101
|
+
q.preview_key = @preview_key
|
102
|
+
q
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return a single content item of the project
|
106
|
+
#
|
107
|
+
# * *Args*:
|
108
|
+
# - *code_name* (+string+) The code name of the desired content item
|
109
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
110
|
+
#
|
111
|
+
# * *Returns*:
|
112
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
113
|
+
def item(code_name, query_parameters = [])
|
114
|
+
q = DeliveryQuery.new project_id: @project_id,
|
115
|
+
secure_key: @secure_key,
|
116
|
+
code_name: code_name,
|
117
|
+
qp: query_parameters,
|
118
|
+
content_link_url_resolver: @content_link_url_resolver,
|
119
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
120
|
+
query_type: QUERY_TYPE_ITEMS,
|
121
|
+
with_retry_policy: @with_retry_policy
|
122
|
+
q.use_preview = use_preview
|
123
|
+
q.preview_key = @preview_key
|
124
|
+
q
|
125
|
+
end
|
126
|
+
|
127
|
+
# Return all taxonomy groups of the project
|
128
|
+
#
|
129
|
+
# * *Args*:
|
130
|
+
# - *query_parameters* (+Array+) _optional_ One or more Kentico::Kontent::Delivery::QueryParameters::Filter objects. A single object will automatically be converted into an Array.
|
131
|
+
#
|
132
|
+
# * *Returns*:
|
133
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
134
|
+
def taxonomies(query_parameters = [])
|
135
|
+
DeliveryQuery.new project_id: @project_id,
|
136
|
+
secure_key: @secure_key,
|
137
|
+
qp: query_parameters,
|
138
|
+
query_type: QUERY_TYPE_TAXONOMIES,
|
139
|
+
with_retry_policy: @with_retry_policy
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return a single taxonomy group of the project
|
143
|
+
#
|
144
|
+
# * *Args*:
|
145
|
+
# - *code_name* (+string+) The code name of the desired taxonomy group
|
146
|
+
#
|
147
|
+
# * *Returns*:
|
148
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
149
|
+
def taxonomy(code_name)
|
150
|
+
DeliveryQuery.new project_id: @project_id,
|
151
|
+
secure_key: @secure_key,
|
152
|
+
code_name: code_name,
|
153
|
+
query_type: QUERY_TYPE_TAXONOMIES,
|
154
|
+
with_retry_policy: @with_retry_policy
|
155
|
+
end
|
156
|
+
|
157
|
+
# Return a single element of a content type
|
158
|
+
#
|
159
|
+
# * *Args*:
|
160
|
+
# - *content_type* (+string+) The code name of the content type containing the element
|
161
|
+
# - *element* (+string+) The code name of the desired element
|
162
|
+
#
|
163
|
+
# * *Returns*:
|
164
|
+
# - Kentico::Kontent::Delivery::DeliveryQuery
|
165
|
+
def element(content_type, element)
|
166
|
+
DeliveryQuery.new project_id: @project_id,
|
167
|
+
secure_key: @secure_key,
|
168
|
+
code_name: element,
|
169
|
+
content_type: content_type,
|
170
|
+
query_type: QUERY_TYPE_ELEMENT,
|
171
|
+
with_retry_policy: @with_retry_policy
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|