delivery-sdk-ruby 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +21 -21
  3. data/README.md +480 -461
  4. data/bin/console +14 -14
  5. data/bin/setup +8 -8
  6. data/lib/delivery-sdk-ruby.rb +17 -17
  7. data/lib/delivery/builders/image_transformation_builder.rb +143 -141
  8. data/lib/delivery/builders/url_builder.rb +75 -73
  9. data/lib/delivery/client/delivery_client.rb +87 -85
  10. data/lib/delivery/client/delivery_query.rb +190 -188
  11. data/lib/delivery/models/content_item.rb +98 -96
  12. data/lib/delivery/models/content_type.rb +28 -26
  13. data/lib/delivery/models/pagination.rb +15 -13
  14. data/lib/delivery/models/taxonomy_group.rb +26 -24
  15. data/lib/delivery/query_parameters/filters.rb +89 -87
  16. data/lib/delivery/query_parameters/parameter_base.rb +32 -30
  17. data/lib/delivery/query_parameters/query_string.rb +51 -49
  18. data/lib/delivery/resolvers/content_link_resolver.rb +64 -62
  19. data/lib/delivery/resolvers/inline_content_item_resolver.rb +52 -50
  20. data/lib/delivery/resolvers/linked_item_resolver.rb +30 -28
  21. data/lib/delivery/responses/delivery_element_response.rb +25 -23
  22. data/lib/delivery/responses/delivery_item_listing_response.rb +41 -39
  23. data/lib/delivery/responses/delivery_item_response.rb +31 -29
  24. data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +34 -32
  25. data/lib/delivery/responses/delivery_taxonomy_response.rb +24 -22
  26. data/lib/delivery/responses/delivery_type_listing_response.rb +33 -31
  27. data/lib/delivery/responses/delivery_type_response.rb +23 -21
  28. data/lib/delivery/responses/response_base.rb +22 -20
  29. data/lib/delivery/version.rb +5 -3
  30. metadata +13 -14
@@ -1,96 +1,98 @@
1
- require 'ostruct'
2
- require 'nokogiri'
3
-
4
- module Delivery
5
- # JSON data of a content item parsed as OpenStruct objects for dynamic use
6
- class ContentItem
7
- attr_accessor :content_link_url_resolver,
8
- :inline_content_item_resolver
9
-
10
- def elements
11
- @elements unless @elements.nil?
12
- @elements = JSON.parse(
13
- JSON.generate(@source['elements']),
14
- object_class: OpenStruct
15
- )
16
- end
17
-
18
- def system
19
- @system unless @system.nil?
20
- @system = JSON.parse(
21
- JSON.generate(@source['system']),
22
- object_class: OpenStruct
23
- )
24
- end
25
-
26
- def initialize(source, content_link_url_resolver, inline_content_item_resolver, linked_items_resolver)
27
- @source =
28
- if source['item'].nil?
29
- source
30
- else
31
- source['item']
32
- end
33
- @linked_items_resolver = linked_items_resolver
34
- self.content_link_url_resolver = content_link_url_resolver
35
- self.inline_content_item_resolver = inline_content_item_resolver
36
- end
37
-
38
- def get_string(code_name)
39
- element = get_element code_name
40
- content = element['value']
41
-
42
- if element['type'] == 'rich_text'
43
- content = content_link_url_resolver.resolve content, element['links'] if should_resolve_links element
44
- inline_items = get_inline_items code_name
45
- content = inline_content_item_resolver.resolve content, inline_items if should_resolve_inline_content element
46
- end
47
- content.to_s
48
- end
49
-
50
- # Returns an array of assets inserted into the specified element
51
- def get_assets(code_name)
52
- element = get_element code_name
53
- element['value'].map { |n| OpenStruct.new(n) }
54
- end
55
-
56
- # Returns an array of ContentItems by comparing code names stored in the
57
- # element with items from request's modular_content
58
- def get_links(code_name)
59
- element = get_element code_name
60
- get_linked_items element['value']
61
- end
62
-
63
- # Returns an array of ContentItems by comparing code names stored in the
64
- # modular_content object with items from request's modular_content
65
- def get_inline_items(code_name)
66
- element = get_element code_name
67
- get_linked_items element['modular_content']
68
- end
69
-
70
- private
71
-
72
- def should_resolve_links(element)
73
- !element['links'].nil? && !content_link_url_resolver.nil?
74
- end
75
-
76
- def should_resolve_inline_content(element)
77
- !element['modular_content'].nil? && !inline_content_item_resolver.nil?
78
- end
79
-
80
- def get_element(code_name)
81
- raise ArgumentError, "Argument 'code_name' cannot be null" if code_name.nil?
82
- raise ArgumentError, "Argument 'code_name' is not a string" unless code_name.is_a? String
83
-
84
- @source['elements'][code_name]
85
- end
86
-
87
- def get_linked_items(codenames)
88
- return [] unless codenames.class == Array
89
-
90
- codenames.each_with_object([]) do |codename, items|
91
- item = @linked_items_resolver.resolve codename
92
- items << item if item
93
- end
94
- end
95
- end
96
- end
1
+ require 'ostruct'
2
+ require 'nokogiri'
3
+
4
+ module KenticoCloud
5
+ module Delivery
6
+ # JSON data of a content item parsed as OpenStruct objects for dynamic use
7
+ class ContentItem
8
+ attr_accessor :content_link_url_resolver,
9
+ :inline_content_item_resolver
10
+
11
+ def elements
12
+ @elements unless @elements.nil?
13
+ @elements = JSON.parse(
14
+ JSON.generate(@source['elements']),
15
+ object_class: OpenStruct
16
+ )
17
+ end
18
+
19
+ def system
20
+ @system unless @system.nil?
21
+ @system = JSON.parse(
22
+ JSON.generate(@source['system']),
23
+ object_class: OpenStruct
24
+ )
25
+ end
26
+
27
+ def initialize(source, content_link_url_resolver, inline_content_item_resolver, linked_items_resolver)
28
+ @source =
29
+ if source['item'].nil?
30
+ source
31
+ else
32
+ source['item']
33
+ end
34
+ @linked_items_resolver = linked_items_resolver
35
+ self.content_link_url_resolver = content_link_url_resolver
36
+ self.inline_content_item_resolver = inline_content_item_resolver
37
+ end
38
+
39
+ def get_string(code_name)
40
+ element = get_element code_name
41
+ content = element['value']
42
+
43
+ if element['type'] == 'rich_text'
44
+ content = content_link_url_resolver.resolve content, element['links'] if should_resolve_links element
45
+ inline_items = get_inline_items code_name
46
+ content = inline_content_item_resolver.resolve content, inline_items if should_resolve_inline_content element
47
+ end
48
+ content.to_s
49
+ end
50
+
51
+ # Returns an array of assets inserted into the specified element
52
+ def get_assets(code_name)
53
+ element = get_element code_name
54
+ element['value'].map { |n| OpenStruct.new(n) }
55
+ end
56
+
57
+ # Returns an array of ContentItems by comparing code names stored in the
58
+ # element with items from request's modular_content
59
+ def get_links(code_name)
60
+ element = get_element code_name
61
+ get_linked_items element['value']
62
+ end
63
+
64
+ # Returns an array of ContentItems by comparing code names stored in the
65
+ # modular_content object with items from request's modular_content
66
+ def get_inline_items(code_name)
67
+ element = get_element code_name
68
+ get_linked_items element['modular_content']
69
+ end
70
+
71
+ private
72
+
73
+ def should_resolve_links(element)
74
+ !element['links'].nil? && !content_link_url_resolver.nil?
75
+ end
76
+
77
+ def should_resolve_inline_content(element)
78
+ !element['modular_content'].nil? && !inline_content_item_resolver.nil?
79
+ end
80
+
81
+ def get_element(code_name)
82
+ raise ArgumentError, "Argument 'code_name' cannot be null" if code_name.nil?
83
+ raise ArgumentError, "Argument 'code_name' is not a string" unless code_name.is_a? String
84
+
85
+ @source['elements'][code_name]
86
+ end
87
+
88
+ def get_linked_items(codenames)
89
+ return [] unless codenames.class == Array
90
+
91
+ codenames.each_with_object([]) do |codename, items|
92
+ item = @linked_items_resolver.resolve codename
93
+ items << item if item
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,26 +1,28 @@
1
- require 'ostruct'
2
-
3
- module Delivery
4
- # JSON data of a content type parsed as OpenStruct objects for dynamic use
5
- class ContentType
6
- def elements
7
- @elements unless @elements.nil?
8
- @elements = JSON.parse(
9
- JSON.generate(@source['elements']),
10
- object_class: OpenStruct
11
- )
12
- end
13
-
14
- def system
15
- @system unless @system.nil?
16
- @system = JSON.parse(
17
- JSON.generate(@source['system']),
18
- object_class: OpenStruct
19
- )
20
- end
21
-
22
- def initialize(source)
23
- @source = source
24
- end
25
- end
26
- end
1
+ require 'ostruct'
2
+
3
+ module KenticoCloud
4
+ module Delivery
5
+ # JSON data of a content type parsed as OpenStruct objects for dynamic use
6
+ class ContentType
7
+ def elements
8
+ @elements unless @elements.nil?
9
+ @elements = JSON.parse(
10
+ JSON.generate(@source['elements']),
11
+ object_class: OpenStruct
12
+ )
13
+ end
14
+
15
+ def system
16
+ @system unless @system.nil?
17
+ @system = JSON.parse(
18
+ JSON.generate(@source['system']),
19
+ object_class: OpenStruct
20
+ )
21
+ end
22
+
23
+ def initialize(source)
24
+ @source = source
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,13 +1,15 @@
1
- module Delivery
2
- # Holds pagination data from a DeliveryItemListingResponse
3
- class Pagination
4
- attr_accessor :skip, :limit, :count, :next_page
5
-
6
- def initialize(json)
7
- self.skip = json['skip']
8
- self.limit = json['limit']
9
- self.count = json['count']
10
- self.next_page = json['next_page']
11
- end
12
- end
13
- end
1
+ module KenticoCloud
2
+ module Delivery
3
+ # Holds pagination data from a DeliveryItemListingResponse
4
+ class Pagination
5
+ attr_accessor :skip, :limit, :count, :next_page
6
+
7
+ def initialize(json)
8
+ self.skip = json['skip']
9
+ self.limit = json['limit']
10
+ self.count = json['count']
11
+ self.next_page = json['next_page']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,24 +1,26 @@
1
- module Delivery
2
- # JSON data of a taxonomy group parsed as OpenStruct objects for dynamic use
3
- class TaxonomyGroup
4
- def terms
5
- @terms unless @terms.nil?
6
- @terms = JSON.parse(
7
- JSON.generate(@source['terms']),
8
- object_class: OpenStruct
9
- )
10
- end
11
-
12
- def system
13
- @system unless @system.nil?
14
- @system = JSON.parse(
15
- JSON.generate(@source['system']),
16
- object_class: OpenStruct
17
- )
18
- end
19
-
20
- def initialize(source)
21
- @source = source
22
- end
23
- end
24
- end
1
+ module KenticoCloud
2
+ module Delivery
3
+ # JSON data of a taxonomy group parsed as OpenStruct objects for dynamic use
4
+ class TaxonomyGroup
5
+ def terms
6
+ @terms unless @terms.nil?
7
+ @terms = JSON.parse(
8
+ JSON.generate(@source['terms']),
9
+ object_class: OpenStruct
10
+ )
11
+ end
12
+
13
+ def system
14
+ @system unless @system.nil?
15
+ @system = JSON.parse(
16
+ JSON.generate(@source['system']),
17
+ object_class: OpenStruct
18
+ )
19
+ end
20
+
21
+ def initialize(source)
22
+ @source = source
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,87 +1,89 @@
1
- require 'delivery/query_parameters/parameter_base'
2
-
3
- module Delivery
4
- module QueryParameters
5
- # Provides the base class for filter implementations.
6
- class Filter < ParameterBase
7
- def initialize(key, operator, values)
8
- super(key, operator, values)
9
- end
10
- end
11
- end
12
- end
13
-
14
- # Extend String class to allow semantic typing of filters
15
- class String
16
- # Represents a filter that matches a content item if the specified content
17
- # element or system attribute has a value that contains all the specified
18
- # values. This filter is applicable to array values only, such as sitemap
19
- # location or value of Linked Items, Taxonomy and Multiple choice content elements.
20
- def all(*args)
21
- Delivery::QueryParameters::Filter.new(self, '[all]', *args)
22
- end
23
-
24
- # Represents a filter that matches a content item if the specified content
25
- # element or system attribute has a value that contains any the specified
26
- # values. This filter is applicable to array values only, such as sitemap
27
- # location or value of Linked Items, Taxonomy and Multiple choice content elements.
28
- def any(*args)
29
- Delivery::QueryParameters::Filter.new(self, '[any]', *args)
30
- end
31
-
32
- # Represents a filter that matches a content item if the specified content element
33
- # or system attribute has a value that contains the specified value.
34
- # This filter is applicable to array values only, such as sitemap location or value
35
- # of Linked Items, Taxonomy and Multiple choice content elements.
36
- def contains(*args)
37
- Delivery::QueryParameters::Filter.new(self, '[contains]', *args)
38
- end
39
-
40
- # Represents a filter that matches a content item if the specified
41
- # content element or system attribute has the specified value.
42
- def eq(*args)
43
- Delivery::QueryParameters::Filter.new(self, '', *args)
44
- end
45
-
46
- # Represents a filter that matches a content item if the specified content
47
- # element or system attribute has a value that is greater than the
48
- # specified value.
49
- def gt(*args)
50
- Delivery::QueryParameters::Filter.new(self, '[gt]', *args)
51
- end
52
-
53
- # Represents a filter that matches a content item if the specified content
54
- # element or system attribute has a value that is greater than or equal to
55
- # the specified value.
56
- def gt_or_eq(*args)
57
- Delivery::QueryParameters::Filter.new(self, '[gte]', *args)
58
- end
59
-
60
- # Represents a filter that matches a content item if the specified
61
- # content element or system attribute has a value that matches a
62
- # value in the specified list.
63
- def in(*args)
64
- Delivery::QueryParameters::Filter.new(self, '[in]', *args)
65
- end
66
-
67
- # Represents a filter that matches a content item if the specified content
68
- # element or system attribute has a value that is less than the
69
- # specified value.
70
- def lt(*args)
71
- Delivery::QueryParameters::Filter.new(self, '[lt]', *args)
72
- end
73
-
74
- # Represents a filter that matches a content item if the specified content
75
- # element or system attribute has a value that is less than or equal to
76
- # the specified value.
77
- def lt_or_eq(*args)
78
- Delivery::QueryParameters::Filter.new(self, '[lte]', *args)
79
- end
80
-
81
- # Represents a filter that matches a content item if the specified
82
- # content element or system attribute has a value that falls within
83
- # the specified range of values (both inclusive).
84
- def range(*args)
85
- Delivery::QueryParameters::Filter.new(self, '[range]', *args)
86
- end
87
- end
1
+ require 'delivery/query_parameters/parameter_base'
2
+
3
+ module KenticoCloud
4
+ module Delivery
5
+ module QueryParameters
6
+ # Provides the base class for filter implementations.
7
+ class Filter < ParameterBase
8
+ def initialize(key, operator, values)
9
+ super(key, operator, values)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ # Extend String class to allow semantic typing of filters
17
+ class String
18
+ # Represents a filter that matches a content item if the specified content
19
+ # element or system attribute has a value that contains all the specified
20
+ # values. This filter is applicable to array values only, such as sitemap
21
+ # location or value of Linked Items, Taxonomy and Multiple choice content elements.
22
+ def all(*args)
23
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[all]', *args)
24
+ end
25
+
26
+ # Represents a filter that matches a content item if the specified content
27
+ # element or system attribute has a value that contains any the specified
28
+ # values. This filter is applicable to array values only, such as sitemap
29
+ # location or value of Linked Items, Taxonomy and Multiple choice content elements.
30
+ def any(*args)
31
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[any]', *args)
32
+ end
33
+
34
+ # Represents a filter that matches a content item if the specified content element
35
+ # or system attribute has a value that contains the specified value.
36
+ # This filter is applicable to array values only, such as sitemap location or value
37
+ # of Linked Items, Taxonomy and Multiple choice content elements.
38
+ def contains(*args)
39
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[contains]', *args)
40
+ end
41
+
42
+ # Represents a filter that matches a content item if the specified
43
+ # content element or system attribute has the specified value.
44
+ def eq(*args)
45
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '', *args)
46
+ end
47
+
48
+ # Represents a filter that matches a content item if the specified content
49
+ # element or system attribute has a value that is greater than the
50
+ # specified value.
51
+ def gt(*args)
52
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[gt]', *args)
53
+ end
54
+
55
+ # Represents a filter that matches a content item if the specified content
56
+ # element or system attribute has a value that is greater than or equal to
57
+ # the specified value.
58
+ def gt_or_eq(*args)
59
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[gte]', *args)
60
+ end
61
+
62
+ # Represents a filter that matches a content item if the specified
63
+ # content element or system attribute has a value that matches a
64
+ # value in the specified list.
65
+ def in(*args)
66
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[in]', *args)
67
+ end
68
+
69
+ # Represents a filter that matches a content item if the specified content
70
+ # element or system attribute has a value that is less than the
71
+ # specified value.
72
+ def lt(*args)
73
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[lt]', *args)
74
+ end
75
+
76
+ # Represents a filter that matches a content item if the specified content
77
+ # element or system attribute has a value that is less than or equal to
78
+ # the specified value.
79
+ def lt_or_eq(*args)
80
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[lte]', *args)
81
+ end
82
+
83
+ # Represents a filter that matches a content item if the specified
84
+ # content element or system attribute has a value that falls within
85
+ # the specified range of values (both inclusive).
86
+ def range(*args)
87
+ KenticoCloud::Delivery::QueryParameters::Filter.new(self, '[range]', *args)
88
+ end
89
+ end