delivery-sdk-ruby 1.0.5 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -48
- 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/tests/filtering/items_gt.json +4 -4
- data/lib/delivery/tests/filtering/multiple.json +2 -2
- data/lib/delivery/tests/filtering/pagination_about_us.json +3 -3
- data/lib/delivery/tests/generic/items.json +25 -25
- data/lib/delivery/tests/generic/items/about_us.json +1 -1
- data/lib/delivery/tests/generic/items/aeropress_filters.json +1 -1
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +1 -1
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +4 -4
- data/lib/delivery/version.rb +5 -3
- data/lib/kontent-delivery-sdk-ruby.rb +19 -0
- metadata +38 -23
@@ -1,35 +1,37 @@
|
|
1
1
|
require 'delivery/models/content_item'
|
2
2
|
require 'delivery/responses/response_base'
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
4
|
+
module Kentico
|
5
|
+
module Kontent
|
6
|
+
module Delivery
|
7
|
+
module Responses
|
8
|
+
# The response of a successful query for a content item.
|
9
|
+
# See https://github.com/Kentico/kontent-delivery-sdk-ruby#listing-items
|
10
|
+
class DeliveryItemResponse < ResponseBase
|
11
|
+
# A Kentico::Kontent::Delivery::ContentItem object from a
|
12
|
+
# Kentico::Kontent::Delivery::DeliveryClient.item call.
|
13
|
+
#
|
14
|
+
# * *Returns*:
|
15
|
+
# - Kentico::Kontent::Delivery::ContentItem
|
16
|
+
def item
|
17
|
+
@item unless @item.nil?
|
18
|
+
linked_items_resolver = Kentico::Kontent::Delivery::Resolvers::LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
|
19
|
+
@item = Kentico::Kontent::Delivery::ContentItem.new(
|
20
|
+
@response,
|
21
|
+
@content_link_url_resolver,
|
22
|
+
@inline_content_item_resolver,
|
23
|
+
linked_items_resolver
|
24
|
+
)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def initialize(response, content_link_url_resolver, inline_content_item_resolver)
|
28
|
+
@response = response
|
29
|
+
@content_link_url_resolver = content_link_url_resolver
|
30
|
+
@inline_content_item_resolver = inline_content_item_resolver
|
31
|
+
super 200,
|
32
|
+
"Success, '#{item.system.codename}' returned",
|
33
|
+
JSON.generate(@response)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -2,41 +2,43 @@ require 'delivery/models/taxonomy_group'
|
|
2
2
|
require 'delivery/models/pagination'
|
3
3
|
require 'delivery/responses/response_base'
|
4
4
|
|
5
|
-
module
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
module Kentico
|
6
|
+
module Kontent
|
7
|
+
module Delivery
|
8
|
+
module Responses
|
9
|
+
# The response of a successful query for taxonomy groups.
|
10
|
+
# See https://github.com/Kentico/kontent-delivery-sdk-ruby#taxonomy
|
11
|
+
class DeliveryTaxonomyListingResponse < ResponseBase
|
12
|
+
# Parses the 'pagination' JSON node of the response.
|
13
|
+
#
|
14
|
+
# * *Returns*:
|
15
|
+
# - Kentico::Kontent::Delivery::Pagination
|
16
|
+
def pagination
|
17
|
+
@pagination unless @pagination.nil?
|
18
|
+
@pagination = Pagination.new @response['pagination']
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
# Parses the 'taxonomies' JSON node of the response from a
|
22
|
+
# Kentico::Kontent::Delivery::DeliveryClient.taxonomies call.
|
23
|
+
#
|
24
|
+
# * *Returns*:
|
25
|
+
# - +Array+ The taxonomy groups as Kentico::Kontent::Delivery::TaxonomyGroup objects
|
26
|
+
def taxonomies
|
27
|
+
@taxonomies unless @taxonomies.nil?
|
28
|
+
taxonomies = []
|
29
|
+
@response['taxonomies'].each do |n|
|
30
|
+
taxonomies << Kentico::Kontent::Delivery::TaxonomyGroup.new(n)
|
31
|
+
end
|
32
|
+
@taxonomies = taxonomies
|
30
33
|
end
|
31
|
-
@taxonomies = taxonomies
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
def initialize(response)
|
36
|
+
@response = response
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
super 200,
|
39
|
+
"Success, #{taxonomies.length} taxonomies returned",
|
40
|
+
JSON.generate(@response)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -1,28 +1,30 @@
|
|
1
1
|
require 'delivery/models/taxonomy_group'
|
2
2
|
require 'delivery/responses/response_base'
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
module Kentico
|
5
|
+
module Kontent
|
6
|
+
module Delivery
|
7
|
+
module Responses
|
8
|
+
# The response of a successful query for a taxonomy group.
|
9
|
+
# See https://github.com/Kentico/kontent-delivery-sdk-ruby#taxonomy
|
10
|
+
class DeliveryTaxonomyResponse < ResponseBase
|
11
|
+
# Parses the response from a
|
12
|
+
# Kentico::Kontent::Delivery::DeliveryClient.taxonomy call.
|
13
|
+
#
|
14
|
+
# * *Returns*:
|
15
|
+
# - Kentico::Kontent::Delivery::TaxonomyGroup
|
16
|
+
def taxonomy
|
17
|
+
@taxonomy unless @taxonomy.nil?
|
18
|
+
@taxonomy = Kentico::Kontent::Delivery::TaxonomyGroup.new(@response)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def initialize(response)
|
22
|
+
@response = response
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
super 200,
|
25
|
+
"Success, '#{taxonomy.system.codename}' returned",
|
26
|
+
JSON.generate(@response)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -2,40 +2,42 @@ require 'delivery/models/content_type'
|
|
2
2
|
require 'delivery/models/pagination'
|
3
3
|
require 'delivery/responses/response_base'
|
4
4
|
|
5
|
-
module
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
module Kentico
|
6
|
+
module Kontent
|
7
|
+
module Delivery
|
8
|
+
module Responses
|
9
|
+
# The response of a successful query for content types.
|
10
|
+
# See https://github.com/Kentico/kontent-delivery-sdk-ruby#retrieving-content-types
|
11
|
+
class DeliveryTypeListingResponse < ResponseBase
|
12
|
+
# Parses the 'pagination' JSON node of the response.
|
13
|
+
#
|
14
|
+
# * *Returns*:
|
15
|
+
# - Kentico::Kontent::Delivery::Pagination
|
16
|
+
def pagination
|
17
|
+
@pagination unless @pagination.nil?
|
18
|
+
@pagination = Pagination.new @response['pagination']
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
# Parses the 'types' JSON node of the response from a
|
22
|
+
# Kentico::Kontent::Delivery::DeliveryClient.types call.
|
23
|
+
#
|
24
|
+
# * *Returns*:
|
25
|
+
# - +Array+ The content types as Kentico::Kontent::Delivery::ContentType objects
|
26
|
+
def types
|
27
|
+
@types unless @types.nil?
|
28
|
+
types = []
|
29
|
+
@response['types'].each do |n|
|
30
|
+
types << Kentico::Kontent::Delivery::ContentType.new(n)
|
31
|
+
end
|
32
|
+
@types = types
|
30
33
|
end
|
31
|
-
@types = types
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def initialize(response)
|
36
|
+
@response = response
|
37
|
+
super 200,
|
38
|
+
"Success, #{types.length} types returned",
|
39
|
+
JSON.generate(@response)
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,27 +1,29 @@
|
|
1
1
|
require 'delivery/models/content_type'
|
2
2
|
require 'delivery/responses/response_base'
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
module Kentico
|
5
|
+
module Kontent
|
6
|
+
module Delivery
|
7
|
+
module Responses
|
8
|
+
# The response of a successful query for a content type.
|
9
|
+
# See https://github.com/Kentico/kontent-delivery-sdk-ruby#retrieving-content-types
|
10
|
+
class DeliveryTypeResponse < ResponseBase
|
11
|
+
# A Kentico::Kontent::Delivery::ContentType object from a
|
12
|
+
# Kentico::Kontent::Delivery::DeliveryClient.type call.
|
13
|
+
#
|
14
|
+
# * *Returns*:
|
15
|
+
# - Kentico::Kontent::Delivery::ContentType
|
16
|
+
def type
|
17
|
+
@type unless @type.nil?
|
18
|
+
@type = Kentico::Kontent::Delivery::ContentType.new(@response)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def initialize(response)
|
22
|
+
@response = response
|
23
|
+
super 200,
|
24
|
+
"Success, type '#{type.system.codename}' returned",
|
25
|
+
JSON.generate(@response)
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
module Responses
|
5
|
+
# Base class for all responses from a
|
6
|
+
# Kentico::Kontent::Delivery::DeliveryQuery.execute call.
|
7
|
+
class ResponseBase
|
8
|
+
attr_accessor :http_code,
|
9
|
+
:message,
|
10
|
+
:json
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
# Constructor.
|
13
|
+
#
|
14
|
+
# * *Args*:
|
15
|
+
# - *http_code* (+integer+) The status code returned by the REST request
|
16
|
+
# - *message* (+string+) An informative message about the response, visible when calling +to_s+
|
17
|
+
# - *json* (+string+) _optional_ The complete, unmodified JSON response from the server
|
18
|
+
def initialize(http_code, message, json = '')
|
19
|
+
self.http_code = http_code
|
20
|
+
self.message = message
|
21
|
+
self.json = json
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# Provides an informative message about the success of the request
|
25
|
+
# by combining the status code and message.
|
26
|
+
#
|
27
|
+
# * *Returns*:
|
28
|
+
# - +string+
|
29
|
+
def to_s
|
30
|
+
"Response is status code #{http_code} with message:\n#{message}"
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -2,61 +2,63 @@ require 'dotenv/load'
|
|
2
2
|
require 'pathname'
|
3
3
|
require 'cgi'
|
4
4
|
|
5
|
-
module
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
module Kentico
|
6
|
+
module Kontent
|
7
|
+
module Delivery
|
8
|
+
module Tests
|
9
|
+
class FakeResponder
|
10
|
+
PROJECT_ID = ENV['PROJECT_ID']
|
11
|
+
IS_SECURE = ENV['TEST_SECURE_API_ENABLED']
|
12
|
+
SECURE_KEY = ENV['SECURE_KEY']
|
13
|
+
PREVIEW_KEY = ENV['PREVIEW_KEY']
|
14
|
+
BASE_URL = "https://deliver.kontent.ai/#{PROJECT_ID}".freeze
|
15
|
+
PREVIEW_URL = "https://preview-deliver.kontent.ai/#{PROJECT_ID}".freeze
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
url =
|
27
|
-
if @query.should_preview
|
28
|
-
url[PREVIEW_URL.length...url.length]
|
29
|
-
else
|
30
|
-
url[BASE_URL.length...url.length]
|
17
|
+
class << self
|
18
|
+
def get_response(query, url, headers)
|
19
|
+
@query = query
|
20
|
+
if IS_SECURE && !(
|
21
|
+
headers['Authorization'] == "Bearer #{SECURE_KEY}" ||
|
22
|
+
headers['Authorization'] == "Bearer #{PREVIEW_KEY}"
|
23
|
+
)
|
24
|
+
return respond_401
|
31
25
|
end
|
32
26
|
|
33
|
-
|
34
|
-
|
27
|
+
url =
|
28
|
+
if @query.should_preview
|
29
|
+
url[PREVIEW_URL.length...url.length]
|
30
|
+
else
|
31
|
+
url[BASE_URL.length...url.length]
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
34
|
+
qs = url.contains('?') ? url.split('?')[1] : nil
|
35
|
+
return respond_filtering qs unless qs.nil? # e.g. /items/about_us?skip=0&limit=5
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
path.read if path.exist?
|
42
|
-
end
|
37
|
+
respond_generic url # Didn't match other clauses, so response should be located in corresponding filepath
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
Pathname.new(File.dirname(__FILE__) + '/filtering/pagination_about_us.json')
|
49
|
-
when 'elements.price[gt]=20'
|
50
|
-
Pathname.new(File.dirname(__FILE__) + '/filtering/items_gt.json')
|
51
|
-
when 'elements.price[gt]=20&system.type=grinder'
|
52
|
-
Pathname.new(File.dirname(__FILE__) + '/filtering/multiple.json')
|
53
|
-
end
|
54
|
-
path.read unless path.nil? && !path.exist?
|
55
|
-
end
|
40
|
+
def respond_generic(url)
|
41
|
+
path = Pathname.new(File.dirname(__FILE__) + "/generic#{url}.json")
|
42
|
+
path.read if path.exist?
|
43
|
+
end
|
56
44
|
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
def respond_filtering(query)
|
46
|
+
path =
|
47
|
+
case CGI.unescape query
|
48
|
+
when 'skip=0&limit=5'
|
49
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/pagination_about_us.json')
|
50
|
+
when 'elements.price[gt]=20'
|
51
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/items_gt.json')
|
52
|
+
when 'elements.price[gt]=20&system.type=grinder'
|
53
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/multiple.json')
|
54
|
+
end
|
55
|
+
path.read unless path.nil? && !path.exist?
|
56
|
+
end
|
57
|
+
|
58
|
+
def respond_401
|
59
|
+
path = Pathname.new(File.dirname(__FILE__) + '/401.json')
|
60
|
+
Kentico::Kontent::Delivery::Responses::ResponseBase.new 401, '', path.read if path.exist?
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|