delivery-sdk-ruby 0.14.6 → 0.14.13

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 +461 -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 +141 -141
  8. data/lib/delivery/builders/url_builder.rb +73 -73
  9. data/lib/delivery/client/delivery_client.rb +85 -85
  10. data/lib/delivery/client/delivery_query.rb +183 -183
  11. data/lib/delivery/models/content_item.rb +96 -96
  12. data/lib/delivery/models/content_type.rb +26 -26
  13. data/lib/delivery/models/pagination.rb +13 -13
  14. data/lib/delivery/models/taxonomy_group.rb +24 -24
  15. data/lib/delivery/query_parameters/filters.rb +87 -87
  16. data/lib/delivery/query_parameters/parameter_base.rb +30 -30
  17. data/lib/delivery/query_parameters/query_string.rb +49 -49
  18. data/lib/delivery/resolvers/content_link_resolver.rb +62 -62
  19. data/lib/delivery/resolvers/inline_content_item_resolver.rb +50 -50
  20. data/lib/delivery/resolvers/linked_item_resolver.rb +27 -27
  21. data/lib/delivery/responses/delivery_element_response.rb +23 -23
  22. data/lib/delivery/responses/delivery_item_listing_response.rb +39 -39
  23. data/lib/delivery/responses/delivery_item_response.rb +29 -29
  24. data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +32 -32
  25. data/lib/delivery/responses/delivery_taxonomy_response.rb +22 -22
  26. data/lib/delivery/responses/delivery_type_listing_response.rb +31 -31
  27. data/lib/delivery/responses/delivery_type_response.rb +21 -21
  28. data/lib/delivery/responses/response_base.rb +20 -20
  29. data/lib/delivery/version.rb +3 -3
  30. metadata +13 -14
@@ -1,96 +1,96 @@
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 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,26 +1,26 @@
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 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,13 +1,13 @@
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 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,24 +1,24 @@
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 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,87 +1,87 @@
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 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