delivery-sdk-ruby 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -21
- data/README.md +480 -461
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/delivery-sdk-ruby.rb +17 -17
- data/lib/delivery/builders/image_transformation_builder.rb +143 -141
- data/lib/delivery/builders/url_builder.rb +75 -73
- data/lib/delivery/client/delivery_client.rb +87 -85
- data/lib/delivery/client/delivery_query.rb +190 -188
- data/lib/delivery/models/content_item.rb +98 -96
- data/lib/delivery/models/content_type.rb +28 -26
- data/lib/delivery/models/pagination.rb +15 -13
- data/lib/delivery/models/taxonomy_group.rb +26 -24
- data/lib/delivery/query_parameters/filters.rb +89 -87
- data/lib/delivery/query_parameters/parameter_base.rb +32 -30
- data/lib/delivery/query_parameters/query_string.rb +51 -49
- data/lib/delivery/resolvers/content_link_resolver.rb +64 -62
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +52 -50
- data/lib/delivery/resolvers/linked_item_resolver.rb +30 -28
- data/lib/delivery/responses/delivery_element_response.rb +25 -23
- data/lib/delivery/responses/delivery_item_listing_response.rb +41 -39
- data/lib/delivery/responses/delivery_item_response.rb +31 -29
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +34 -32
- data/lib/delivery/responses/delivery_taxonomy_response.rb +24 -22
- data/lib/delivery/responses/delivery_type_listing_response.rb +33 -31
- data/lib/delivery/responses/delivery_type_response.rb +23 -21
- data/lib/delivery/responses/response_base.rb +22 -20
- data/lib/delivery/version.rb +5 -3
- metadata +13 -14
@@ -1,96 +1,98 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
JSON.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
JSON.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
source
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
JSON.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
JSON.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
JSON.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
JSON.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# specified
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# the specified
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# specified
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# the specified
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|