cloudinary 1.25.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/cloudinary.gemspec +7 -1
- data/lib/active_storage/service/cloudinary_service.rb +1 -1
- data/lib/cloudinary/api.rb +155 -0
- data/lib/cloudinary/uploader.rb +16 -4
- data/lib/cloudinary/utils.rb +5 -3
- data/lib/cloudinary/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bb33366a739a067a66cbcaf66534e48663e726d57f4d4b3657c44ec43f092e7
|
4
|
+
data.tar.gz: 0dd05a5beabf06fc8d1914c7375fa7a6d37fce532edca0021919e13d9b28d318
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64cb7b27cd9909da6fbbaaf98777d4f05046098a6adb1572998323fd7517bf30c73095844683c83da59808f5945c93e90f1e2c685e06ff156b682fe92e902878
|
7
|
+
data.tar.gz: f098206a8c9f6c73609ad2415cfc90f8359c678461d0bb22f5164aba57111fe55129eed6e98767c6242387ee6294bf4139b034848a1ff9b792cf1dba9fa3ef77
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
1.26.0 / 2023-06-01
|
2
|
+
==================
|
3
|
+
|
4
|
+
New functionality and features
|
5
|
+
------------------------------
|
6
|
+
|
7
|
+
* Add support for related assets Admin APIs
|
8
|
+
* Add support for expressions in `start_offset` and `end_offset` parameters
|
9
|
+
* Add support for Conditional Metadata Rules API
|
10
|
+
* Add support for large files in Active Storage
|
11
|
+
|
1
12
|
1.25.0 / 2023-01-04
|
2
13
|
==================
|
3
14
|
|
data/cloudinary.gemspec
CHANGED
@@ -39,8 +39,12 @@ Gem::Specification.new do |s|
|
|
39
39
|
else
|
40
40
|
s.add_development_dependency "rake", "<= 12.2.1"
|
41
41
|
end
|
42
|
+
if RUBY_VERSION >= "2.7.0"
|
43
|
+
s.add_development_dependency "sqlite3"
|
44
|
+
else
|
45
|
+
s.add_development_dependency "sqlite3", "< 1.6.0"
|
46
|
+
end
|
42
47
|
|
43
|
-
s.add_development_dependency "sqlite3"
|
44
48
|
s.add_development_dependency "rspec", '>=3.5'
|
45
49
|
s.add_development_dependency "rspec-retry"
|
46
50
|
|
@@ -57,6 +61,8 @@ Gem::Specification.new do |s|
|
|
57
61
|
|
58
62
|
if RUBY_VERSION <= "2.4.0"
|
59
63
|
s.add_development_dependency "simplecov", "<= 0.17.1" # support testing Ruby 1.9
|
64
|
+
s.add_development_dependency 'loofah', '~>2.19.1'
|
65
|
+
s.add_development_dependency "rails-html-sanitizer", "<1.5.0"
|
60
66
|
else
|
61
67
|
s.add_development_dependency "simplecov", "> 0.18.0"
|
62
68
|
end
|
@@ -39,7 +39,7 @@ module ActiveStorage
|
|
39
39
|
begin
|
40
40
|
extra_headers = checksum.nil? ? {} : {Headers::CONTENT_MD5 => checksum}
|
41
41
|
options = @options.merge(options)
|
42
|
-
Cloudinary::Uploader.
|
42
|
+
Cloudinary::Uploader.upload_large(
|
43
43
|
io,
|
44
44
|
public_id: public_id_internal(key),
|
45
45
|
resource_type: resource_type(io, key),
|
data/lib/cloudinary/api.rb
CHANGED
@@ -406,6 +406,76 @@ class Cloudinary::Api
|
|
406
406
|
call_api(:delete, uri, params, options)
|
407
407
|
end
|
408
408
|
|
409
|
+
# Relates an asset to other assets by public IDs.
|
410
|
+
#
|
411
|
+
# @param [String] public_id The public ID of the asset.
|
412
|
+
# @param [String|Array] assets_to_relate The array of up to 10 fully_qualified_public_ids given as
|
413
|
+
# resource_type/type/public_id.
|
414
|
+
# @param [Hash] options The optional parameters. See the
|
415
|
+
# {https://cloudinary.com/documentation/admin_api#add_related_assets Admin API} documentation.
|
416
|
+
#
|
417
|
+
# @return [Cloudinary::Api::Response]
|
418
|
+
#
|
419
|
+
# @raise [Cloudinary::Api::Error]
|
420
|
+
def self.add_related_assets(public_id, assets_to_relate, options={})
|
421
|
+
resource_type = options[:resource_type] || "image"
|
422
|
+
type = options[:type] || "upload"
|
423
|
+
uri = "resources/related_assets/#{resource_type}/#{type}/#{public_id}"
|
424
|
+
params = {:assets_to_relate => Cloudinary::Utils.build_array(assets_to_relate)}
|
425
|
+
call_api(:post, uri, params, options)
|
426
|
+
end
|
427
|
+
|
428
|
+
# Relates an asset to other assets by asset IDs.
|
429
|
+
#
|
430
|
+
# @param [String] asset_id The asset ID of the asset to update.
|
431
|
+
# @param [String|Array] assets_to_relate The array of up to 10 asset IDs.
|
432
|
+
# @param [Hash] options The optional parameters. See the
|
433
|
+
# {https://cloudinary.com/documentation/admin_api#add_related_assets_by_asset_id Admin API} documentation.
|
434
|
+
#
|
435
|
+
# @return [Cloudinary::Api::Response]
|
436
|
+
#
|
437
|
+
# @raise [Cloudinary::Api::Error]
|
438
|
+
def self.add_related_assets_by_asset_ids(asset_id, assets_to_relate, options={})
|
439
|
+
uri = "resources/related_assets/#{asset_id}"
|
440
|
+
params = {:assets_to_relate => Cloudinary::Utils.build_array(assets_to_relate)}
|
441
|
+
call_api(:post, uri, params, options)
|
442
|
+
end
|
443
|
+
|
444
|
+
# Unrelates an asset from other assets by public IDs.
|
445
|
+
#
|
446
|
+
# @param [String] public_id The public ID of the asset.
|
447
|
+
# @param [String|Array] assets_to_unrelate The array of up to 10 fully_qualified_public_ids given as
|
448
|
+
# resource_type/type/public_id.
|
449
|
+
# @param [Hash] options The optional parameters. See the
|
450
|
+
# {https://cloudinary.com/documentation/admin_api#delete_related_assets Admin API} documentation.
|
451
|
+
#
|
452
|
+
# @return [Cloudinary::Api::Response]
|
453
|
+
#
|
454
|
+
# @raise [Cloudinary::Api::Error]
|
455
|
+
def self.delete_related_assets(public_id, assets_to_unrelate, options={})
|
456
|
+
resource_type = options[:resource_type] || "image"
|
457
|
+
type = options[:type] || "upload"
|
458
|
+
uri = "resources/related_assets/#{resource_type}/#{type}/#{public_id}"
|
459
|
+
params = {:assets_to_unrelate => Cloudinary::Utils.build_array(assets_to_unrelate)}
|
460
|
+
call_api(:delete, uri, params, options)
|
461
|
+
end
|
462
|
+
|
463
|
+
# Unrelates an asset from other assets by asset IDs.
|
464
|
+
#
|
465
|
+
# @param [String] asset_id The asset ID of the asset to update.
|
466
|
+
# @param [String|Array] assets_to_unrelate The array of up to 10 asset IDs.
|
467
|
+
# @param [Hash] options The optional parameters. See the
|
468
|
+
# {https://cloudinary.com/documentation/admin_api#delete_related_assets_by_asset_id Admin API} documentation.
|
469
|
+
#
|
470
|
+
# @return [Cloudinary::Api::Response]
|
471
|
+
#
|
472
|
+
# @raise [Cloudinary::Api::Error]
|
473
|
+
def self.delete_related_assets_by_asset_ids(asset_id, assets_to_unrelate, options={})
|
474
|
+
uri = "resources/related_assets/#{asset_id}"
|
475
|
+
params = {:assets_to_unrelate => Cloudinary::Utils.build_array(assets_to_unrelate)}
|
476
|
+
call_api(:delete, uri, params, options)
|
477
|
+
end
|
478
|
+
|
409
479
|
# Lists all the tags currently used for a specified asset type.
|
410
480
|
#
|
411
481
|
# @param [Hash] options The optional parameters. See the
|
@@ -1077,6 +1147,75 @@ class Cloudinary::Api
|
|
1077
1147
|
call_metadata_api(:put, uri, params, options)
|
1078
1148
|
end
|
1079
1149
|
|
1150
|
+
# Lists all metadata rules definitions.
|
1151
|
+
#
|
1152
|
+
# @param [Hash] options The optional parameters.
|
1153
|
+
#
|
1154
|
+
# @return [Cloudinary::Api::Response]
|
1155
|
+
#
|
1156
|
+
# @raise [Cloudinary::Api::Error]
|
1157
|
+
#
|
1158
|
+
# @see https://cloudinary.com/documentation/conditional_metadata_rules_api#get_metadata_rules
|
1159
|
+
def self.list_metadata_rules(options = {})
|
1160
|
+
call_metadata_rules_api(:get, [], {}, options)
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
|
1164
|
+
# Creates a new metadata rule definition.
|
1165
|
+
#
|
1166
|
+
# @param [Hash] rule The rule to add.
|
1167
|
+
# @param [Hash] options The optional parameters.
|
1168
|
+
#
|
1169
|
+
# @return [Cloudinary::Api::Response]
|
1170
|
+
#
|
1171
|
+
# @raise [Cloudinary::Api::Error]
|
1172
|
+
#
|
1173
|
+
# @see https://cloudinary.com/documentation/conditional_metadata_rules_api#create_a_metadata_rule
|
1174
|
+
def self.add_metadata_rule(rule, options = {})
|
1175
|
+
params = only(rule, :metadata_field_id, :condition, :result, :name)
|
1176
|
+
|
1177
|
+
call_metadata_rules_api(:post, [], params, options)
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
# Updates a metadata rule by external ID.
|
1181
|
+
#
|
1182
|
+
# Updates an existing metadata rule definition. Expects a JSON object which defines the updated rule.
|
1183
|
+
#
|
1184
|
+
# @param [String] external_id The ID of the rule to update.
|
1185
|
+
# @param [Hash] rule The rule definition.
|
1186
|
+
# @param [Hash] options The optional parameters.
|
1187
|
+
#
|
1188
|
+
# @return [Cloudinary::Api::Response]
|
1189
|
+
#
|
1190
|
+
# @raise [Cloudinary::Api::Error]
|
1191
|
+
#
|
1192
|
+
# @see https://cloudinary.com/documentation/conditional_metadata_rules_api#update_a_metadata_rule_by_id
|
1193
|
+
def self.update_metadata_rule(external_id, rule, options = {})
|
1194
|
+
uri = [external_id]
|
1195
|
+
params = only(rule, :metadata_field_id, :condition, :result, :name, :state)
|
1196
|
+
|
1197
|
+
call_metadata_rules_api(:put, uri, params, options)
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
# Deletes a metadata rule definition by external ID.
|
1201
|
+
#
|
1202
|
+
# The rule should no longer be considered a valid candidate for all other endpoints
|
1203
|
+
# (it will not show up in the list of rules, etc).
|
1204
|
+
#
|
1205
|
+
# @param [String] external_id The ID of the rule to delete.
|
1206
|
+
# @param [Hash] options The optional parameters.
|
1207
|
+
#
|
1208
|
+
# @return [Cloudinary::Api::Response]
|
1209
|
+
#
|
1210
|
+
# @raise [Cloudinary::Api::Error]
|
1211
|
+
#
|
1212
|
+
# @see https://cloudinary.com/documentation/conditional_metadata_rules_api#delete_a_metadata_rule_by_id
|
1213
|
+
def self.delete_metadata_rule(external_id, options = {})
|
1214
|
+
uri = [external_id]
|
1215
|
+
|
1216
|
+
call_metadata_rules_api(:delete, uri, {}, options)
|
1217
|
+
end
|
1218
|
+
|
1080
1219
|
protected
|
1081
1220
|
|
1082
1221
|
# Execute a call api for input params.
|
@@ -1128,6 +1267,22 @@ class Cloudinary::Api
|
|
1128
1267
|
call_api(method, uri, params, options)
|
1129
1268
|
end
|
1130
1269
|
|
1270
|
+
# Protected function that assists with performing an API call to the metadata_rules part of the Admin API.
|
1271
|
+
#
|
1272
|
+
# @protected
|
1273
|
+
# @param [Symbol] method The HTTP method. Valid methods: get, post, put, delete
|
1274
|
+
# @param [Array] uri REST endpoint of the API (without 'metadata_rules')
|
1275
|
+
# @param [Hash] params Query/body parameters passed to the method
|
1276
|
+
# @param [Hash] options Additional options. Can be an override of the configuration, headers, etc.
|
1277
|
+
# @return [Cloudinary::Api::Response] Returned response from Cloudinary
|
1278
|
+
# @raise [Cloudinary::Api::Error]
|
1279
|
+
def self.call_metadata_rules_api(method, uri, params, options)
|
1280
|
+
options[:content_type] = :json
|
1281
|
+
uri = ["metadata_rules", uri].reject(&:empty?).join("/")
|
1282
|
+
|
1283
|
+
call_api(method, uri, params, options)
|
1284
|
+
end
|
1285
|
+
|
1131
1286
|
# Prepares optional parameters for asset/assetByAssetId API calls.
|
1132
1287
|
# @param [Hash] options Additional options
|
1133
1288
|
# @return [Object] Optional parameters
|
data/lib/cloudinary/uploader.rb
CHANGED
@@ -108,26 +108,38 @@ class Cloudinary::Uploader
|
|
108
108
|
public_id = public_id_or_options
|
109
109
|
options = old_options
|
110
110
|
end
|
111
|
+
|
112
|
+
options.merge(:public_id => public_id)
|
113
|
+
|
111
114
|
if Cloudinary::Utils.is_remote?(file)
|
112
|
-
return upload(file, options
|
113
|
-
|
115
|
+
return upload(file, options)
|
116
|
+
end
|
117
|
+
|
118
|
+
if file.is_a?(Pathname) || !file.respond_to?(:read)
|
114
119
|
filename = file
|
115
120
|
file = File.open(file, "rb")
|
116
121
|
else
|
117
122
|
filename = "cloudinaryfile"
|
118
123
|
end
|
119
124
|
|
125
|
+
chunk_size = options[:chunk_size] || 20_000_000
|
126
|
+
|
127
|
+
if file.size < chunk_size
|
128
|
+
return upload(file, options)
|
129
|
+
end
|
130
|
+
|
120
131
|
filename = options[:filename] if options[:filename]
|
121
132
|
|
122
133
|
unique_upload_id = Cloudinary::Utils.random_public_id
|
123
134
|
upload = nil
|
124
135
|
index = 0
|
125
|
-
|
136
|
+
|
126
137
|
until file.eof?
|
127
138
|
buffer = file.read(chunk_size)
|
128
139
|
current_loc = index*chunk_size
|
129
140
|
range = "bytes #{current_loc}-#{current_loc+buffer.size - 1}/#{file.size}"
|
130
|
-
upload = upload_large_part(Cloudinary::Blob.new(buffer, :original_filename => filename),
|
141
|
+
upload = upload_large_part(Cloudinary::Blob.new(buffer, :original_filename => filename),
|
142
|
+
options.merge(:unique_upload_id => unique_upload_id, :content_range => range))
|
131
143
|
index += 1
|
132
144
|
end
|
133
145
|
upload
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -1175,11 +1175,13 @@ class Cloudinary::Utils
|
|
1175
1175
|
# @private
|
1176
1176
|
def self.norm_range_value(value) # :nodoc:
|
1177
1177
|
offset = /^#{offset_any_pattern}$/.match( value.to_s)
|
1178
|
+
|
1178
1179
|
if offset
|
1179
|
-
modifier
|
1180
|
-
|
1180
|
+
modifier = offset[5].present? ? 'p' : ''
|
1181
|
+
"#{offset[1]}#{modifier}"
|
1182
|
+
else
|
1183
|
+
normalize_expression(value)
|
1181
1184
|
end
|
1182
|
-
value
|
1183
1185
|
end
|
1184
1186
|
private_class_method :norm_range_value
|
1185
1187
|
|
data/lib/cloudinary/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudinary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadav Soferman
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-01
|
13
|
+
date: 2023-06-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws_cf_signer
|
@@ -276,8 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
276
|
- !ruby/object:Gem::Version
|
277
277
|
version: '0'
|
278
278
|
requirements: []
|
279
|
-
|
280
|
-
rubygems_version: 2.7.6
|
279
|
+
rubygems_version: 3.4.12
|
281
280
|
signing_key:
|
282
281
|
specification_version: 4
|
283
282
|
summary: Client library for easily using the Cloudinary service
|