cloudinary 1.20.0 → 1.23.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.
@@ -1,21 +1,33 @@
1
1
  class Cloudinary::Api
2
2
  extend Cloudinary::BaseApi
3
3
 
4
+ # Tests the reachability of the Cloudinary API.
5
+ #
6
+ # @param [Hash] options The optional parameters.
7
+ #
8
+ # @return [Cloudinary::Api::Response] The current status of the Cloudinary servers
9
+ #
10
+ # @raise [Cloudinary::Api::Error]
11
+ #
12
+ # @see https://cloudinary.com/documentation/admin_api#ping
4
13
  def self.ping(options={})
5
14
  call_api(:get, "ping", {}, options)
6
15
  end
7
16
 
8
- # Gets account usage details
17
+ # Gets cloud usage details.
9
18
  #
10
- # Get a report on the status of your Cloudinary account usage details, including
11
- # storage, bandwidth, requests, number of resources, and add-on usage.
19
+ # Returns a report detailing your current Cloudinary cloud usage details, including
20
+ # storage, bandwidth, requests, number of assets, and add-on usage.
12
21
  # Note that numbers are updated periodically.
13
22
  #
14
- # @see https://cloudinary.com/documentation/admin_api#get_account_usage_details Get account usage details
23
+ # @param [Hash] options The optional parameters. See the
24
+ # {https://cloudinary.com/documentation/admin_api#usage Admin API} documentation.
15
25
  #
16
- # @param [Hash] options Additional options
17
26
  # @return [Cloudinary::Api::Response]
27
+ #
18
28
  # @raise [Cloudinary::Api:Error]
29
+ #
30
+ # @see https://cloudinary.com/documentation/admin_api#usage
19
31
  def self.usage(options={})
20
32
  uri = 'usage'
21
33
  date = options[:date]
@@ -25,39 +37,133 @@ class Cloudinary::Api
25
37
  call_api(:get, uri, {}, options)
26
38
  end
27
39
 
40
+ # Lists all uploaded assets filtered by any specified options.
41
+ #
42
+ # @param [Hash] options The optional parameters. See the
43
+ # {https://cloudinary.com/documentation/admin_api#get_resources Admin API} documentation.
44
+ #
45
+ # @return [Cloudinary::Api::Response]
46
+ #
47
+ # @raise [Cloudinary::Api::Error]
48
+ #
49
+ # @see https://cloudinary.com/documentation/admin_api#get_resources
28
50
  def self.resource_types(options={})
29
51
  call_api(:get, "resources", {}, options)
30
52
  end
31
53
 
54
+ # Lists all uploaded assets filtered by any specified options.
55
+ #
56
+ # see https://cloudinary.com/documentation/admin_api#get_resources Get all images
57
+ #
58
+ # @param [Hash] options The optional parameters. See the
59
+ # {https://cloudinary.com/documentation/admin_api#get_resources Admin API} documentation.
60
+ #
61
+ # @return [Cloudinary::Api::Response]
62
+ #
63
+ # @raise [Cloudinary::Api::Error]
64
+ #
65
+ # @see https://cloudinary.com/documentation/admin_api#get_resources
32
66
  def self.resources(options={})
33
67
  resource_type = options[:resource_type] || "image"
34
68
  type = options[:type]
35
69
  uri = "resources/#{resource_type}"
36
70
  uri += "/#{type}" unless type.blank?
37
- call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :moderations, :direction, :start_at), options)
71
+ call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :moderations, :direction, :start_at, :metadata), options)
38
72
  end
39
73
 
74
+ # Lists assets with the specified tag.
75
+ #
76
+ # This method does not return matching deleted assets, even if they have been backed up.
77
+ #
78
+ # @param [String] tag The tag value.
79
+ # @param [Hash] options The optional parameters. See the
80
+ # {https://cloudinary.com/documentation/admin_api#get_resources_by_tag Admin API} documentation.
81
+ #
82
+ # @return [Cloudinary::Api::Response]
83
+ #
84
+ # @raise [Cloudinary::Api::Error]
85
+ #
86
+ # @see https://cloudinary.com/documentation/admin_api#get_resources_by_tag
40
87
  def self.resources_by_tag(tag, options={})
41
88
  resource_type = options[:resource_type] || "image"
42
89
  uri = "resources/#{resource_type}/tags/#{tag}"
43
- call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction), options)
90
+ call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction, :metadata), options)
44
91
  end
45
92
 
93
+ # Lists assets currently in the specified moderation queue and status.
94
+ #
95
+ # @param [String] kind Type of image moderation queue to list.
96
+ # Valid values: "manual", "webpurify", "aws_rek", or "metascan".
97
+ # @param [String] status Only assets with this moderation status will be returned.
98
+ # Valid values: "pending", "approved", "rejected".
99
+ # @param [Hash] options The optional parameters. See the
100
+ # {https://cloudinary.com/documentation/admin_api#get_resources_in_moderation_queues Admin API} documentation.
101
+ #
102
+ # @return [Cloudinary::Api::Response]
103
+ #
104
+ # @raise [Cloudinary::Api::Error]
105
+ #
106
+ # @see https://cloudinary.com/documentation/admin_api#get_resources_in_moderation_queues
46
107
  def self.resources_by_moderation(kind, status, options={})
47
108
  resource_type = options[:resource_type] || "image"
48
109
  uri = "resources/#{resource_type}/moderations/#{kind}/#{status}"
49
- call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction), options)
110
+ call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction, :metadata), options)
50
111
  end
51
112
 
113
+ # Lists assets with the specified contextual metadata.
114
+ #
115
+ # This method does not return matching deleted assets, even if they have been backed up.
116
+ #
117
+ # @param [String] key Only assets with this context key are returned.
118
+ # @param [String] value Only assets with this context value for the specified context key are returned.
119
+ # If this parameter is not provided, all assets with the specified context key are returned,
120
+ # regardless of the key value.
121
+ # @param [Hash] options The optional parameters. See the
122
+ # {https://cloudinary.com/documentation/admin_api#get_resources_by_context Admin API} documentation.
123
+ #
124
+ # @return [Cloudinary::Api::Response]
125
+ #
126
+ # @raise [Cloudinary::Api::Error]
127
+ #
128
+ # @see https://cloudinary.com/documentation/admin_api#get_resources_by_context
52
129
  def self.resources_by_context(key, value=nil, options={})
53
130
  resource_type = options[:resource_type] || "image"
54
131
  uri = "resources/#{resource_type}/context"
55
- params = only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction,:key,:value)
132
+ params = only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction, :key, :value, :metadata)
56
133
  params[:key] = key
57
134
  params[:value] = value
58
135
  call_api(:get, uri, params, options)
59
136
  end
60
137
 
138
+ # Returns the details of the specified asset and all its derived assets by asset id.
139
+ #
140
+ # Note that if you only need details about the original asset,
141
+ # you can also use the Uploader::upload or Uploader::explicit methods, which return the same information and
142
+ # are not rate limited.
143
+ #
144
+ # @param [String] asset_id The Asset ID of the asset.
145
+ # @param [Hash] options The optional parameters. See the <a href=https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource target="_blank"> Admin API</a> documentation.
146
+ #
147
+ # @return [Cloudinary::Api::Response]
148
+ #
149
+ # @see https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource
150
+ def self.resource_by_asset_id(asset_id, options={})
151
+ uri = "resources/#{asset_id}"
152
+ params = prepare_resource_details_params(options)
153
+ call_api(:get, uri, params, options)
154
+ end
155
+
156
+ # Lists assets with the specified public IDs.
157
+ #
158
+ # @param [String|Array] public_ids The requested public_ids (up to 100).
159
+ # @param [Hash] options The optional parameters. See the
160
+ # {https://cloudinary.com/documentation/admin_api#get_resources Admin API} documentation.
161
+ #
162
+ # @return [Cloudinary::Api::Response]
163
+ #
164
+ # @raise [Cloudinary::Api::Error]
165
+ #
166
+ # @see https://cloudinary.com/documentation/admin_api#get_resources
61
167
  def self.resources_by_ids(public_ids, options={})
62
168
  resource_type = options[:resource_type] || "image"
63
169
  type = options[:type] || "upload"
@@ -65,28 +171,58 @@ class Cloudinary::Api
65
171
  call_api(:get, uri, only(options, :tags, :context, :moderations).merge(:public_ids => public_ids), options)
66
172
  end
67
173
 
174
+ # Lists assets with the specified asset IDs.
175
+ #
176
+ # @param [Object] asset_ids The requested asset IDs.
177
+ # @param [Hash] options The optional parameters. See the
178
+ # <a href=https://cloudinary.com/documentation/admin_api#get_resources target="_blank"> Admin API</a> documentation.
179
+ #
180
+ # @return [Cloudinary::Api::Response]
181
+ #
182
+ # @raise [Cloudinary::Api::Error]
183
+ #
184
+ # @see https://cloudinary.com/documentation/admin_api#get_resources
185
+ def self.resources_by_asset_ids(asset_ids, options={})
186
+ uri = "resources/by_asset_ids"
187
+ params = only(options, :public_ids, :tags, :moderations, :context)
188
+ params[:asset_ids] = asset_ids
189
+ call_api(:get, uri, params, options)
190
+ end
191
+
192
+ # Returns the details of the specified asset and all its derived assets.
193
+ #
194
+ # Note that if you only need details about the original asset,
195
+ # you can also use the Uploader::upload or Uploader::explicit methods, which return the same information and
196
+ # are not rate limited.
197
+ #
198
+ # @param [String] public_id The public ID of the asset.
199
+ # @param [Hash] options The optional parameters. See the
200
+ # {https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource Admin API} documentation.
201
+ #
202
+ # @return [Cloudinary::Api::Response]
203
+ #
204
+ # @raise [Cloudinary::Api::Error]
205
+ #
206
+ # @see https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource
68
207
  def self.resource(public_id, options={})
69
208
  resource_type = options[:resource_type] || "image"
70
209
  type = options[:type] || "upload"
71
210
  uri = "resources/#{resource_type}/#{type}/#{public_id}"
72
- call_api(:get, uri,
73
- only(options,
74
- :cinemagraph_analysis,
75
- :colors,
76
- :coordinates,
77
- :exif,
78
- :faces,
79
- :image_metadata,
80
- :max_results,
81
- :pages,
82
- :phash,
83
- :quality_analysis,
84
- :derived_next_cursor,
85
- :accessibility_analysis,
86
- :versions
87
- ), options)
211
+ call_api(:get, uri, prepare_resource_details_params(options), options)
88
212
  end
89
213
 
214
+ # Reverts to the latest backed up version of the specified deleted assets.
215
+ #
216
+ # @param [String|Array] public_ids The public IDs of the backed up assets to restore. They can be existing or
217
+ # deleted assets.
218
+ # @param [Hash] options The optional parameters. See the
219
+ # {https://cloudinary.com/documentation/admin_api#restore_resources Admin API} documentation.
220
+ #
221
+ # @return [Cloudinary::Api::Response]
222
+ #
223
+ # @raise [Cloudinary::Api::Error]
224
+ #
225
+ # @see https://cloudinary.com/documentation/admin_api#restore_resources
90
226
  def self.restore(public_ids, options={})
91
227
  resource_type = options[:resource_type] || "image"
92
228
  type = options[:type] || "upload"
@@ -94,6 +230,20 @@ class Cloudinary::Api
94
230
  call_api(:post, uri, { :public_ids => public_ids, :versions => options[:versions] }, options)
95
231
  end
96
232
 
233
+ # Updates details of an existing asset.
234
+ #
235
+ # Update one or more of the attributes associated with a specified asset. Note that you can also update
236
+ # most attributes of an existing asset using the Uploader::explicit method, which is not rate limited.
237
+ #
238
+ # @param [String|Array] public_id The public ID of the asset to update.
239
+ # @param [Hash] options The optional parameters. See the
240
+ # {https://cloudinary.com/documentation/admin_api#update_details_of_an_existing_resource Admin API} documentation.
241
+ #
242
+ # @return [Cloudinary::Api::Response]
243
+ #
244
+ # @raise [Cloudinary::Api::Error]
245
+ #
246
+ # @see https://cloudinary.com/documentation/admin_api#update_details_of_an_existing_resource
97
247
  def self.update(public_id, options={})
98
248
  resource_type = options[:resource_type] || "image"
99
249
  type = options[:type] || "upload"
@@ -118,6 +268,17 @@ class Cloudinary::Api
118
268
  call_api(:post, uri, update_options, options)
119
269
  end
120
270
 
271
+ # Deletes the specified assets.
272
+ #
273
+ # @param [String|Array] public_ids The public IDs of the assets to delete (up to 100).
274
+ # @param [Hash] options The optional parameters. See the
275
+ # {https://cloudinary.com/documentation/admin_api#sdelete_resources Admin API} documentation.
276
+ #
277
+ # @return [Cloudinary::Api::Response]
278
+ #
279
+ # @raise [Cloudinary::Api::Error]
280
+ #
281
+ # @see https://cloudinary.com/documentation/admin_api#delete_resources
121
282
  def self.delete_resources(public_ids, options={})
122
283
  resource_type = options[:resource_type] || "image"
123
284
  type = options[:type] || "upload"
@@ -125,6 +286,20 @@ class Cloudinary::Api
125
286
  call_api(:delete, uri, delete_resource_params(options, :public_ids => public_ids ), options)
126
287
  end
127
288
 
289
+ # Deletes assets by prefix.
290
+ #
291
+ # Delete up to 1000 original assets, along with their derived assets, where the public ID starts with the
292
+ # specified prefix.
293
+ #
294
+ # @param [String] prefix The Public ID prefix.
295
+ # @param [Hash] options The optional parameters. See the
296
+ # {https://cloudinary.com/documentation/admin_api#delete_resources Admin API} documentation.
297
+ #
298
+ # @return [Cloudinary::Api::Response]
299
+ #
300
+ # @raise [Cloudinary::Api::Error]
301
+ #
302
+ # @see https://cloudinary.com/documentation/admin_api#delete_resources
128
303
  def self.delete_resources_by_prefix(prefix, options={})
129
304
  resource_type = options[:resource_type] || "image"
130
305
  type = options[:type] || "upload"
@@ -132,6 +307,18 @@ class Cloudinary::Api
132
307
  call_api(:delete, uri, delete_resource_params(options, :prefix => prefix), options)
133
308
  end
134
309
 
310
+ # Deletes all assets of the specified asset and delivery type, including their derived assets.
311
+ #
312
+ # Supports deleting up to a maximum of 1000 original assets in a single call.
313
+ #
314
+ # @param [Hash] options The optional parameters. See the
315
+ # {https://cloudinary.com/documentation/admin_api#delete_resources Admin API} documentation.
316
+ #
317
+ # @return [Cloudinary::Api::Response]
318
+ #
319
+ # @raise [Cloudinary::Api::Error]
320
+ #
321
+ # https://cloudinary.com/documentation/admin_api#delete_resources
135
322
  def self.delete_all_resources(options={})
136
323
  resource_type = options[:resource_type] || "image"
137
324
  type = options[:type] || "upload"
@@ -139,23 +326,53 @@ class Cloudinary::Api
139
326
  call_api(:delete, uri, delete_resource_params(options, :all => true ), options)
140
327
  end
141
328
 
329
+ # Deletes assets with the specified tag, including their derived assets.
330
+ #
331
+ # Supports deleting up to a maximum of 1000 original assets in a single call.
332
+ #
333
+ # @param [String] tag The tag value of the assets to delete.
334
+ # @param [Hash] options The optional parameters. See the
335
+ # {https://cloudinary.com/documentation/admin_api#delete_resources_by_tags Admin API} documentation.
336
+ #
337
+ # @return [Cloudinary::Api::Response]
338
+ #
339
+ # @raise [Cloudinary::Api::Error]
340
+ #
341
+ # @see https://cloudinary.com/documentation/admin_api#delete_resources_by_tags
142
342
  def self.delete_resources_by_tag(tag, options={})
143
343
  resource_type = options[:resource_type] || "image"
144
344
  uri = "resources/#{resource_type}/tags/#{tag}"
145
345
  call_api(:delete, uri, delete_resource_params(options), options)
146
346
  end
147
347
 
348
+ # Deletes the specified derived assets by derived asset ID.
349
+ #
350
+ # The derived asset IDs for a particular original asset are returned when calling the {.resource} method to
351
+ # return the details of a single asset.
352
+ #
353
+ # @param [String|Array] derived_resource_ids The derived asset IDs (up to 100 ids).
354
+ # @param [Hash] options The optional parameters.
355
+ #
356
+ # @return [Cloudinary::Api::Response]
357
+ #
358
+ # @raise [Cloudinary::Api::Error]
359
+ #
360
+ # @see https://cloudinary.com/documentation/admin_api##delete_resources
148
361
  def self.delete_derived_resources(derived_resource_ids, options={})
149
362
  uri = "derived_resources"
150
363
  call_api(:delete, uri, { :derived_resource_ids => derived_resource_ids }, options)
151
364
  end
152
365
 
153
- # Delete derived resources identified by transformation for the provided public_ids
154
- # @param [String|Array] public_ids The resources the derived resources belong to
155
- # @param [String|Hash|Array] transformations the transformation(s) associated with the derived resources
156
- # @param [Hash] options
157
- # @option options [String] :resource_type ("image")
158
- # @option options [String] :type ("upload")
366
+ # Deletes derived assets identified by transformation and public_ids.
367
+ #
368
+ # @param [String|Array] public_ids The public IDs for which you want to delete derived assets.
369
+ # @param [String|Array|Hash] transformations The transformation(s) associated with the derived assets to delete.
370
+ # @param [Hash] options The optional parameters. See the
371
+ # {https://cloudinary.com/documentation/admin_api#resources Admin API} documentation.
372
+ #
373
+ # @return [Cloudinary::Api::Response]
374
+ #
375
+ # @raise [Cloudinary::Api::Error]
159
376
  def self.delete_derived_by_transformation(public_ids, transformations, options={})
160
377
  resource_type = options[:resource_type] || "image"
161
378
  type = options[:type] || "upload"
@@ -166,124 +383,413 @@ class Cloudinary::Api
166
383
  call_api(:delete, uri, params, options)
167
384
  end
168
385
 
386
+ # Lists all the tags currently used for a specified asset type.
387
+ #
388
+ # @param [Hash] options The optional parameters. See the
389
+ # {https://cloudinary.com/documentation/admin_api#get_tags Admin API} documentation.
390
+ #
391
+ # @return [Cloudinary::Api::Response]
392
+ #
393
+ # @raise [Cloudinary::Api::Error]
394
+ #
395
+ # @see https://cloudinary.com/documentation/admin_api#get_tags
169
396
  def self.tags(options={})
170
397
  resource_type = options[:resource_type] || "image"
171
398
  uri = "tags/#{resource_type}"
172
399
  call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix), options)
173
400
  end
174
401
 
402
+ # Lists stored transformations.
403
+ #
404
+ # @param [Hash] options The optional parameters. See the
405
+ # {https://cloudinary.com/documentation/admin_api#get_transformations Admin API} documentation.
406
+ #
407
+ # @return [Cloudinary::Api::Response]
408
+ #
409
+ # @raise [Cloudinary::Api::Error]
410
+ #
411
+ # @see https://cloudinary.com/documentation/admin_api#get_transformations
175
412
  def self.transformations(options={})
176
413
  call_api(:get, "transformations", only(options, :named, :next_cursor, :max_results), options)
177
414
  end
178
415
 
416
+ # Returns the details of a single transformation.
417
+ #
418
+ # @param [String|Array] transformation The transformation. Can be either a string or an array of parameters.
419
+ # For example: "w_150,h_100,c_fill" or array("width" => 150, "height" =>
420
+ # 100,"crop" => "fill").
421
+ # @param [Hash] options The optional parameters. See the
422
+ # {https://cloudinary.com/documentation/admin_api#get_transformation_details Admin API} documentation.
423
+ #
424
+ # @return [Cloudinary::Api::Response]
425
+ #
426
+ # @raise [Cloudinary::Api::Error]
427
+ #
428
+ # @see https://cloudinary.com/documentation/admin_api#get_transformation_details
179
429
  def self.transformation(transformation, options={})
180
- call_api(:get, "transformations/#{transformation_string(transformation)}", only(options, :next_cursor, :max_results), options)
430
+ params = only(options, :next_cursor, :max_results)
431
+ params[:transformation] = Cloudinary::Utils.build_eager(transformation)
432
+ call_api(:get, "transformations", params, options)
181
433
  end
182
434
 
435
+ # Deletes the specified stored transformation.
436
+ #
437
+ # Deleting a transformation also deletes all the stored derived assets based on this transformation (up to 1000).
438
+ # The method returns an error if there are more than 1000 derived assets based on this transformation.
439
+ #
440
+ # @param [String|Hash] transformation The transformation to delete. Can be either a string or an array of
441
+ # parameters. For example:
442
+ # "w_150,h_100,c_fill" or !{"width" => 150, "height" => 100,"crop" => "fill"}.
443
+ # @param [Hash] options The optional parameters. See the
444
+ # {https://cloudinary.com/documentation/admin_api#delete_transformation Admin API} documentation.
445
+ #
446
+ # @return [Cloudinary::Api::Response]
447
+ #
448
+ # @raise [Cloudinary::Api::Error]
449
+ #
450
+ # @see https://cloudinary.com/documentation/admin_api#delete_transformation
183
451
  def self.delete_transformation(transformation, options={})
184
- call_api(:delete, "transformations/#{transformation_string(transformation)}", {}, options)
452
+ call_api(:delete, "transformations", {:transformation => Cloudinary::Utils.build_eager(transformation)}, options)
185
453
  end
186
454
 
187
- # updates - supports:
188
- # "allowed_for_strict" boolean
189
- # "unsafe_update" transformation params - updates a named transformation parameters without regenerating existing images
455
+ # Updates the specified transformation.
456
+ #
457
+ # @param [String|Hash] transformation The transformation. Can be either a string or an array of parameters.
458
+ # For example: "w_150,h_100,c_fill" or !{"width" => 150, "height" =>
459
+ # 100,"crop" => "fill"}.
460
+ # @param [Hash] updates The update parameters. See the
461
+ # {https://cloudinary.com/documentation/admin_api#update_transformation Admin API} documentation.
462
+ # @param [Hash] options The optional parameters.
463
+ #
464
+ # @return [Cloudinary::Api::Response]
465
+ #
466
+ # @raise [Cloudinary::Api::Error]
467
+ #
468
+ # @see https://cloudinary.com/documentation/admin_api#update_transformation
190
469
  def self.update_transformation(transformation, updates, options={})
191
- params = only(updates, :allowed_for_strict)
192
- params[:unsafe_update] = transformation_string(updates[:unsafe_update]) if updates[:unsafe_update]
193
- call_api(:put, "transformations/#{transformation_string(transformation)}", params, options)
470
+ params = only(updates, :allowed_for_strict)
471
+ params[:unsafe_update] = Cloudinary::Utils.build_eager(updates[:unsafe_update]) if updates[:unsafe_update]
472
+ params[:transformation] = Cloudinary::Utils.build_eager(transformation)
473
+ call_api(:put, "transformations", params, options)
194
474
  end
195
475
 
476
+ # Creates a named transformation.
477
+ #
478
+ # @param [String] name The name of the transformation.
479
+ # @param [String|Hash] definition The transformation. Can be a string or a hash. For example:
480
+ # "w_150,h_100,c_fill" or !{"width" => 150, "height" => 100, "crop" => "fill"}.
481
+ # @param [Hash] options The optional parameters.
482
+ #
483
+ # @return [Cloudinary::Api::Response]
484
+ #
485
+ # @raise [Cloudinary::Api::Error]
486
+ #
487
+ # @see https://cloudinary.com/documentation/admin_api#create_named_transformation
196
488
  def self.create_transformation(name, definition, options={})
197
- call_api(:post, "transformations/#{name}", { :transformation => transformation_string(definition) }, options)
489
+ params = {
490
+ :name => name,
491
+ :transformation => Cloudinary::Utils.build_eager(definition)
492
+ }
493
+
494
+ call_api(:post, "transformations", params, options)
198
495
  end
199
496
 
200
- # upload presets
497
+ # Lists existing upload presets.
498
+ #
499
+ # @param [Hash] options The optional parameters. See the
500
+ # {https://cloudinary.com/documentation/admin_api#get_upload_presets Admin API} documentation.
501
+ #
502
+ # @return [Cloudinary::Api::Response]
503
+ #
504
+ # @raise [Cloudinary::Api::Error]
505
+ #
506
+ # @see https://cloudinary.com/documentation/admin_api#get_upload_presets
201
507
  def self.upload_presets(options={})
202
508
  call_api(:get, "upload_presets", only(options, :next_cursor, :max_results), options)
203
509
  end
204
510
 
511
+ # Retrieves the details of the specified upload preset.
512
+ #
513
+ # @param [String] name The name of the upload preset.
514
+ # @param [Hash] options The optional parameters. See the
515
+ # {https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_upload_preset Admin API}
516
+ # documentation.
517
+ #
518
+ # @return [Cloudinary::Api::Response]
519
+ #
520
+ # @raise [Cloudinary::Api::Error]
521
+ #
522
+ # @see https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_upload_preset
205
523
  def self.upload_preset(name, options={})
206
524
  call_api(:get, "upload_presets/#{name}", only(options, :max_results), options)
207
525
  end
208
526
 
527
+ # Deletes the specified upload preset.
528
+ #
529
+ # @param [String] The name of the upload preset to delete.
530
+ # @param [Hash] options The optional parameters.
531
+ #
532
+ # @return [Cloudinary::Api::Response]
533
+ #
534
+ # @raise [Cloudinary::Api::Error]
535
+ #
536
+ # @see https://cloudinary.com/documentation/admin_api#delete_an_upload_preset
209
537
  def self.delete_upload_preset(name, options={})
210
538
  call_api(:delete, "upload_presets/#{name}", {}, options)
211
539
  end
212
540
 
541
+ # Updates the specified upload preset.
542
+ #
543
+ # @param [String] name The name of the upload preset.
544
+ # @param [Hash] options The optional parameters. See the
545
+ # {https://cloudinary.com/documentation/admin_api#update_an_upload_preset Admin API} documentation.
546
+ #
547
+ # @return [Cloudinary::Api::Response]
548
+ #
549
+ # @raise [Cloudinary::Api::Error]
550
+ #
551
+ # @see https://cloudinary.com/documentation/admin_api#update_an_upload_preset
213
552
  def self.update_upload_preset(name, options={})
214
553
  params = Cloudinary::Uploader.build_upload_params(options)
215
- call_api(:put, "upload_presets/#{name}", params.merge(only(options, :unsigned, :disallow_public_id)), options)
554
+ call_api(:put, "upload_presets/#{name}", params.merge(only(options, :unsigned, :disallow_public_id, :live)), options)
216
555
  end
217
556
 
557
+ # Creates a new upload preset.
558
+ #
559
+ # @param [Hash] options The optional parameters. See the
560
+ # {https://cloudinary.com/documentation/admin_api#create_an_upload_preset Admin API} documentation.
561
+ #
562
+ # @return [Cloudinary::Api::Response]
563
+ #
564
+ # @raise [Cloudinary::Api::Error]
565
+ #
566
+ # @see https://cloudinary.com/documentation/admin_api#create_an_upload_preset
218
567
  def self.create_upload_preset(options={})
219
568
  params = Cloudinary::Uploader.build_upload_params(options)
220
- call_api(:post, "upload_presets", params.merge(only(options, :name, :unsigned, :disallow_public_id)), options)
569
+ call_api(:post, "upload_presets", params.merge(only(options, :name, :unsigned, :disallow_public_id, :live)), options)
221
570
  end
222
571
 
572
+ # Lists all root folders.
573
+ #
574
+ # @param [Hash] options The optional parameters. See the
575
+ # {https://cloudinary.com/documentation/admin_api#get_root_folders Admin API} documentation.
576
+ #
577
+ # @return [Cloudinary::Api::Response]
578
+ #
579
+ # @raise [Cloudinary::Api::Error]
580
+ #
581
+ # @see https://cloudinary.com/documentation/admin_api#get_root_folders
223
582
  def self.root_folders(options={})
224
583
  params = only(options, :max_results, :next_cursor)
225
584
  call_api(:get, "folders", params, options)
226
585
  end
227
586
 
587
+ # Lists sub-folders.
588
+ #
589
+ # Returns the name and path of all the sub-folders of a specified parent folder. Limited to 2000 results.
590
+ #
591
+ # @param [String] of_folder_path The parent folder.
592
+ # @param [Hash] options The optional parameters. See the
593
+ # {https://cloudinary.com/documentation/admin_api#get_subfolders Admin API} documentation.
594
+ #
595
+ # @return [Cloudinary::Api::Response]
596
+ #
597
+ # @raise [Cloudinary::Api::Error]
598
+ #
599
+ # @see https://cloudinary.com/documentation/admin_api#get_subfolders
228
600
  def self.subfolders(of_folder_path, options={})
229
601
  params = only(options, :max_results, :next_cursor)
230
602
  call_api(:get, "folders/#{of_folder_path}", params, options)
231
603
  end
232
604
 
605
+ # Deletes an empty folder.
606
+ #
607
+ # The specified folder cannot contain any assets, but can have empty descendant sub-folders.
608
+ #
609
+ # @param [String] path The full path of the empty folder to delete.
610
+ # @param [Hash] options The optional parameters.
611
+ #
612
+ # @return [Cloudinary::Api::Response]
613
+ #
614
+ # @raise [Cloudinary::Api::Error]
615
+ #
616
+ # @see https://cloudinary.com/documentation/admin_api#delete_folder
233
617
  def self.delete_folder(path, options={})
234
618
  call_api(:delete, "folders/#{path}", {}, options)
235
619
  end
236
620
 
621
+ # Creates a new empty folder.
622
+ #
623
+ # @param [String] folder_name The full path of the new folder to create.
624
+ # @param [Hash] options The optional parameters.
625
+ #
626
+ # @return [Cloudinary::Api::Response]
627
+ #
628
+ # @raise [Cloudinary::Api::Error]
629
+ #
630
+ # @see https://cloudinary.com/documentation/admin_api#create_folder
237
631
  def self.create_folder(folder_name, options={})
238
632
  call_api(:post, "folders/#{folder_name}", {}, options)
239
633
  end
240
634
 
635
+ # Lists upload mappings by folder and its mapped template (URL).
636
+ #
637
+ # @param [Hash] options The optional parameters. See the
638
+ # {https://cloudinary.com/documentation/admin_api#get_upload_mapping Admin API} documentation.
639
+ #
640
+ # @return [Cloudinary::Api::Response]
641
+ #
642
+ # @raise [Cloudinary::Api::Error]
643
+ #
644
+ # @see https://cloudinary.com/documentation/admin_api#get_upload_mappings
241
645
  def self.upload_mappings(options={})
242
646
  params = only(options, :next_cursor, :max_results)
243
647
  call_api(:get, :upload_mappings, params, options)
244
648
  end
245
649
 
650
+ # Returns the details of the specified upload mapping.
651
+ #
652
+ # Retrieve the mapped template (URL) of a specified upload mapping folder.
653
+ #
654
+ # @param [String] name The name of the upload mapping folder.
655
+ # @param [Hash] options The optional parameters.
656
+ #
657
+ # @return [Cloudinary::Api::Response]
658
+ #
659
+ # @raise [Cloudinary::Api::Error]
660
+ #
661
+ # @see https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_upload_mapping
246
662
  def self.upload_mapping(name=nil, options={})
247
663
  call_api(:get, 'upload_mappings', { :folder => name }, options)
248
664
  end
249
665
 
666
+ # Deletes an upload mapping.
667
+ #
668
+ # @param [String] name The name of the upload mapping folder to delete.
669
+ # @param [Hash] options The optional parameters.
670
+ #
671
+ # @return [Cloudinary::Api::Response]
672
+ #
673
+ # @raise [Cloudinary::Api::Error]
674
+ #
675
+ # @see https://cloudinary.com/documentation/admin_api#delete_an_upload_mapping
250
676
  def self.delete_upload_mapping(name, options={})
251
677
  call_api(:delete, 'upload_mappings', { :folder => name }, options)
252
678
  end
253
679
 
680
+ # Updates an existing upload mapping with a new template (URL).
681
+ #
682
+ # @param [String] name The name of the upload mapping folder to remap.
683
+ # @param [Hash] options The optional parameters. See the
684
+ # {https://cloudinary.com/documentation/admin_api#update_an_upload_mapping Admin API} documentation.
685
+ #
686
+ # @return [Cloudinary::Api::Response]
687
+ #
688
+ # @raise [Cloudinary::Api::Error]
689
+ #
690
+ # @see https://cloudinary.com/documentation/admin_api#update_an_upload_mapping
254
691
  def self.update_upload_mapping(name, options={})
255
692
  params = only(options, :template)
256
693
  params[:folder] = name
257
694
  call_api(:put, 'upload_mappings', params, options)
258
695
  end
259
696
 
697
+ # Creates a new upload mapping.
698
+ #
699
+ # @param [String] name The name of the folder to map.
700
+ # @param [Hash] options The optional parameters. See the
701
+ # {https://cloudinary.com/documentation/admin_api#create_an_upload_mapping Admin API} documentation.
702
+ #
703
+ # @return [Cloudinary::Api::Response]
704
+ #
705
+ # @raise [Cloudinary::Api::Error]
706
+ #
707
+ # @see https://cloudinary.com/documentation/admin_api#create_an_upload_mapping
260
708
  def self.create_upload_mapping(name, options={})
261
709
  params = only(options, :template)
262
710
  params[:folder] = name
263
711
  call_api(:post, 'upload_mappings', params, options)
264
712
  end
265
713
 
714
+ # Creates a new, custom streaming profile.
715
+ #
716
+ # @param [String] name The name to assign to the new streaming profile.
717
+ # The name is case-insensitive and can contain alphanumeric characters, underscores (_) and
718
+ # hyphens (-). If the name is of a predefined profile, the profile will be modified.
719
+ # @param [Hash] options The optional parameters. See the
720
+ # {https://cloudinary.com/documentation/admin_api#create_a_streaming_profile Admin API} documentation.
721
+ #
722
+ # @return [Cloudinary::Api::Response]
723
+ #
724
+ # @raise [Cloudinary::Api::Error]
725
+ #
726
+ # @see https://cloudinary.com/documentation/admin_api#create_a_streaming_profile
266
727
  def self.create_streaming_profile(name, options={})
267
- params = only(options, :display_name, :representations)
268
- params[:representations] = params[:representations].map do |r|
269
- {:transformation => Cloudinary::Utils.generate_transformation_string(r[:transformation])}
270
- end.to_json
271
- params[:name] = name
272
- call_api(:post, 'streaming_profiles', params, options)
728
+ params = only(options, :display_name, :representations)
729
+ params[:representations] = params[:representations].map do |r|
730
+ {:transformation => Cloudinary::Utils.generate_transformation_string(r[:transformation])}
731
+ end.to_json
732
+ params[:name] = name
733
+ call_api(:post, 'streaming_profiles', params, options)
273
734
  end
274
735
 
736
+ # Lists streaming profiles including built-in and custom profiles.
737
+ #
738
+ # @return [Cloudinary::Api::Response]
739
+ #
740
+ # @raise [Cloudinary::Api::Error]
741
+ #
742
+ # @see https://cloudinary.com/documentation/admin_api#get_adaptive_streaming_profiles
275
743
  def self.list_streaming_profiles
276
744
  call_api(:get, 'streaming_profiles', {}, {})
277
745
  end
278
746
 
747
+ # Deletes or reverts the specified streaming profile.
748
+ #
749
+ # For custom streaming profiles, deletes the specified profile.
750
+ # For built-in streaming profiles, if the built-in profile was modified, reverts the profile to the original
751
+ # settings.
752
+ # For built-in streaming profiles that have not been modified, the Delete method returns an error.
753
+ #
754
+ # @param [String] name The name of the streaming profile to delete or revert.
755
+ # @param [Hash] options The optional parameters.
756
+ #
757
+ # @return [Cloudinary::Api::Response]
758
+ #
759
+ # @raise [Cloudinary::Api::Error]
760
+ #
761
+ # @see https://cloudinary.com/documentation/admin_api#delete_or_revert_the_specified_streaming_profile
279
762
  def self.delete_streaming_profile(name, options={})
280
763
  call_api(:delete, "streaming_profiles/#{name}", {}, options)
281
764
  end
282
765
 
766
+ # Gets details of a single streaming profile by name.
767
+ #
768
+ # @param [String] name The identification name of the streaming profile.
769
+ # @param [Hash] options The optional parameters.
770
+ #
771
+ # @return [Cloudinary::Api::Response]
772
+ #
773
+ # @raise [Cloudinary::Api::Error]
774
+ #
775
+ # @see https://cloudinary.com/documentation/admin_api#get_details_of_a_single_streaming_profile
283
776
  def self.get_streaming_profile(name, options={})
284
777
  call_api(:get, "streaming_profiles/#{name}", {}, options)
285
778
  end
286
779
 
780
+ # Updates an existing streaming profile.
781
+ #
782
+ # You can update both custom and built-in profiles. The specified list of representations replaces the previous list.
783
+ #
784
+ # @param [String] name The name of the streaming profile to update.
785
+ # @param [Hash] options The optional parameters. See the
786
+ # {https://cloudinary.com/documentation/admin_api#create_a_streaming_profile Admin API} documentation.
787
+ #
788
+ # @return [Cloudinary::Api::Response]
789
+ #
790
+ # @raise [Cloudinary::Api::Error]
791
+ #
792
+ # @see https://cloudinary.com/documentation/admin_api#create_a_streaming_profile
287
793
  def self.update_streaming_profile(name, options={})
288
794
  params = only(options, :display_name, :representations)
289
795
  params[:representations] = params[:representations].map do |r|
@@ -292,73 +798,98 @@ class Cloudinary::Api
292
798
  call_api(:put, "streaming_profiles/#{name}", params, options)
293
799
  end
294
800
 
295
- # Update resources access mode. Resources are selected by the prefix
296
- # @param [String] access_mode the access mode to set the resources to
297
- # @param [String] prefix The prefix by which to filter applicable resources
298
- # @param [Object] options additional options
299
- # @option options [String] :resource_type ("image") the type of resources to modify
300
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
301
- # @option options [String] :next_cursor (nil) provided by a previous call to the method
801
+ # Update resources access mode. Resources are selected by the prefix.
802
+ #
803
+ # @param [String] access_mode The access mode to set the resources to.
804
+ # @param [String] prefix The prefix by which to filter applicable resources
805
+ # @param [Hash] options The optional parameters.
806
+ #
807
+ # @return [Cloudinary::Api::Response]
808
+ #
809
+ # @raise [Cloudinary::Api::Error]
810
+ #
811
+ # @see https://cloudinary.com/documentation/admin_api#examples-8
302
812
  def self.update_resources_access_mode_by_prefix(access_mode, prefix, options = {})
303
-
304
- update_resources_access_mode(access_mode, :prefix, prefix, options)
813
+ update_resources_access_mode(access_mode, :prefix, prefix, options)
305
814
  end
306
815
 
307
- # Update resources access mode. Resources are selected by the tag
308
- # @param [String] access_mode the access mode to set the resources to
309
- # @param [String] tag the tag by which to filter applicable resources
310
- # @param [Object] options additional options
311
- # @option options [String] :resource_type ("image") the type of resources to modify
312
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
313
- # @option options [String] :next_cursor (nil) provided by a previous call to the method
816
+ # Update resources access mode. Resources are selected by the tag.
817
+ #
818
+ # @param [String] access_mode The access mode to set the resources to.
819
+ # @param [String] tag The tag by which to filter applicable resources.
820
+ # @param [Hash] options The optional parameters.
821
+ #
822
+ # @return [Cloudinary::Api::Response]
823
+ #
824
+ # @raise [Cloudinary::Api::Error]
825
+ #
826
+ # @see https://cloudinary.com/documentation/admin_api#examples-8
314
827
  def self.update_resources_access_mode_by_tag(access_mode, tag, options = {})
315
-
316
- update_resources_access_mode(access_mode, :tag, tag, options)
828
+ update_resources_access_mode(access_mode, :tag, tag, options)
317
829
  end
318
830
 
319
- # Update resources access mode. Resources are selected by the provided public_ids
320
- # @param [String] access_mode the access mode to set the resources to
321
- # @param [Array<String>] public_ids The prefix by which to filter applicable resources
322
- # @param [Object] options additional options
323
- # @option options [String] :resource_type ("image") the type of resources to modify
324
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
325
- # @option options [String] :next_cursor (nil) provided by a previous call to the method
831
+ # Update resources access mode. Resources are selected by the provided public_ids.
832
+ #
833
+ # @param [String] access_mode The access mode to set the resources to.
834
+ # @param [Array] public_ids The ids by which to filter applicable resources
835
+ # @param [Hash] options The optional parameters.
836
+ #
837
+ # @return [Cloudinary::Api::Response]
838
+ #
839
+ # @raise [Cloudinary::Api::Error]
840
+ #
841
+ # @see https://cloudinary.com/documentation/admin_api#examples-8
326
842
  def self.update_resources_access_mode_by_ids(access_mode, public_ids, options = {})
327
-
328
- update_resources_access_mode(access_mode, :public_ids, public_ids, options)
843
+ update_resources_access_mode(access_mode, :public_ids, public_ids, options)
329
844
  end
330
845
 
846
+ # Gets the breakpoints.
847
+ #
848
+ # Returns breakpoints if defined, otherwise checks the cache(if configured), otherwise fall backs to static
849
+ # calculation.
850
+ #
851
+ # @param [String] public_id Resource source.
852
+ # @param [Hash] options The optional parameters.
853
+ #
854
+ # @return [Cloudinary::Api::Response]
855
+ #
856
+ # @raise [Cloudinary::Api::Error]
857
+ #
858
+ # @internal
331
859
  def self.get_breakpoints(public_id, options)
332
860
  local_options = options.clone
333
861
  base_transformation = Cloudinary::Utils.generate_transformation_string(local_options)
334
862
  srcset = local_options[:srcset]
335
863
  breakpoints = [:min_width, :max_width, :bytes_step, :max_images].map {|k| srcset[k]}.join('_')
336
864
 
337
-
338
865
  local_options[:transformation] = [base_transformation, width: "auto:breakpoints_#{breakpoints}:json"]
339
866
  json_url = Cloudinary::Utils.cloudinary_url public_id, local_options
340
867
  call_json_api('GET', json_url, {}, 60, {})
341
868
  end
342
869
 
343
- # Returns a list of all metadata field definitions.
870
+ # Lists all metadata field definitions.
344
871
  #
345
- # @see https://cloudinary.com/documentation/admin_api#get_metadata_fields Get metadata fields API reference
872
+ # @param [Hash] options The optional parameters.
346
873
  #
347
- # @param [Hash] options Additional options
348
874
  # @return [Cloudinary::Api::Response]
875
+ #
349
876
  # @raise [Cloudinary::Api::Error]
877
+ #
878
+ # @see https://cloudinary.com/documentation/admin_api#get_metadata_fields
350
879
  def self.list_metadata_fields(options = {})
351
880
  call_metadata_api(:get, [], {}, options)
352
881
  end
353
882
 
354
- # Gets a metadata field by external id.
883
+ # Gets a single metadata field definition by external ID.
355
884
  #
356
- # @see https://cloudinary.com/documentation/admin_api#get_a_metadata_field_by_external_id Get metadata field by external ID API reference
885
+ # @param [String] field_external_id The external ID of the field to retrieve.
886
+ # @param [Hash] options The optional parameters.
357
887
  #
358
- # @param [String] field_external_id The ID of the metadata field to retrieve
359
- # @param [Hash] options Additional options
360
888
  # @return [Cloudinary::Api::Response]
889
+ #
361
890
  # @raise [Cloudinary::Api::Error]
891
+ #
892
+ # @see https://cloudinary.com/documentation/admin_api#get_a_metadata_field_by_external_id
362
893
  def self.metadata_field_by_field_id(field_external_id, options = {})
363
894
  uri = [field_external_id]
364
895
 
@@ -367,31 +898,33 @@ class Cloudinary::Api
367
898
 
368
899
  # Creates a new metadata field definition.
369
900
  #
370
- # @see https://cloudinary.com/documentation/admin_api#create_a_metadata_field Create metadata field API reference
901
+ # @param [Hash] field The field to add.
902
+ # @param [Hash] options The optional parameters.
371
903
  #
372
- # @param [Hash] field The field to add
373
- # @param [Hash] options Additional options
374
904
  # @return [Cloudinary::Api::Response]
905
+ #
375
906
  # @raise [Cloudinary::Api::Error]
907
+ #
908
+ # @see https://cloudinary.com/documentation/admin_api#create_a_metadata_field
376
909
  def self.add_metadata_field(field, options = {})
377
910
  params = only(field, :type, :external_id, :label, :mandatory, :default_value, :validation, :datasource)
378
911
 
379
912
  call_metadata_api(:post, [], params, options)
380
913
  end
381
914
 
382
- # Updates a metadata field by external id.
915
+ # Updates a metadata field by external ID.
383
916
  #
384
917
  # Updates a metadata field definition (partially, no need to pass the entire object) passed as JSON data.
385
- # See https://cloudinary.com/documentation/admin_api#generic_structure_of_a_metadata_field for the generic structure
386
- # of a metadata field.
387
918
  #
388
- # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_by_external_id Update metadata field API reference
919
+ # @param [String] field_external_id The ID of the field to update.
920
+ # @param [Hash] field The field definition.
921
+ # @param [Hash] options The optional parameters.
389
922
  #
390
- # @param [String] field_external_id The id of the metadata field to update
391
- # @param [Hash] field The field definition
392
- # @param [Hash] options Additional options
393
923
  # @return [Cloudinary::Api::Response]
924
+ #
394
925
  # @raise [Cloudinary::Api::Error]
926
+ #
927
+ # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_by_external_id
395
928
  def self.update_metadata_field(field_external_id, field, options = {})
396
929
  uri = [field_external_id]
397
930
  params = only(field, :label, :mandatory, :default_value, :validation)
@@ -399,35 +932,40 @@ class Cloudinary::Api
399
932
  call_metadata_api(:put, uri, params, options)
400
933
  end
401
934
 
402
- # Deletes a metadata field definition.
935
+ # Deletes a metadata field definition by external ID.
403
936
  #
404
- # The field should no longer be considered a valid candidate for all other endpoints.
937
+ # The external ID is immutable. Therefore, once deleted, the field's external ID can no longer be used for
938
+ # future purposes.
405
939
  #
406
- # @see https://cloudinary.com/documentation/admin_api#delete_a_metadata_field_by_external_id Delete metadata field API reference
940
+ # @param [String] field_external_id The ID of the field to delete.
941
+ # @param [Hash] options The optional parameters.
942
+ #
943
+ # @return [Cloudinary::Api::Response]
407
944
  #
408
- # @param [String] field_external_id The external id of the field to delete
409
- # @param [Hash] options Additional options
410
- # @return [Cloudinary::Api::Response] A hash with a "message" key. "ok" value indicates a successful deletion
411
945
  # @raise [Cloudinary::Api::Error]
946
+ #
947
+ # @see https://cloudinary.com/documentation/admin_api#delete_a_metadata_field_by_external_id
412
948
  def self.delete_metadata_field(field_external_id, options = {})
413
949
  uri = [field_external_id]
414
950
 
415
951
  call_metadata_api(:delete, uri, {}, options)
416
952
  end
417
953
 
418
- # Deletes entries in a metadata field datasource.
954
+ # Deletes entries in a metadata single or multi-select field's datasource.
419
955
  #
420
- # Deletes (blocks) the datasource entries for a specified metadata field definition. Sets the state of the
421
- # entries to inactive. This is a soft delete, the entries still exist under the hood and can be activated
422
- # again with the restore datasource entries method.
956
+ # Deletes (blocks) the datasource (list) entries from the specified metadata field definition. Sets the state of
957
+ # the entries to inactive. This is a soft delete. The entries still exist in the database and can be reactivated
958
+ # using the restoreDatasourceEntries method.
423
959
  #
424
- # @see https://cloudinary.com/documentation/admin_api#delete_entries_in_a_metadata_field_datasource Delete entries in a metadata field datasource API reference
960
+ # @param [String] field_external_id The ID of the field to update.
961
+ # @param [Array] entries_external_id The IDs of the entries to delete from the data source.
962
+ # @param [Hash] options The optional parameters.
963
+ #
964
+ # @return [Cloudinary::Api::Response]
425
965
  #
426
- # @param [String] field_external_id The id of the field to update
427
- # @param [Array] entries_external_id The ids of all the entries to delete from the datasource
428
- # @param [Hash] options Additional options
429
- # @return [Cloudinary::Api::Response] The remaining datasource entries
430
966
  # @raise [Cloudinary::Api::Error]
967
+ #
968
+ # @see https://cloudinary.com/documentation/admin_api#delete_entries_in_a_metadata_field_datasource
431
969
  def self.delete_datasource_entries(field_external_id, entries_external_id, options = {})
432
970
  uri = [field_external_id, "datasource"]
433
971
  params = {:external_ids => entries_external_id }
@@ -437,17 +975,20 @@ class Cloudinary::Api
437
975
 
438
976
  # Updates a metadata field datasource.
439
977
  #
440
- # Updates the datasource of a supported field type (currently only enum and set), passed as JSON data. The
978
+ # Updates the datasource of a supported field type (currently enum or set), passed as JSON data. The
441
979
  # update is partial: datasource entries with an existing external_id will be updated and entries with new
442
980
  # external_id’s (or without external_id’s) will be appended.
443
981
  #
444
- # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_datasource Update a metadata field datasource API reference
982
+ # @param [String] field_external_id The ID of the field to update.
983
+ # @param [Array] entries_external_id A list of datasource entries. Existing entries (according to entry id) will be
984
+ # updated. New entries will be added.
985
+ # @param [Hash] options The optional parameters.
445
986
  #
446
- # @param [String] field_external_id The external id of the field to update
447
- # @param [Array] entries_external_id
448
- # @param [Hash] options Additional options
449
987
  # @return [Cloudinary::Api::Response]
988
+ #
450
989
  # @raise [Cloudinary::Api::Error]
990
+ #
991
+ # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_datasource
451
992
  def self.update_metadata_field_datasource(field_external_id, entries_external_id, options = {})
452
993
  uri = [field_external_id, "datasource"]
453
994
 
@@ -459,18 +1000,20 @@ class Cloudinary::Api
459
1000
  call_metadata_api(:put, uri, params, options)
460
1001
  end
461
1002
 
462
- # Restores entries in a metadata field datasource.
1003
+ # Restore entries in a metadata field datasource.
463
1004
  #
464
1005
  # Restores (unblocks) any previously deleted datasource entries for a specified metadata field definition.
465
1006
  # Sets the state of the entries to active.
466
1007
  #
467
- # @see https://cloudinary.com/documentation/admin_api#restore_entries_in_a_metadata_field_datasource Restore entries in a metadata field datasource API reference
1008
+ # @param [String] field_external_id The ID of the metadata field.
1009
+ # @param [Array] entries_external_ids An array of IDs of datasource entries to restore (unblock).
1010
+ # @param [Hash] options The optional parameters.
468
1011
  #
469
- # @param [String] field_external_id The ID of the metadata field
470
- # @param [Array] entries_external_ids An array of IDs of datasource entries to restore (unblock)
471
- # @param [Hash] options Additional options
472
1012
  # @return [Cloudinary::Api::Response]
1013
+ #
473
1014
  # @raise [Cloudinary::Api::Error]
1015
+ #
1016
+ # @see https://cloudinary.com/documentation/admin_api#restore_entries_in_a_metadata_field_datasource
474
1017
  def self.restore_metadata_field_datasource(field_external_id, entries_external_ids, options = {})
475
1018
  uri = [field_external_id, "datasource_restore"]
476
1019
  params = {:external_ids => entries_external_ids }
@@ -478,18 +1021,67 @@ class Cloudinary::Api
478
1021
  call_metadata_api(:post, uri, params, options)
479
1022
  end
480
1023
 
1024
+ # Reorders metadata field datasource. Currently supports only value.
1025
+ #
1026
+ # @param [String] field_external_id The ID of the metadata field
1027
+ # @param [String] order_by Criteria for the order. Currently supports only value
1028
+ # @param [String] direction Optional (gets either asc or desc)
1029
+ # @param [Hash] options Configuration options
1030
+ #
1031
+ # @return [Cloudinary::Api::Response]
1032
+ #
1033
+ # @raise [Cloudinary::Api::Error]
1034
+ def self.reorder_metadata_field_datasource(field_external_id, order_by, direction = nil, options = {})
1035
+ uri = [field_external_id, "datasource", "order"]
1036
+ params = { :order_by => order_by, :direction => direction }
1037
+
1038
+ call_metadata_api(:post, uri, params, options)
1039
+ end
1040
+
1041
+ # Reorders metadata fields.
1042
+ #
1043
+ # @param [String] order_by Criteria for the order (one of the fields 'label', 'external_id', 'created_at').
1044
+ # @param [String] direction Optional (gets either asc or desc).
1045
+ # @param [Hash] options Configuration options.
1046
+ #
1047
+ # @return [Cloudinary::Api::Response]
1048
+ #
1049
+ # @raise [Cloudinary::Api::Error]
1050
+ def self.reorder_metadata_fields(order_by, direction = nil, options = {})
1051
+ uri = ["order"]
1052
+ params = { :order_by => order_by, :direction => direction }
1053
+
1054
+ call_metadata_api(:put, uri, params, options)
1055
+ end
1056
+
481
1057
  protected
482
1058
 
1059
+ # Execute a call api for input params.
1060
+ # @param [Object] method The method for a request
1061
+ # @param [Object] uri The uri for a request
1062
+ # @param [Object] params Additional params
1063
+ # @param [Object] options Additional options
1064
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1065
+ # @raise [Cloudinary::Api::Error]
483
1066
  def self.call_api(method, uri, params, options)
484
- cloud_name = options[:cloud_name] || Cloudinary.config.cloud_name || raise('Must supply cloud_name')
485
- api_key = options[:api_key] || Cloudinary.config.api_key || raise('Must supply api_key')
486
- api_secret = options[:api_secret] || Cloudinary.config.api_secret || raise('Must supply api_secret')
1067
+ cloud_name = options[:cloud_name] || Cloudinary.config.cloud_name || raise('Must supply cloud_name')
1068
+ api_key = options[:api_key] || Cloudinary.config.api_key
1069
+ api_secret = options[:api_secret] || Cloudinary.config.api_secret
1070
+ oauth_token = options[:oauth_token] || Cloudinary.config.oauth_token
1071
+
1072
+ validate_authorization(api_key, api_secret, oauth_token)
1073
+
1074
+ auth = { :key => api_key, :secret => api_secret, :oauth_token => oauth_token }
487
1075
 
488
- call_cloudinary_api(method, uri, api_key, api_secret, params, options) do |cloudinary, inner_uri|
1076
+ call_cloudinary_api(method, uri, auth, params, options) do |cloudinary, inner_uri|
489
1077
  [cloudinary, 'v1_1', cloud_name, inner_uri]
490
1078
  end
491
1079
  end
492
1080
 
1081
+ # Parse a json response.
1082
+ # @param [Object] response Returned response from Cloudinary
1083
+ # @return [Hash] Decoded string
1084
+ # @raise [Cloudinary::Api::GeneralError]
493
1085
  def self.parse_json_response(response)
494
1086
  return Cloudinary::Utils.json_decode(response.body)
495
1087
  rescue => e
@@ -504,7 +1096,7 @@ class Cloudinary::Api
504
1096
  # @param [Array] uri REST endpoint of the API (without 'metadata_fields')
505
1097
  # @param [Hash] params Query/body parameters passed to the method
506
1098
  # @param [Hash] options Additional options. Can be an override of the configuration, headers, etc.
507
- # @return [Cloudinary::Api::Response]
1099
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
508
1100
  # @raise [Cloudinary::Api::Error]
509
1101
  def self.call_metadata_api(method, uri, params, options)
510
1102
  options[:content_type] = :json
@@ -513,6 +1105,31 @@ class Cloudinary::Api
513
1105
  call_api(method, uri, params, options)
514
1106
  end
515
1107
 
1108
+ # Prepares optional parameters for asset/assetByAssetId API calls.
1109
+ # @param [Hash] options Additional options
1110
+ # @return [Object] Optional parameters
1111
+ def self.prepare_resource_details_params(options)
1112
+ only(options,
1113
+ :exif,
1114
+ :colors,
1115
+ :faces,
1116
+ :quality_analysis,
1117
+ :image_metadata,
1118
+ :phash,
1119
+ :pages,
1120
+ :cinemagraph_analysis,
1121
+ :coordinates,
1122
+ :max_results,
1123
+ :derived_next_cursor,
1124
+ :accessibility_analysis,
1125
+ :versions
1126
+ )
1127
+ end
1128
+
1129
+ # Filter hash with specific keys.
1130
+ # @param [Object] hash Input hash
1131
+ # @param [Array] keys Input keys
1132
+ # @return [Hash] Result of hash filtering
516
1133
  def self.only(hash, *keys)
517
1134
  result = {}
518
1135
  keys.each do |key|
@@ -522,32 +1139,65 @@ class Cloudinary::Api
522
1139
  result
523
1140
  end
524
1141
 
1142
+ # Merge params with a certain set of options.
1143
+ # @param [Object] options Set of options
1144
+ # @param [Hash] params Additional params
1145
+ # @return [Hash] Result of hash merging
525
1146
  def self.delete_resource_params(options, params ={})
526
1147
  params.merge(only(options, :keep_original, :next_cursor, :invalidate, :transformations))
527
1148
  end
528
1149
 
1150
+ # Generate a transformation string if an input a param is not a string.
1151
+ # @param [String|Hash] transformation Input transformation param
1152
+ # @return [String] Result of transformation
529
1153
  def self.transformation_string(transformation)
530
1154
  transformation.is_a?(String) ? transformation : Cloudinary::Utils.generate_transformation_string(transformation.clone)
531
1155
  end
532
1156
 
1157
+ # Publish resources.
1158
+ # @param [Hash] options Additional options
1159
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1160
+ # @raise [Cloudinary::Api::Error]
533
1161
  def self.publish_resources(options = {})
534
1162
  resource_type = options[:resource_type] || "image"
535
1163
  params = only(options, :public_ids, :prefix, :tag, :type, :overwrite, :invalidate)
536
1164
  call_api("post", "resources/#{resource_type}/publish_resources", params, options)
537
1165
  end
538
1166
 
1167
+ # Publish resources by a prefix.
1168
+ # @param [String] prefix The name of a prefix
1169
+ # @param [Hash] options Additional options
1170
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1171
+ # @raise [Cloudinary::Api::Error]
539
1172
  def self.publish_by_prefix(prefix, options = {})
540
1173
  return self.publish_resources(options.merge(:prefix => prefix))
541
1174
  end
542
1175
 
1176
+ # Publish resources by a tag.
1177
+ # @param [String] tag The name of a tag
1178
+ # @param [Hash] options Additional options
1179
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1180
+ # @raise [Cloudinary::Api::Error]
543
1181
  def self.publish_by_tag(tag, options = {})
544
1182
  return self.publish_resources(options.merge(:tag => tag))
545
1183
  end
546
1184
 
1185
+ # Publish resources by ids.
1186
+ # @param [Array] publicIds List of public ids
1187
+ # @param [Hash] options Additional options
1188
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1189
+ # @raise [Cloudinary::Api::Error]
547
1190
  def self.publish_by_ids(publicIds, options = {})
548
1191
  return self.publish_resources(options.merge(:public_ids => publicIds))
549
1192
  end
550
1193
 
1194
+ # Build a link and prepare data for a call.
1195
+ # @param [String] access_mode The access_mode of resources
1196
+ # @param [Symbol] by_key The new access mode to be set. Possible values: public, authenticated.
1197
+ # @param [String|Array<String>] value The value to assign
1198
+ # @param [Hash] options Additional options
1199
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1200
+ # @raise [Cloudinary::Api::Error]
551
1201
  def self.update_resources_access_mode(access_mode, by_key, value, options = {})
552
1202
  resource_type = options[:resource_type] || "image"
553
1203
  type = options[:type] || "upload"