delivery-sdk-ruby 1.0.5 → 2.0.3

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