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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +21 -21
  3. data/README.md +575 -576
  4. data/bin/console +14 -14
  5. data/bin/setup +8 -8
  6. data/lib/delivery/builders/image_transformation_builder.rb +271 -271
  7. data/lib/delivery/builders/url_builder.rb +120 -120
  8. data/lib/delivery/client/delivery_client.rb +176 -176
  9. data/lib/delivery/client/delivery_query.rb +302 -302
  10. data/lib/delivery/client/request_manager.rb +125 -125
  11. data/lib/delivery/models/content_item.rb +153 -153
  12. data/lib/delivery/models/content_type.rb +41 -41
  13. data/lib/delivery/models/pagination.rb +22 -22
  14. data/lib/delivery/models/taxonomy_group.rb +39 -39
  15. data/lib/delivery/query_parameters/filters.rb +158 -158
  16. data/lib/delivery/query_parameters/parameter_base.rb +46 -46
  17. data/lib/delivery/query_parameters/query_string.rb +78 -78
  18. data/lib/delivery/resolvers/content_link_resolver.rb +102 -102
  19. data/lib/delivery/resolvers/inline_content_item_resolver.rb +75 -75
  20. data/lib/delivery/resolvers/linked_item_resolver.rb +37 -37
  21. data/lib/delivery/responses/delivery_element_response.rb +34 -34
  22. data/lib/delivery/responses/delivery_item_listing_response.rb +54 -54
  23. data/lib/delivery/responses/delivery_item_response.rb +40 -40
  24. data/lib/delivery/responses/delivery_items_feed_response.rb +58 -58
  25. data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +47 -47
  26. data/lib/delivery/responses/delivery_taxonomy_response.rb +33 -33
  27. data/lib/delivery/responses/delivery_type_listing_response.rb +46 -46
  28. data/lib/delivery/responses/delivery_type_response.rb +32 -32
  29. data/lib/delivery/responses/response_base.rb +39 -39
  30. data/lib/delivery/tests/401.json +5 -5
  31. data/lib/delivery/tests/429.json +4 -4
  32. data/lib/delivery/tests/fake_responder.rb +110 -110
  33. data/lib/delivery/tests/filtering/items_gt.json +565 -565
  34. data/lib/delivery/tests/filtering/items_with_count.json +4985 -4985
  35. data/lib/delivery/tests/filtering/multiple.json +282 -282
  36. data/lib/delivery/tests/filtering/pagination_about_us.json +646 -646
  37. data/lib/delivery/tests/generic/items.json +4984 -4984
  38. data/lib/delivery/tests/generic/items/about_us.json +227 -227
  39. data/lib/delivery/tests/generic/items/aeropress_filters.json +138 -138
  40. data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +168 -168
  41. data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +620 -620
  42. data/lib/delivery/tests/generic/taxonomies.json +126 -126
  43. data/lib/delivery/tests/generic/types.json +780 -780
  44. data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +5 -5
  45. data/lib/delivery/tests/items_feed/articles_feed_1.json +39 -39
  46. data/lib/delivery/tests/items_feed/articles_feed_2.json +78 -78
  47. data/lib/delivery/tests/items_feed/articles_feed_3.json +104 -104
  48. data/lib/delivery/version.rb +7 -7
  49. data/lib/kontent-delivery-sdk-ruby.rb +20 -20
  50. metadata +30 -11
@@ -1,75 +1,75 @@
1
- require 'nokogiri'
2
-
3
- module Kentico
4
- module Kontent
5
- module Delivery
6
- module Resolvers
7
- # Locates <object data-type="item"> tags in content and calls a user-defined
8
- # method to supply the output for the content item.
9
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-inline-content
10
- class InlineContentItemResolver
11
- def initialize(callback = nil)
12
- @callback = callback
13
- end
14
-
15
- # Resolves all inline content items in the content.
16
- #
17
- # * *Args*:
18
- # - *content* (+string+) The string value stored in the element
19
- # - *inline_items* (+Array+) ContentItems referenced by the content from the 'modular_content' JSON node
20
- #
21
- # * *Returns*:
22
- # - +string+ The original content passed, with all <object data-type="item"> replaced with custom output
23
- def resolve(content, inline_items)
24
- doc = Nokogiri::HTML.parse(content).xpath('//body')
25
- tags = doc.xpath('//object[@type="application/kenticocloud"][@data-type="item"]')
26
- tags.each do |tag|
27
- output = resolve_tag tag, inline_items
28
- el = doc.at_xpath(
29
- '//object[@type="application/kenticocloud"][@data-type="item"][@data-codename=$value]',
30
- nil,
31
- value: tag['data-codename']
32
- )
33
- el.swap(output) unless output.nil?
34
- end
35
- doc.inner_html
36
- end
37
-
38
- private
39
-
40
- # Accepts a tag found in the content and tries to locate matching
41
- # ContentItem from JSON response.
42
- #
43
- # * *Args*:
44
- # - *tag* (+string+) A <object data-type="item"> tag found in the content
45
- # - *inline_items* (+Array+) ContentItems referenced by the content from the 'modular_content' JSON node
46
- #
47
- # * *Returns*:
48
- # - +string+ The custom output generated by the +provide_output+ method
49
- def resolve_tag(tag, inline_items)
50
- matches = inline_items.select { |item| item.system.codename == tag['data-codename'].to_s }
51
- provide_output matches
52
- end
53
-
54
- # Generates custom output for a content item using the +resolve_item+
55
- # method.
56
- #
57
- # * *Args*:
58
- # - *matches* (+Array+) The ContentItems from the 'modular_content' JSON node which match the code name of a particular <object data-type="item"> tag
59
- #
60
- # * *Returns*:
61
- # - +string+ The custom output generated by the +resolve_item+ method
62
- def provide_output(matches)
63
- if !matches.empty?
64
- if @callback.nil?
65
- resolve_item matches[0]
66
- else
67
- @callback.call matches[0]
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
1
+ require 'nokogiri'
2
+
3
+ module Kentico
4
+ module Kontent
5
+ module Delivery
6
+ module Resolvers
7
+ # Locates <object data-type="item"> tags in content and calls a user-defined
8
+ # method to supply the output for the content item.
9
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#resolving-inline-content
10
+ class InlineContentItemResolver
11
+ def initialize(callback = nil)
12
+ @callback = callback
13
+ end
14
+
15
+ # Resolves all inline content items in the content.
16
+ #
17
+ # * *Args*:
18
+ # - *content* (+string+) The string value stored in the element
19
+ # - *inline_items* (+Array+) ContentItems referenced by the content from the 'modular_content' JSON node
20
+ #
21
+ # * *Returns*:
22
+ # - +string+ The original content passed, with all <object data-type="item"> replaced with custom output
23
+ def resolve(content, inline_items)
24
+ doc = Nokogiri::HTML.parse(content).xpath('//body')
25
+ tags = doc.xpath('//object[@type="application/kenticocloud"][@data-type="item"]')
26
+ tags.each do |tag|
27
+ output = resolve_tag tag, inline_items
28
+ el = doc.at_xpath(
29
+ '//object[@type="application/kenticocloud"][@data-type="item"][@data-codename=$value]',
30
+ nil,
31
+ value: tag['data-codename']
32
+ )
33
+ el.swap(output) unless output.nil?
34
+ end
35
+ doc.inner_html
36
+ end
37
+
38
+ private
39
+
40
+ # Accepts a tag found in the content and tries to locate matching
41
+ # ContentItem from JSON response.
42
+ #
43
+ # * *Args*:
44
+ # - *tag* (+string+) A <object data-type="item"> tag found in the content
45
+ # - *inline_items* (+Array+) ContentItems referenced by the content from the 'modular_content' JSON node
46
+ #
47
+ # * *Returns*:
48
+ # - +string+ The custom output generated by the +provide_output+ method
49
+ def resolve_tag(tag, inline_items)
50
+ matches = inline_items.select { |item| item.system.codename == tag['data-codename'].to_s }
51
+ provide_output matches
52
+ end
53
+
54
+ # Generates custom output for a content item using the +resolve_item+
55
+ # method.
56
+ #
57
+ # * *Args*:
58
+ # - *matches* (+Array+) The ContentItems from the 'modular_content' JSON node which match the code name of a particular <object data-type="item"> tag
59
+ #
60
+ # * *Returns*:
61
+ # - +string+ The custom output generated by the +resolve_item+ method
62
+ def provide_output(matches)
63
+ if !matches.empty?
64
+ if @callback.nil?
65
+ resolve_item matches[0]
66
+ else
67
+ @callback.call matches[0]
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,37 +1,37 @@
1
- module Kentico
2
- module Kontent
3
- module Delivery
4
- module Resolvers
5
- # Resolves a content item by its codename. It contains the modular content
6
- # of item/items response.
7
- class LinkedItemResolver
8
- def initialize(modular_content, content_link_url_resolver, inline_content_item_resolver)
9
- @modular_content = modular_content
10
- @content_link_url_resolver = content_link_url_resolver
11
- @inline_content_item_resolver = inline_content_item_resolver
12
- @resolved_items = {}
13
- end
14
-
15
- # Resolves a content item. If the link for a codename was resolved
16
- # before, it returns the same instance of ContentItem.
17
- #
18
- # * *Args*:
19
- # - *codename* (+string+) Codename of the content item
20
- #
21
- # * *Return*:
22
- # - Kentico::Kontent::Delivery::ContentItem
23
- def resolve(codename)
24
- @resolved_items[codename] ||= resolve_item(codename)
25
- end
26
-
27
- private
28
-
29
- def resolve_item(codename)
30
- item = @modular_content.values.find { |i| i['system']['codename'] == codename }
31
- ContentItem.new JSON.parse(JSON.generate(item)), @content_link_url_resolver, @inline_content_item_resolver, self
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
1
+ module Kentico
2
+ module Kontent
3
+ module Delivery
4
+ module Resolvers
5
+ # Resolves a content item by its codename. It contains the modular content
6
+ # of item/items response.
7
+ class LinkedItemResolver
8
+ def initialize(modular_content, content_link_url_resolver, inline_content_item_resolver)
9
+ @modular_content = modular_content
10
+ @content_link_url_resolver = content_link_url_resolver
11
+ @inline_content_item_resolver = inline_content_item_resolver
12
+ @resolved_items = {}
13
+ end
14
+
15
+ # Resolves a content item. If the link for a codename was resolved
16
+ # before, it returns the same instance of ContentItem.
17
+ #
18
+ # * *Args*:
19
+ # - *codename* (+string+) Codename of the content item
20
+ #
21
+ # * *Return*:
22
+ # - Kentico::Kontent::Delivery::ContentItem
23
+ def resolve(codename)
24
+ @resolved_items[codename] ||= resolve_item(codename)
25
+ end
26
+
27
+ private
28
+
29
+ def resolve_item(codename)
30
+ item = @modular_content.values.find { |i| i['system']['codename'] == codename }
31
+ ContentItem.new JSON.parse(JSON.generate(item)), @content_link_url_resolver, @inline_content_item_resolver, self
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,34 +1,34 @@
1
- require 'delivery/responses/response_base'
2
-
3
- module Kentico
4
- module Kontent
5
- module Delivery
6
- module Responses
7
- # The response of a successful query of a content type's element
8
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#retrieving-content-type-elements
9
- class DeliveryElementResponse < ResponseBase
10
- # An element's definition from a
11
- # Kentico::Kontent::Delivery::DeliveryClient.element call
12
- #
13
- # * *Returns*:
14
- # - +OpenStruct+ The element of a content item
15
- def element
16
- @element unless @element.nil?
17
- @element = JSON.parse(
18
- JSON.generate(@response),
19
- object_class: OpenStruct
20
- )
21
- end
22
-
23
- def initialize(headers, body)
24
- @response = JSON.parse(body)
25
- super 200,
26
- "Success, '#{element.codename}' returned",
27
- headers,
28
- JSON.generate(@response)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
1
+ require 'delivery/responses/response_base'
2
+
3
+ module Kentico
4
+ module Kontent
5
+ module Delivery
6
+ module Responses
7
+ # The response of a successful query of a content type's element
8
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#retrieving-content-type-elements
9
+ class DeliveryElementResponse < ResponseBase
10
+ # An element's definition from a
11
+ # Kentico::Kontent::Delivery::DeliveryClient.element call
12
+ #
13
+ # * *Returns*:
14
+ # - +OpenStruct+ The element of a content item
15
+ def element
16
+ @element unless @element.nil?
17
+ @element = JSON.parse(
18
+ JSON.generate(@response),
19
+ object_class: OpenStruct
20
+ )
21
+ end
22
+
23
+ def initialize(headers, body)
24
+ @response = JSON.parse(body)
25
+ super 200,
26
+ "Success, '#{element.codename}' returned",
27
+ headers,
28
+ JSON.generate(@response)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,54 +1,54 @@
1
- require 'delivery/models/content_item'
2
- require 'delivery/models/pagination'
3
- require 'delivery/responses/response_base'
4
-
5
- module Kentico
6
- module Kontent
7
- module Delivery
8
- module Responses
9
- # The response of a successful query for content items.
10
- # See https://github.com/Kentico/kontent-delivery-sdk-ruby#listing-items
11
- class DeliveryItemListingResponse < 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
20
-
21
- # A collection of Kentico::Kontent::Delivery::ContentItem objects from
22
- # a Kentico::Kontent::Delivery::DeliveryClient.items call.
23
- #
24
- # * *Returns*:
25
- # - +Array+ One or more Kentico::Kontent::Delivery::ContentItem objects
26
- def items
27
- @items unless @items.nil?
28
- linked_items_resolver = Kentico::Kontent::Delivery::Resolvers::LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
29
- items = []
30
- @response['items'].each do |n|
31
- items << Kentico::Kontent::Delivery::ContentItem.new(
32
- n,
33
- @content_link_url_resolver,
34
- @inline_content_item_resolver,
35
- linked_items_resolver
36
- )
37
- end
38
- @items = items
39
- end
40
-
41
- def initialize(headers, body, query)
42
- @response = JSON.parse(body)
43
- @content_link_url_resolver = query.content_link_url_resolver
44
- @inline_content_item_resolver = query.inline_content_item_resolver
45
- super 200,
46
- "Success, #{items.length} items returned",
47
- headers,
48
- JSON.generate(@response)
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
1
+ require 'delivery/models/content_item'
2
+ require 'delivery/models/pagination'
3
+ require 'delivery/responses/response_base'
4
+
5
+ module Kentico
6
+ module Kontent
7
+ module Delivery
8
+ module Responses
9
+ # The response of a successful query for content items.
10
+ # See https://github.com/Kentico/kontent-delivery-sdk-ruby#listing-items
11
+ class DeliveryItemListingResponse < 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
20
+
21
+ # A collection of Kentico::Kontent::Delivery::ContentItem objects from
22
+ # a Kentico::Kontent::Delivery::DeliveryClient.items call.
23
+ #
24
+ # * *Returns*:
25
+ # - +Array+ One or more Kentico::Kontent::Delivery::ContentItem objects
26
+ def items
27
+ @items unless @items.nil?
28
+ linked_items_resolver = Kentico::Kontent::Delivery::Resolvers::LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
29
+ items = []
30
+ @response['items'].each do |n|
31
+ items << Kentico::Kontent::Delivery::ContentItem.new(
32
+ n,
33
+ @content_link_url_resolver,
34
+ @inline_content_item_resolver,
35
+ linked_items_resolver
36
+ )
37
+ end
38
+ @items = items
39
+ end
40
+
41
+ def initialize(headers, body, query)
42
+ @response = JSON.parse(body)
43
+ @content_link_url_resolver = query.content_link_url_resolver
44
+ @inline_content_item_resolver = query.inline_content_item_resolver
45
+ super 200,
46
+ "Success, #{items.length} items returned",
47
+ headers,
48
+ JSON.generate(@response)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,40 +1,40 @@
1
- require 'delivery/models/content_item'
2
- require 'delivery/responses/response_base'
3
-
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
26
-
27
- def initialize(headers, body, query)
28
- @response = JSON.parse(body)
29
- @content_link_url_resolver = query.content_link_url_resolver
30
- @inline_content_item_resolver = query.inline_content_item_resolver
31
- super 200,
32
- "Success, '#{item.system.codename}' returned",
33
- headers,
34
- JSON.generate(@response)
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
1
+ require 'delivery/models/content_item'
2
+ require 'delivery/responses/response_base'
3
+
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
26
+
27
+ def initialize(headers, body, query)
28
+ @response = JSON.parse(body)
29
+ @content_link_url_resolver = query.content_link_url_resolver
30
+ @inline_content_item_resolver = query.inline_content_item_resolver
31
+ super 200,
32
+ "Success, '#{item.system.codename}' returned",
33
+ headers,
34
+ JSON.generate(@response)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end