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,35 +1,37 @@
1
1
  require 'delivery/models/content_item'
2
2
  require 'delivery/responses/response_base'
3
3
 
4
- module KenticoCloud
5
- module Delivery
6
- module Responses
7
- # The response of a successful query for a content item.
8
- # See https://github.com/Kentico/delivery-sdk-ruby#listing-items
9
- class DeliveryItemResponse < ResponseBase
10
- # A KenticoCloud::Delivery::ContentItem object from a
11
- # KenticoCloud::Delivery::DeliveryClient.item call.
12
- #
13
- # * *Returns*:
14
- # - KenticoCloud::Delivery::ContentItem
15
- def item
16
- @item unless @item.nil?
17
- linked_items_resolver = KenticoCloud::Delivery::Resolvers::LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
18
- @item = KenticoCloud::Delivery::ContentItem.new(
19
- @response,
20
- @content_link_url_resolver,
21
- @inline_content_item_resolver,
22
- linked_items_resolver
23
- )
24
- end
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
- def initialize(response, content_link_url_resolver, inline_content_item_resolver)
27
- @response = response
28
- @content_link_url_resolver = content_link_url_resolver
29
- @inline_content_item_resolver = inline_content_item_resolver
30
- super 200,
31
- "Success, '#{item.system.codename}' returned",
32
- JSON.generate(@response)
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 KenticoCloud
6
- module Delivery
7
- module Responses
8
- # The response of a successful query for taxonomy groups.
9
- # See https://github.com/Kentico/delivery-sdk-ruby#taxonomy
10
- class DeliveryTaxonomyListingResponse < ResponseBase
11
- # Parses the 'pagination' JSON node of the response.
12
- #
13
- # * *Returns*:
14
- # - KenticoCloud::Delivery::Pagination
15
- def pagination
16
- @pagination unless @pagination.nil?
17
- @pagination = Pagination.new @response['pagination']
18
- end
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
- # Parses the 'taxonomies' JSON node of the response from a
21
- # KenticoCloud::Delivery::DeliveryClient.taxonomies call.
22
- #
23
- # * *Returns*:
24
- # - +Array+ The taxonomy groups as KenticoCloud::Delivery::TaxonomyGroup objects
25
- def taxonomies
26
- @taxonomies unless @taxonomies.nil?
27
- taxonomies = []
28
- @response['taxonomies'].each do |n|
29
- taxonomies << KenticoCloud::Delivery::TaxonomyGroup.new(n)
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
- def initialize(response)
35
- @response = response
35
+ def initialize(response)
36
+ @response = response
36
37
 
37
- super 200,
38
- "Success, #{taxonomies.length} taxonomies returned",
39
- JSON.generate(@response)
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 KenticoCloud
5
- module Delivery
6
- module Responses
7
- # The response of a successful query for a taxonomy group.
8
- # See https://github.com/Kentico/delivery-sdk-ruby#taxonomy
9
- class DeliveryTaxonomyResponse < ResponseBase
10
- # Parses the response from a
11
- # KenticoCloud::Delivery::DeliveryClient.taxonomy call.
12
- #
13
- # * *Returns*:
14
- # - KenticoCloud::Delivery::TaxonomyGroup
15
- def taxonomy
16
- @taxonomy unless @taxonomy.nil?
17
- @taxonomy = KenticoCloud::Delivery::TaxonomyGroup.new(@response)
18
- end
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
- def initialize(response)
21
- @response = response
21
+ def initialize(response)
22
+ @response = response
22
23
 
23
- super 200,
24
- "Success, '#{taxonomy.system.codename}' returned",
25
- JSON.generate(@response)
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 KenticoCloud
6
- module Delivery
7
- module Responses
8
- # The response of a successful query for content types.
9
- # See https://github.com/Kentico/delivery-sdk-ruby#retrieving-content-types
10
- class DeliveryTypeListingResponse < ResponseBase
11
- # Parses the 'pagination' JSON node of the response.
12
- #
13
- # * *Returns*:
14
- # - KenticoCloud::Delivery::Pagination
15
- def pagination
16
- @pagination unless @pagination.nil?
17
- @pagination = Pagination.new @response['pagination']
18
- end
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
- # Parses the 'types' JSON node of the response from a
21
- # KenticoCloud::Delivery::DeliveryClient.types call.
22
- #
23
- # * *Returns*:
24
- # - +Array+ The content types as KenticoCloud::Delivery::ContentType objects
25
- def types
26
- @types unless @types.nil?
27
- types = []
28
- @response['types'].each do |n|
29
- types << KenticoCloud::Delivery::ContentType.new(n)
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
- def initialize(response)
35
- @response = response
36
- super 200,
37
- "Success, #{types.length} types returned",
38
- JSON.generate(@response)
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 KenticoCloud
5
- module Delivery
6
- module Responses
7
- # The response of a successful query for a content type.
8
- # See https://github.com/Kentico/delivery-sdk-ruby#retrieving-content-types
9
- class DeliveryTypeResponse < ResponseBase
10
- # A KenticoCloud::Delivery::ContentType object from a
11
- # KenticoCloud::Delivery::DeliveryClient.type call.
12
- #
13
- # * *Returns*:
14
- # - KenticoCloud::Delivery::ContentType
15
- def type
16
- @type unless @type.nil?
17
- @type = KenticoCloud::Delivery::ContentType.new(@response)
18
- end
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
- def initialize(response)
21
- @response = response
22
- super 200,
23
- "Success, type '#{type.system.codename}' returned",
24
- JSON.generate(@response)
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 KenticoCloud
2
- module Delivery
3
- module Responses
4
- # Base class for all responses from a
5
- # KenticoCloud::Delivery::DeliveryQuery.execute call.
6
- class ResponseBase
7
- attr_accessor :http_code,
8
- :message,
9
- :json
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
- # Constructor.
12
- #
13
- # * *Args*:
14
- # - *http_code* (+integer+) The status code returned by the REST request
15
- # - *message* (+string+) An informative message about the response, visible when calling +to_s+
16
- # - *json* (+string+) _optional_ The complete, unmodified JSON response from the server
17
- def initialize(http_code, message, json = '')
18
- self.http_code = http_code
19
- self.message = message
20
- self.json = json
21
- end
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
- # Provides an informative message about the success of the request
24
- # by combining the status code and message.
25
- #
26
- # * *Returns*:
27
- # - +string+
28
- def to_s
29
- "Response is status code #{http_code} with message:\n#{message}"
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 KenticoCloud
6
- module Delivery
7
- module Tests
8
- class FakeResponder
9
- PROJECT_ID = ENV['PROJECT_ID']
10
- IS_SECURE = ENV['TEST_SECURE_API_ENABLED']
11
- SECURE_KEY = ENV['SECURE_KEY']
12
- PREVIEW_KEY = ENV['PREVIEW_KEY']
13
- BASE_URL = "https://deliver.kenticocloud.com/#{PROJECT_ID}".freeze
14
- PREVIEW_URL = "https://preview-deliver.kenticocloud.com/#{PROJECT_ID}".freeze
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
- class << self
17
- def get_response(query, url, headers)
18
- @query = query
19
- if IS_SECURE && !(
20
- headers['Authorization'] == "Bearer #{SECURE_KEY}" ||
21
- headers['Authorization'] == "Bearer #{PREVIEW_KEY}"
22
- )
23
- return respond_401
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
- qs = url.contains('?') ? url.split('?')[1] : nil
34
- return respond_filtering qs unless qs.nil? # e.g. /items/about_us?skip=0&limit=5
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
- respond_generic url # Didn't match other clauses, so response should be located in corresponding filepath
37
- end
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
- def respond_generic(url)
40
- path = Pathname.new(File.dirname(__FILE__) + "/generic#{url}.json")
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
- def respond_filtering(query)
45
- path =
46
- case CGI.unescape query
47
- when 'skip=0&limit=5'
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
- def respond_401
58
- path = Pathname.new(File.dirname(__FILE__) + '/401.json')
59
- KenticoCloud::Delivery::Responses::ResponseBase.new 401, '', path.read if path.exist?
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