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
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "delivery"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "delivery"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/lib/delivery-sdk-ruby.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/delivery/client/delivery_client'
|
2
|
-
require File.dirname(__FILE__) + '/delivery/client/delivery_query'
|
3
|
-
require File.dirname(__FILE__) + '/delivery/models/content_item'
|
4
|
-
require File.dirname(__FILE__) + '/delivery/models/content_type'
|
5
|
-
require File.dirname(__FILE__) + '/delivery/models/taxonomy_group'
|
6
|
-
require File.dirname(__FILE__) + '/delivery/query_parameters/filters'
|
7
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_item_listing_response'
|
8
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_item_response'
|
9
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_type_listing_response'
|
10
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_type_response'
|
11
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_listing_response'
|
12
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_response'
|
13
|
-
require File.dirname(__FILE__) + '/delivery/responses/delivery_element_response'
|
14
|
-
require File.dirname(__FILE__) + '/delivery/resolvers/content_link_resolver'
|
15
|
-
require File.dirname(__FILE__) + '/delivery/resolvers/inline_content_item_resolver'
|
16
|
-
require File.dirname(__FILE__) + '/delivery/resolvers/linked_item_resolver'
|
17
|
-
require File.dirname(__FILE__) + '/delivery/builders/image_transformation_builder'
|
1
|
+
require File.dirname(__FILE__) + '/delivery/client/delivery_client'
|
2
|
+
require File.dirname(__FILE__) + '/delivery/client/delivery_query'
|
3
|
+
require File.dirname(__FILE__) + '/delivery/models/content_item'
|
4
|
+
require File.dirname(__FILE__) + '/delivery/models/content_type'
|
5
|
+
require File.dirname(__FILE__) + '/delivery/models/taxonomy_group'
|
6
|
+
require File.dirname(__FILE__) + '/delivery/query_parameters/filters'
|
7
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_item_listing_response'
|
8
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_item_response'
|
9
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_type_listing_response'
|
10
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_type_response'
|
11
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_listing_response'
|
12
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_response'
|
13
|
+
require File.dirname(__FILE__) + '/delivery/responses/delivery_element_response'
|
14
|
+
require File.dirname(__FILE__) + '/delivery/resolvers/content_link_resolver'
|
15
|
+
require File.dirname(__FILE__) + '/delivery/resolvers/inline_content_item_resolver'
|
16
|
+
require File.dirname(__FILE__) + '/delivery/resolvers/linked_item_resolver'
|
17
|
+
require File.dirname(__FILE__) + '/delivery/builders/image_transformation_builder'
|
@@ -1,141 +1,143 @@
|
|
1
|
-
require 'delivery/query_parameters/query_string'
|
2
|
-
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
(x
|
90
|
-
(
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
(value
|
125
|
-
(value == '
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
1
|
+
require 'delivery/query_parameters/query_string'
|
2
|
+
|
3
|
+
module KenticoCloud
|
4
|
+
module Delivery
|
5
|
+
module Builders
|
6
|
+
class ImageTransformationBuilder
|
7
|
+
FIT_MODE_CLIP = 'clip'.freeze
|
8
|
+
FIT_MODE_SCALE = 'scale'.freeze
|
9
|
+
FIT_MODE_CROP = 'crop'.freeze
|
10
|
+
FORMAT_GIF = 'gif'.freeze
|
11
|
+
FORMAT_PNG = 'png'.freeze
|
12
|
+
FORMAT_PNG8 = 'png8'.freeze
|
13
|
+
FORMAT_JPG = 'jpg'.freeze
|
14
|
+
FORMAT_PJPG = 'pjpg'.freeze
|
15
|
+
FORMAT_WEBP = 'webp'.freeze
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def transform(url)
|
19
|
+
AssetURL.new url
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class AssetURL
|
25
|
+
INVALID_PARAMS = 'One or more of the parameters is invalid. '\
|
26
|
+
'See https://developer.kenticocloud.com/v1/reference#focal-point-crop'\
|
27
|
+
'for more information.'.freeze
|
28
|
+
ONE_TO_100 = 'Quality parameter must be between 1 and 100.'.freeze
|
29
|
+
BOOLEAN_PARAM = 'The lossless parameter must be "true," "false," '\
|
30
|
+
'1, or 0.'.freeze
|
31
|
+
|
32
|
+
def initialize(url)
|
33
|
+
@url = url
|
34
|
+
@query_string = KenticoCloud::Delivery::QueryParameters::QueryString.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
@url + @query_string.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def with_width(width)
|
42
|
+
@query_string.set_param 'w', width
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def with_height(height)
|
47
|
+
@query_string.set_param 'h', height
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def with_pixel_ratio(dpr)
|
52
|
+
@query_string.set_param 'dpr', dpr
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def with_fit_mode(fit)
|
57
|
+
@query_string.set_param 'fit', fit
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Setting this will remove focal point cropping from the image,
|
62
|
+
# as the two options are incompatible.
|
63
|
+
# @param x
|
64
|
+
# @param y
|
65
|
+
# @param width
|
66
|
+
# @param height
|
67
|
+
def with_rect(x, y, width, height)
|
68
|
+
@query_string.remove_param 'fp-x'
|
69
|
+
@query_string.remove_param 'fp-y'
|
70
|
+
@query_string.remove_param 'fp-z'
|
71
|
+
@query_string.remove_param 'crop', 'focalpoint'
|
72
|
+
@query_string.set_param 'rect', "#{x},#{y},#{width},#{height}"
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Setting this will remove the source rectangle region,
|
77
|
+
# as the two options are incompatible.
|
78
|
+
def with_focal_point(x, y, z)
|
79
|
+
raise ArgumentError, INVALID_PARAMS unless valid_dims?(x, y, z)
|
80
|
+
|
81
|
+
@query_string.remove_param 'rect'
|
82
|
+
@query_string.set_param 'fp-x', x
|
83
|
+
@query_string.set_param 'fp-y', y
|
84
|
+
@query_string.set_param 'fp-z', z
|
85
|
+
@query_string.set_param 'crop', 'focalpoint'
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def valid_dims?(x, y, z)
|
90
|
+
(x.to_f >= 0.0 && x.to_f <= 1.0) &&
|
91
|
+
(y.to_f >= 0.0 && y.to_f <= 1.0) &&
|
92
|
+
(z.to_i >= 1)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Sets the background color.
|
96
|
+
# @param [String] color a valid 3, 4, 6, or 8 digit hexadecimal color, without the # symbol
|
97
|
+
def with_background_color(color)
|
98
|
+
@query_string.set_param 'bg', color
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
def with_output_format(format)
|
103
|
+
@query_string.set_param 'fm', format
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def with_quality(quality)
|
108
|
+
raise ArgumentError, ONE_TO_100 unless quality.to_i >= 1 && quality.to_i <= 100
|
109
|
+
|
110
|
+
@query_string.set_param 'q', quality
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
# Sets lossless to true or false. If true, automatically sets the format to WebP
|
115
|
+
def with_lossless(lossless)
|
116
|
+
lossless = lossless.to_s.downcase
|
117
|
+
raise ArgumentError, BOOLEAN_PARAM unless bool? lossless
|
118
|
+
|
119
|
+
@query_string.set_param 'lossless', lossless
|
120
|
+
@query_string.set_param 'fm', KenticoCloud::Delivery::Builders::ImageTransformationBuilder::FORMAT_WEBP if %w[true 1].include? lossless
|
121
|
+
self
|
122
|
+
end
|
123
|
+
|
124
|
+
def bool?(value)
|
125
|
+
(value == 'true') ||
|
126
|
+
(value == 'false') ||
|
127
|
+
(value == '0') ||
|
128
|
+
(value == '1')
|
129
|
+
end
|
130
|
+
|
131
|
+
def with_auto_format_selection(auto)
|
132
|
+
auto = auto.to_s.downcase
|
133
|
+
if %w[true 1].include? auto
|
134
|
+
@query_string.set_param 'auto', 'format'
|
135
|
+
else
|
136
|
+
@query_string.remove_param 'auto'
|
137
|
+
end
|
138
|
+
self
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -1,73 +1,75 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
end
|
1
|
+
module KenticoCloud
|
2
|
+
module Delivery
|
3
|
+
module Builders
|
4
|
+
# Generates the URL required for Delivery REST API
|
5
|
+
class UrlBuilder
|
6
|
+
URL_TEMPLATE_BASE = 'https://deliver.kenticocloud.com/%s'.freeze
|
7
|
+
URL_TEMPLATE_PREVIEW = 'https://preview-deliver.kenticocloud.com/%s'.freeze
|
8
|
+
URL_TEMPLATE_ITEM = '/items/%s'.freeze
|
9
|
+
URL_TEMPLATE_ITEMS = '/items'.freeze
|
10
|
+
URL_TEMPLATE_TYPE = '/types/%s'.freeze
|
11
|
+
URL_TEMPLATE_TYPES = '/types'.freeze
|
12
|
+
URL_TEMPLATE_ELEMENTS = '/types/%s/elements/%s'.freeze
|
13
|
+
URL_TEMPLATE_TAXONOMY = '/taxonomies/%s'.freeze
|
14
|
+
URL_TEMPLATE_TAXONOMIES = '/taxonomies'.freeze
|
15
|
+
|
16
|
+
URL_MAX_LENGTH = 65_519
|
17
|
+
MSG_LONG_QUERY = 'The request url is too long. Split your query into multiple calls.'.freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def provide_url(query)
|
21
|
+
url = provide_base_url(query)
|
22
|
+
url += provide_path_part(query)
|
23
|
+
|
24
|
+
if query.query_string.empty?
|
25
|
+
url
|
26
|
+
else
|
27
|
+
url + query.query_string.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_url(url)
|
32
|
+
raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Returns relative path part of URL depending on query type
|
38
|
+
def provide_path_part(query)
|
39
|
+
case query.query_type
|
40
|
+
when KenticoCloud::Delivery::QUERY_TYPE_ITEMS
|
41
|
+
if query.code_name.nil?
|
42
|
+
URL_TEMPLATE_ITEMS
|
43
|
+
else
|
44
|
+
format(URL_TEMPLATE_ITEM, query.code_name)
|
45
|
+
end
|
46
|
+
when KenticoCloud::Delivery::QUERY_TYPE_TYPES
|
47
|
+
if query.code_name.nil?
|
48
|
+
URL_TEMPLATE_TYPES
|
49
|
+
else
|
50
|
+
format(URL_TEMPLATE_TYPE, query.code_name)
|
51
|
+
end
|
52
|
+
when KenticoCloud::Delivery::QUERY_TYPE_TAXONOMIES
|
53
|
+
if query.code_name.nil?
|
54
|
+
URL_TEMPLATE_TAXONOMIES
|
55
|
+
else
|
56
|
+
format(URL_TEMPLATE_TAXONOMY, query.code_name)
|
57
|
+
end
|
58
|
+
when KenticoCloud::Delivery::QUERY_TYPE_ELEMENT
|
59
|
+
format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the protocol and domain with project ID
|
64
|
+
def provide_base_url(query)
|
65
|
+
if query.use_preview
|
66
|
+
format(URL_TEMPLATE_PREVIEW, query.project_id)
|
67
|
+
else
|
68
|
+
format(URL_TEMPLATE_BASE, query.project_id)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|