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.
- checksums.yaml +4 -4
- data/README.md +49 -48
- data/lib/delivery/builders/image_transformation_builder.rb +239 -237
- data/lib/delivery/builders/url_builder.rb +95 -93
- data/lib/delivery/client/delivery_client.rb +137 -135
- data/lib/delivery/client/delivery_query.rb +222 -220
- data/lib/delivery/client/request_manager.rb +83 -81
- data/lib/delivery/models/content_item.rb +132 -130
- data/lib/delivery/models/content_type.rb +33 -31
- data/lib/delivery/models/pagination.rb +16 -14
- data/lib/delivery/models/taxonomy_group.rb +33 -31
- data/lib/delivery/query_parameters/filters.rb +36 -34
- data/lib/delivery/query_parameters/parameter_base.rb +37 -35
- data/lib/delivery/query_parameters/query_string.rb +65 -63
- data/lib/delivery/resolvers/content_link_resolver.rb +85 -83
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +61 -59
- data/lib/delivery/resolvers/linked_item_resolver.rb +29 -27
- 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 +30 -28
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +33 -31
- data/lib/delivery/responses/delivery_taxonomy_response.rb +22 -20
- data/lib/delivery/responses/delivery_type_listing_response.rb +33 -31
- data/lib/delivery/responses/delivery_type_response.rb +22 -20
- data/lib/delivery/responses/response_base.rb +29 -27
- data/lib/delivery/tests/fake_responder.rb +50 -48
- data/lib/delivery/tests/filtering/items_gt.json +4 -4
- data/lib/delivery/tests/filtering/multiple.json +2 -2
- data/lib/delivery/tests/filtering/pagination_about_us.json +3 -3
- data/lib/delivery/tests/generic/items.json +25 -25
- data/lib/delivery/tests/generic/items/about_us.json +1 -1
- data/lib/delivery/tests/generic/items/aeropress_filters.json +1 -1
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +1 -1
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +4 -4
- data/lib/delivery/version.rb +5 -3
- data/lib/kontent-delivery-sdk-ruby.rb +19 -0
- metadata +38 -23
@@ -1,38 +1,40 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
JSON.
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
class ContentType
|
7
|
+
# Parses the 'elements' JSON object as a dynamic OpenStruct object.
|
8
|
+
#
|
9
|
+
# * *Returns*:
|
10
|
+
# - +OpenStruct+ The elements of the content type
|
11
|
+
def elements
|
12
|
+
@elements unless @elements.nil?
|
13
|
+
@elements = JSON.parse(
|
14
|
+
JSON.generate(@source['elements']),
|
15
|
+
object_class: OpenStruct
|
16
|
+
)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
# Parses the 'system' JSON object as a dynamic OpenStruct object.
|
20
|
+
#
|
21
|
+
# * *Returns*:
|
22
|
+
# - +OpenStruct+ The system properties of the content type
|
23
|
+
def system
|
24
|
+
@system unless @system.nil?
|
25
|
+
@system = JSON.parse(
|
26
|
+
JSON.generate(@source['system']),
|
27
|
+
object_class: OpenStruct
|
28
|
+
)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
# Constructor.
|
32
|
+
#
|
33
|
+
# * *Args*:
|
34
|
+
# - *source* (+JSON+) The response from a REST request for content types
|
35
|
+
def initialize(source)
|
36
|
+
@source = source
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
# Holds pagination data from listing responses
|
5
|
+
class Pagination
|
6
|
+
attr_accessor :skip, :limit, :count, :next_page
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# Constructor.
|
9
|
+
#
|
10
|
+
# * *Args*:
|
11
|
+
# - *json* (+JSON+) The 'pagination' node of a listing reponse's JSON object
|
12
|
+
def initialize(json)
|
13
|
+
self.skip = json['skip']
|
14
|
+
self.limit = json['limit']
|
15
|
+
self.count = json['count']
|
16
|
+
self.next_page = json['next_page']
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
JSON.
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
class TaxonomyGroup
|
5
|
+
# Parses the 'terms' JSON node as a dynamic OpenStruct object.
|
6
|
+
#
|
7
|
+
# * *Returns*:
|
8
|
+
# - +OpenStruct+ The terms of the taxonomy group as a dynamic object
|
9
|
+
def terms
|
10
|
+
@terms unless @terms.nil?
|
11
|
+
@terms = JSON.parse(
|
12
|
+
JSON.generate(@source['terms']),
|
13
|
+
object_class: OpenStruct
|
14
|
+
)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
# Parses the 'system' JSON node as a dynamic OpenStruct object.
|
18
|
+
#
|
19
|
+
# * *Returns*:
|
20
|
+
# - +OpenStruct+ The system properties of the taxonomy group
|
21
|
+
def system
|
22
|
+
@system unless @system.nil?
|
23
|
+
@system = JSON.parse(
|
24
|
+
JSON.generate(@source['system']),
|
25
|
+
object_class: OpenStruct
|
26
|
+
)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
# Constructor.
|
30
|
+
#
|
31
|
+
# * *Args*:
|
32
|
+
# - *json* (+JSON+) A JSON node representing a taxonomy group
|
33
|
+
def initialize(source)
|
34
|
+
@source = source
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -1,19 +1,21 @@
|
|
1
1
|
require 'delivery/query_parameters/parameter_base'
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
module QueryParameters
|
7
|
+
# Provides the base class for filter implementations.
|
8
|
+
# See https://developer.kenticocloud.com/v1/reference#content-filtering
|
9
|
+
class Filter < ParameterBase
|
10
|
+
# Constructor.
|
11
|
+
#
|
12
|
+
# * *Args*:
|
13
|
+
# - *key* (+string+) The field to filter upon
|
14
|
+
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
15
|
+
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
16
|
+
def initialize(key, operator, values)
|
17
|
+
super(key, operator, values)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -31,9 +33,9 @@ class String
|
|
31
33
|
# - +Object+ One or more objects representing the values that must appear in the field
|
32
34
|
#
|
33
35
|
# * *Returns*:
|
34
|
-
# -
|
36
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
35
37
|
def all(*args)
|
36
|
-
|
38
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[all]', *args)
|
37
39
|
end
|
38
40
|
|
39
41
|
# Represents a filter that matches a content item if the specified content
|
@@ -45,9 +47,9 @@ class String
|
|
45
47
|
# - +Object+ One or more objects representing the values that may appear in the field
|
46
48
|
#
|
47
49
|
# * *Returns*:
|
48
|
-
# -
|
50
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
49
51
|
def any(*args)
|
50
|
-
|
52
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[any]', *args)
|
51
53
|
end
|
52
54
|
|
53
55
|
# Represents a filter that matches a content item if the specified content element
|
@@ -59,9 +61,9 @@ class String
|
|
59
61
|
# - +Object+ An object representing the value that must appear in the field
|
60
62
|
#
|
61
63
|
# * *Returns*:
|
62
|
-
# -
|
64
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
63
65
|
def contains(*args)
|
64
|
-
|
66
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[contains]', *args)
|
65
67
|
end
|
66
68
|
|
67
69
|
# Represents a filter that matches a content item if the specified
|
@@ -71,9 +73,9 @@ class String
|
|
71
73
|
# - +Object+ An object representing the value that must equal the value in the field
|
72
74
|
#
|
73
75
|
# * *Returns*:
|
74
|
-
# -
|
76
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
75
77
|
def eq(*args)
|
76
|
-
|
78
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '', *args)
|
77
79
|
end
|
78
80
|
|
79
81
|
# Represents a filter that matches a content item if the specified content
|
@@ -84,9 +86,9 @@ class String
|
|
84
86
|
# - +Object+ An object representing the lowest possible value of the field, non-inclusive
|
85
87
|
#
|
86
88
|
# * *Returns*:
|
87
|
-
# -
|
89
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
88
90
|
def gt(*args)
|
89
|
-
|
91
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gt]', *args)
|
90
92
|
end
|
91
93
|
|
92
94
|
# Represents a filter that matches a content item if the specified content
|
@@ -97,9 +99,9 @@ class String
|
|
97
99
|
# - +Object+ An object representing the lowest possible value of the field
|
98
100
|
#
|
99
101
|
# * *Returns*:
|
100
|
-
# -
|
102
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
101
103
|
def gt_or_eq(*args)
|
102
|
-
|
104
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[gte]', *args)
|
103
105
|
end
|
104
106
|
|
105
107
|
# Represents a filter that matches a content item if the specified
|
@@ -110,9 +112,9 @@ class String
|
|
110
112
|
# - +Object+ One or more objects representing the required values of the field
|
111
113
|
#
|
112
114
|
# * *Returns*:
|
113
|
-
# -
|
115
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
114
116
|
def in(*args)
|
115
|
-
|
117
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[in]', *args)
|
116
118
|
end
|
117
119
|
|
118
120
|
# Represents a filter that matches a content item if the specified content
|
@@ -123,9 +125,9 @@ class String
|
|
123
125
|
# - +Object+ An object representing the highest possible value of the field, non-inclusive
|
124
126
|
#
|
125
127
|
# * *Returns*:
|
126
|
-
# -
|
128
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
127
129
|
def lt(*args)
|
128
|
-
|
130
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lt]', *args)
|
129
131
|
end
|
130
132
|
|
131
133
|
# Represents a filter that matches a content item if the specified content
|
@@ -136,9 +138,9 @@ class String
|
|
136
138
|
# - +Object+ An object representing the highest possible value of the field
|
137
139
|
#
|
138
140
|
# * *Returns*:
|
139
|
-
# -
|
141
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
140
142
|
def lt_or_eq(*args)
|
141
|
-
|
143
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[lte]', *args)
|
142
144
|
end
|
143
145
|
|
144
146
|
# Represents a filter that matches a content item if the specified
|
@@ -149,8 +151,8 @@ class String
|
|
149
151
|
# - +Object+ An object representing the lowest and highest possible values of the field
|
150
152
|
#
|
151
153
|
# * *Returns*:
|
152
|
-
# -
|
154
|
+
# - Kentico::Kontent::Delivery::QueryParameters::Filter
|
153
155
|
def range(*args)
|
154
|
-
|
156
|
+
Kentico::Kontent::Delivery::QueryParameters::Filter.new(self, '[range]', *args)
|
155
157
|
end
|
156
158
|
end
|
@@ -1,40 +1,42 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Kentico
|
2
|
+
module Kontent
|
3
|
+
module Delivery
|
4
|
+
module QueryParameters
|
5
|
+
# Base class for all parameters added to a DeliveryQuery. All
|
6
|
+
# QueryParameters will appear in the query string.
|
7
|
+
class ParameterBase
|
8
|
+
attr_accessor :key
|
9
|
+
SEPARATOR = CGI.escape(',')
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
# Constructor.
|
12
|
+
#
|
13
|
+
# * *Args*:
|
14
|
+
# - *key* (+string+) The field to filter upon
|
15
|
+
# - *operator* (+string+) The Kentico Kontent filter being applied to the field, in brackets
|
16
|
+
# - *values* (+Object+) One or more values which will appear as the value of the query string parameter
|
17
|
+
def initialize(key, operator, values)
|
18
|
+
self.key = key
|
19
|
+
values = [values] unless values.respond_to? :each
|
20
|
+
@values = values
|
21
|
+
@operator = operator
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
# Converts the object into a valid query string parameter for use in
|
25
|
+
# a request to Delivery. The key, operator, and values are all escaped
|
26
|
+
# and if there are multiple values, they are joined with commas.
|
27
|
+
#
|
28
|
+
# * *Returns*:
|
29
|
+
# - +string+ A query string parameter without any additional characters (e.g. '&')
|
30
|
+
def provide_query_string_parameter
|
31
|
+
escaped_values = []
|
32
|
+
@values.each { |n| escaped_values << CGI.escape(n.to_s) }
|
33
|
+
format(
|
34
|
+
'%<k>s%<o>s=%<v>s',
|
35
|
+
k: CGI.escape(key),
|
36
|
+
o: CGI.escape(@operator),
|
37
|
+
v: escaped_values.join(SEPARATOR)
|
38
|
+
)
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -1,74 +1,76 @@
|
|
1
1
|
require 'delivery/query_parameters/parameter_base'
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Kentico
|
4
|
+
module Kontent
|
5
|
+
module Delivery
|
6
|
+
module QueryParameters
|
7
|
+
# Represents the entire query string for a request to Delivery.
|
8
|
+
class QueryString
|
9
|
+
def initialize
|
10
|
+
@params = []
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
# Adds a parameter to the query string
|
14
|
+
#
|
15
|
+
# * *Args*:
|
16
|
+
# - *param* (+Object+) Either a string representing the key for the parameter, or a complete Kentico::Kontent::Delivery::QueryParameters::ParameterBase object
|
17
|
+
# - *values* (+string+) A string or array of strings representing the values for the parameter
|
18
|
+
# - *operator* (+string+) Kentico Kontent filtering parameter, placed after the key, before the equal sign
|
19
|
+
def set_param(param, values = '', operator = '')
|
20
|
+
parameter_base =
|
21
|
+
if param.is_a? String
|
22
|
+
Kentico::Kontent::Delivery::QueryParameters::ParameterBase.new(
|
23
|
+
param,
|
24
|
+
operator,
|
25
|
+
values
|
26
|
+
)
|
27
|
+
else
|
28
|
+
param
|
29
|
+
end
|
30
|
+
# Ensure we have a ParameterBase object
|
31
|
+
return unless parameter_base.respond_to? 'provide_query_string_parameter'
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
remove_param parameter_base.key
|
34
|
+
@params << parameter_base
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
# Removes all parameters from the query string with a matching key.
|
38
|
+
#
|
39
|
+
# * *Args*:
|
40
|
+
# - *key* (+string+) Parameter key
|
41
|
+
def remove_param(key)
|
42
|
+
@params.delete_if { |i| i.key.eql? key }
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
# Returns all parameters from the query string with a matching key.
|
46
|
+
#
|
47
|
+
# * *Args*:
|
48
|
+
# - *key* (+string+) Parameter key
|
49
|
+
#
|
50
|
+
# * *Returns*:
|
51
|
+
# - +Object+ One or more Kentico::Kontent::Delivery::QueryParameters::ParameterBase objects
|
52
|
+
def param(key)
|
53
|
+
@params.select { |p| p.key.eql? key }
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
# Checks whether there are any parameters defined.
|
57
|
+
#
|
58
|
+
# * *Returns*:
|
59
|
+
# - +bool+ True if there are no parameters set.
|
60
|
+
def empty?
|
61
|
+
@params.empty?
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
# Generates a full query string based on the set parameters, with the
|
65
|
+
# required '?' character at the start. Accomplished by calling the
|
66
|
+
# Kentico::Kontent::Delivery::QueryParameters::ParameterBase.provide_query_string_parameter
|
67
|
+
# method for each parameter.
|
68
|
+
#
|
69
|
+
# * *Returns*:
|
70
|
+
# - +string+ A complete query string
|
71
|
+
def to_s
|
72
|
+
'?' + @params.map(&:provide_query_string_parameter).join('&')
|
73
|
+
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|