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