cloudinary 2.1.2 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e13d4a9d8701f1b37bfa34a12f4d393390a2d61ee0a351edb35c662f347ef2f
4
- data.tar.gz: d818c41861f532a8cc991d8bba70fc3bf29ae3fcbe0e769efec86a4457767045
3
+ metadata.gz: 1244ab3ce91f6fda0b07e5438ed79f896cde743306efb9c3ac58e5a5f1d4a6dc
4
+ data.tar.gz: a36510b3d2a2e1b788c2455e5def6f314b78b0b94def573a75a4750e96498b6c
5
5
  SHA512:
6
- metadata.gz: c32eab5d9184adb7063bbd5f5b1a9e728ded397b76834bceaa331faf9d3429e4ad45bf7493aa4e3ceedcdf33eba21b4354fbd7173bcd7c3727382d9b5b43793e
7
- data.tar.gz: 28c275bc3ae56751653ceefca9cbd81609ee9894cac57ee259ded5083ca94c64a2936196fd5bff92e1cd09c91275edce33b98e0fcf9edf903d2c70ad6fa1ad6d
6
+ metadata.gz: 7ba876181927174ec445d3abd04c79cc03af3837713c234ea9a89651131b6dd4c4be6e3ec02d155596d4f2ce821b269600adda74210408af066b04e0671169fb
7
+ data.tar.gz: 8bcbb47be56d985537d237fcd5989979555ba0d622bf8a6a3f60484e8b31ffd7d0682353ce4768e4f732edb3fe1a909e001640226fc8fe085ff35cc321b662c6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ 2.3.0 / 2025-02-20
2
+ ==================
3
+
4
+ New functionality and features
5
+ ------------------------------
6
+
7
+ * Add support for `429 Too Many Requests` HTTP status code
8
+ * Add support for `allow_dynamic_list_values` parameter in `MetadataField`
9
+ * Add support for `config` Admin API
10
+
11
+ 2.2.0 / 2024-09-08
12
+ ==================
13
+
14
+ New functionality and features
15
+ ------------------------------
16
+
17
+ * Add support for ActiveStorage model service configuration
18
+
19
+ Other Changes
20
+ -------------
21
+
22
+ * Fix asset type detection in ActiveStorage
23
+ * Add explicit `ostruct` dependency
24
+
1
25
  2.1.2 / 2024-08-18
2
26
  ==================
3
27
 
data/cloudinary.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency "faraday", ">= 2.0.1", "< 3.0.0"
28
28
  s.add_dependency "faraday-multipart", "~> 1.0", ">= 1.0.4"
29
29
  s.add_dependency 'faraday-follow_redirects', '~> 0.3.0'
30
+ s.add_dependency "ostruct"
30
31
 
31
32
  s.add_development_dependency "rails", ">= 6.1.7", "< 8.0.0"
32
33
  s.add_development_dependency "rexml", ">= 3.2.5", "< 4.0.0"
@@ -17,9 +17,13 @@ module CloudinaryHelper
17
17
  alias cloudinary_url_internal_original cloudinary_url_internal
18
18
 
19
19
  def cloudinary_url_internal(source, options = {})
20
- if defined?(ActiveStorage::Blob.service.public_id) && options.fetch(:type, "").to_s != "fetch"
21
- source = ActiveStorage::Blob.service.public_id(source)
20
+ service_instance, options = ActiveStorage::Service::CloudinaryService.fetch_service_instance_and_config(source, options)
21
+ service_instance ||= ActiveStorage::Blob.service
22
+
23
+ if defined?(service_instance.public_id) && options.fetch(:type, "").to_s != "fetch"
24
+ source = service_instance.public_id(source)
22
25
  end
26
+
23
27
  cloudinary_url_internal_original(source, options)
24
28
  end
25
29
  end
@@ -58,6 +62,7 @@ module ActiveStorage
58
62
  end
59
63
 
60
64
  def url(key, filename: nil, content_type: '', **options)
65
+ key = find_blob_or_use_key(key)
61
66
  instrument :url, key: key do |payload|
62
67
  url = Cloudinary::Utils.cloudinary_url(
63
68
  full_public_id_internal(key, options),
@@ -101,6 +106,7 @@ module ActiveStorage
101
106
  end
102
107
 
103
108
  def delete(key)
109
+ key = find_blob_or_use_key(key)
104
110
  instrument :delete, key: key do
105
111
  options = {
106
112
  resource_type: resource_type(nil, key),
@@ -117,6 +123,7 @@ module ActiveStorage
117
123
  end
118
124
 
119
125
  def exist?(key)
126
+ key = find_blob_or_use_key(key)
120
127
  instrument :exist, key: key do |payload|
121
128
  begin
122
129
  options = {
@@ -153,8 +160,7 @@ module ActiveStorage
153
160
 
154
161
  # Return the partial content in the byte +range+ of the file at the +key+.
155
162
  def download_chunk(key, range)
156
- url = Cloudinary::Utils.cloudinary_url(public_id(key), resource_type: resource_type(nil, key))
157
- uri = URI(url)
163
+ uri = URI(url(key))
158
164
  instrument :download, key: key do
159
165
  req = Net::HTTP::Get.new(uri)
160
166
  range_end = case
@@ -190,6 +196,33 @@ module ActiveStorage
190
196
  full_public_id_internal(public_id)
191
197
  end
192
198
 
199
+ def self.fetch_service_instance_and_config(source, options)
200
+ return [nil, options] unless defined?(ActiveStorage::BlobKey) && source.is_a?(ActiveStorage::BlobKey) &&
201
+ source.respond_to?(:attributes) && source.attributes.key?(:service_name)
202
+
203
+ service_name = source.attributes[:service_name]
204
+
205
+ begin
206
+ service_instance = ActiveStorage::Blob.services.fetch(service_name.to_sym)
207
+
208
+ unless service_instance.instance_of?(ActiveStorage::Service::CloudinaryService)
209
+ Rails.logger.error "Expected service instance #{service_instance.class.name} to be of type ActiveStorage::Service::CloudinaryService."
210
+ return [nil, options]
211
+ end
212
+
213
+ service_config = Rails.application.config.active_storage.service_configurations.fetch(service_name)
214
+ options = service_config.merge(options)
215
+ rescue NameError => e
216
+ Rails.logger.error "Failed to retrieve the service instance for #{service_name}: #{e.message}"
217
+ return [nil, options]
218
+ rescue => e
219
+ Rails.logger.error "An unexpected error occurred: #{e.message}"
220
+ return [nil, options]
221
+ end
222
+
223
+ [service_instance, options]
224
+ end
225
+
193
226
  private
194
227
 
195
228
  def api_uri(action, options)
@@ -278,5 +311,19 @@ module ActiveStorage
278
311
  end
279
312
  content_type_to_resource_type(content_type)
280
313
  end
314
+
315
+ def find_blob_or_use_key(key)
316
+ if key.is_a?(ActiveStorage::BlobKey)
317
+ key
318
+ else
319
+ begin
320
+ blob = ActiveStorage::Blob.find_by(key: key)
321
+ blob ? ActiveStorage::BlobKey.new(blob.attributes.as_json) : key
322
+ rescue ActiveRecord::StatementInvalid => e
323
+ # Return the original key if an error occurs
324
+ key
325
+ end
326
+ end
327
+ end
281
328
  end
282
329
  end
@@ -14,6 +14,22 @@ class Cloudinary::Api
14
14
  call_api(:get, "ping", {}, options)
15
15
  end
16
16
 
17
+ # Retrieves account configuration details.
18
+ #
19
+ # @param [Hash] options The optional parameters.
20
+ #
21
+ # @return [Cloudinary::Api::Response]
22
+ #
23
+ # @raise [Cloudinary::Api::Error]
24
+ #
25
+ # @see https://cloudinary.com/documentation/admin_api#config
26
+ def self.config(options={})
27
+ uri = "config"
28
+ params = only(options, :settings)
29
+
30
+ call_api(:get, uri, params, options)
31
+ end
32
+
17
33
  # Gets cloud usage details.
18
34
  #
19
35
  # Returns a report detailing your current Cloudinary cloud usage details, including
@@ -1021,9 +1037,7 @@ class Cloudinary::Api
1021
1037
  #
1022
1038
  # @see https://cloudinary.com/documentation/admin_api#create_a_metadata_field
1023
1039
  def self.add_metadata_field(field, options = {})
1024
- params = only(field, :type, :external_id, :label, :mandatory, :default_value, :validation, :datasource)
1025
-
1026
- call_metadata_api(:post, [], params, options)
1040
+ call_metadata_api(:post, [], prepare_metadata_field_params(field), options)
1027
1041
  end
1028
1042
 
1029
1043
  # Updates a metadata field by external ID.
@@ -1040,10 +1054,19 @@ class Cloudinary::Api
1040
1054
  #
1041
1055
  # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_by_external_id
1042
1056
  def self.update_metadata_field(field_external_id, field, options = {})
1043
- uri = [field_external_id]
1044
- params = only(field, :label, :mandatory, :default_value, :validation)
1057
+ uri = [field_external_id]
1045
1058
 
1046
- call_metadata_api(:put, uri, params, options)
1059
+ call_metadata_api(:put, uri, prepare_metadata_field_params(field), options)
1060
+ end
1061
+
1062
+ # Prepares optional parameters for add/update_metadata_field API calls.
1063
+ # @param [Hash] options Additional options
1064
+ # @return [Object] Optional parameters
1065
+ def self.prepare_metadata_field_params(field)
1066
+ only(field,
1067
+ :type, :external_id, :label, :mandatory, :restrictions, :default_value, :default_disabled,
1068
+ :validation, :datasource, :allow_dynamic_list_values
1069
+ )
1047
1070
  end
1048
1071
 
1049
1072
  # Deletes a metadata field definition by external ID.
@@ -57,7 +57,7 @@ module Cloudinary::BaseApi
57
57
  when 403 then NotAllowed
58
58
  when 404 then NotFound
59
59
  when 409 then AlreadyExists
60
- when 420 then RateLimited
60
+ when 420, 429 then RateLimited
61
61
  when 500 then GeneralError
62
62
  else raise GeneralError.new("Server returned unexpected status code - #{response.status} - #{response.body}")
63
63
  end
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "2.1.2"
3
+ VERSION = "2.3.0"
4
4
  end
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: 2.1.2
4
+ version: 2.3.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: 2024-08-18 00:00:00.000000000 Z
13
+ date: 2025-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: ostruct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rails
71
85
  requirement: !ruby/object:Gem::Requirement