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