cloudinary 1.21.0 → 1.22.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,10 +37,32 @@ 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]
@@ -37,18 +71,61 @@ class Cloudinary::Api
37
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
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
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"
@@ -58,6 +135,35 @@ class Cloudinary::Api
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,29 +383,89 @@ 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
430
  params = only(options, :next_cursor, :max_results)
181
431
  params[:transformation] = Cloudinary::Utils.build_eager(transformation)
182
432
  call_api(:get, "transformations", params, options)
183
433
  end
184
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
185
451
  def self.delete_transformation(transformation, options={})
186
452
  call_api(:delete, "transformations", {:transformation => Cloudinary::Utils.build_eager(transformation)}, options)
187
453
  end
188
454
 
189
- # updates - supports:
190
- # "allowed_for_strict" boolean
191
- # "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
192
469
  def self.update_transformation(transformation, updates, options={})
193
470
  params = only(updates, :allowed_for_strict)
194
471
  params[:unsafe_update] = Cloudinary::Utils.build_eager(updates[:unsafe_update]) if updates[:unsafe_update]
@@ -196,6 +473,18 @@ class Cloudinary::Api
196
473
  call_api(:put, "transformations", params, options)
197
474
  end
198
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
199
488
  def self.create_transformation(name, definition, options={})
200
489
  params = {
201
490
  :name => name,
@@ -205,93 +494,302 @@ class Cloudinary::Api
205
494
  call_api(:post, "transformations", params, options)
206
495
  end
207
496
 
208
- # 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
209
507
  def self.upload_presets(options={})
210
508
  call_api(:get, "upload_presets", only(options, :next_cursor, :max_results), options)
211
509
  end
212
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
213
523
  def self.upload_preset(name, options={})
214
524
  call_api(:get, "upload_presets/#{name}", only(options, :max_results), options)
215
525
  end
216
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
217
537
  def self.delete_upload_preset(name, options={})
218
538
  call_api(:delete, "upload_presets/#{name}", {}, options)
219
539
  end
220
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
221
552
  def self.update_upload_preset(name, options={})
222
553
  params = Cloudinary::Uploader.build_upload_params(options)
223
554
  call_api(:put, "upload_presets/#{name}", params.merge(only(options, :unsigned, :disallow_public_id, :live)), options)
224
555
  end
225
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
226
567
  def self.create_upload_preset(options={})
227
568
  params = Cloudinary::Uploader.build_upload_params(options)
228
569
  call_api(:post, "upload_presets", params.merge(only(options, :name, :unsigned, :disallow_public_id, :live)), options)
229
570
  end
230
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
231
582
  def self.root_folders(options={})
232
583
  params = only(options, :max_results, :next_cursor)
233
584
  call_api(:get, "folders", params, options)
234
585
  end
235
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
236
600
  def self.subfolders(of_folder_path, options={})
237
601
  params = only(options, :max_results, :next_cursor)
238
602
  call_api(:get, "folders/#{of_folder_path}", params, options)
239
603
  end
240
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
241
617
  def self.delete_folder(path, options={})
242
618
  call_api(:delete, "folders/#{path}", {}, options)
243
619
  end
244
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
245
631
  def self.create_folder(folder_name, options={})
246
632
  call_api(:post, "folders/#{folder_name}", {}, options)
247
633
  end
248
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
249
645
  def self.upload_mappings(options={})
250
646
  params = only(options, :next_cursor, :max_results)
251
647
  call_api(:get, :upload_mappings, params, options)
252
648
  end
253
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
254
662
  def self.upload_mapping(name=nil, options={})
255
663
  call_api(:get, 'upload_mappings', { :folder => name }, options)
256
664
  end
257
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
258
676
  def self.delete_upload_mapping(name, options={})
259
677
  call_api(:delete, 'upload_mappings', { :folder => name }, options)
260
678
  end
261
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
262
691
  def self.update_upload_mapping(name, options={})
263
692
  params = only(options, :template)
264
693
  params[:folder] = name
265
694
  call_api(:put, 'upload_mappings', params, options)
266
695
  end
267
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
268
708
  def self.create_upload_mapping(name, options={})
269
709
  params = only(options, :template)
270
710
  params[:folder] = name
271
711
  call_api(:post, 'upload_mappings', params, options)
272
712
  end
273
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
274
727
  def self.create_streaming_profile(name, options={})
275
- params = only(options, :display_name, :representations)
276
- params[:representations] = params[:representations].map do |r|
277
- {:transformation => Cloudinary::Utils.generate_transformation_string(r[:transformation])}
278
- end.to_json
279
- params[:name] = name
280
- 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)
281
734
  end
282
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
283
743
  def self.list_streaming_profiles
284
744
  call_api(:get, 'streaming_profiles', {}, {})
285
745
  end
286
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
287
762
  def self.delete_streaming_profile(name, options={})
288
763
  call_api(:delete, "streaming_profiles/#{name}", {}, options)
289
764
  end
290
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
291
776
  def self.get_streaming_profile(name, options={})
292
777
  call_api(:get, "streaming_profiles/#{name}", {}, options)
293
778
  end
294
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
295
793
  def self.update_streaming_profile(name, options={})
296
794
  params = only(options, :display_name, :representations)
297
795
  params[:representations] = params[:representations].map do |r|
@@ -300,73 +798,98 @@ class Cloudinary::Api
300
798
  call_api(:put, "streaming_profiles/#{name}", params, options)
301
799
  end
302
800
 
303
- # Update resources access mode. Resources are selected by the prefix
304
- # @param [String] access_mode the access mode to set the resources to
305
- # @param [String] prefix The prefix by which to filter applicable resources
306
- # @param [Object] options additional options
307
- # @option options [String] :resource_type ("image") the type of resources to modify
308
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
309
- # @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
310
812
  def self.update_resources_access_mode_by_prefix(access_mode, prefix, options = {})
311
-
312
- update_resources_access_mode(access_mode, :prefix, prefix, options)
813
+ update_resources_access_mode(access_mode, :prefix, prefix, options)
313
814
  end
314
815
 
315
- # Update resources access mode. Resources are selected by the tag
316
- # @param [String] access_mode the access mode to set the resources to
317
- # @param [String] tag the tag by which to filter applicable resources
318
- # @param [Object] options additional options
319
- # @option options [String] :resource_type ("image") the type of resources to modify
320
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
321
- # @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
322
827
  def self.update_resources_access_mode_by_tag(access_mode, tag, options = {})
323
-
324
- update_resources_access_mode(access_mode, :tag, tag, options)
828
+ update_resources_access_mode(access_mode, :tag, tag, options)
325
829
  end
326
830
 
327
- # Update resources access mode. Resources are selected by the provided public_ids
328
- # @param [String] access_mode the access mode to set the resources to
329
- # @param [Array<String>] public_ids The prefix by which to filter applicable resources
330
- # @param [Object] options additional options
331
- # @option options [String] :resource_type ("image") the type of resources to modify
332
- # @option options [Fixnum] :max_results (nil) the maximum resources to process in a single invocation
333
- # @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
334
842
  def self.update_resources_access_mode_by_ids(access_mode, public_ids, options = {})
335
-
336
- update_resources_access_mode(access_mode, :public_ids, public_ids, options)
843
+ update_resources_access_mode(access_mode, :public_ids, public_ids, options)
337
844
  end
338
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
339
859
  def self.get_breakpoints(public_id, options)
340
860
  local_options = options.clone
341
861
  base_transformation = Cloudinary::Utils.generate_transformation_string(local_options)
342
862
  srcset = local_options[:srcset]
343
863
  breakpoints = [:min_width, :max_width, :bytes_step, :max_images].map {|k| srcset[k]}.join('_')
344
864
 
345
-
346
865
  local_options[:transformation] = [base_transformation, width: "auto:breakpoints_#{breakpoints}:json"]
347
866
  json_url = Cloudinary::Utils.cloudinary_url public_id, local_options
348
867
  call_json_api('GET', json_url, {}, 60, {})
349
868
  end
350
869
 
351
- # Returns a list of all metadata field definitions.
870
+ # Lists all metadata field definitions.
352
871
  #
353
- # @see https://cloudinary.com/documentation/admin_api#get_metadata_fields Get metadata fields API reference
872
+ # @param [Hash] options The optional parameters.
354
873
  #
355
- # @param [Hash] options Additional options
356
874
  # @return [Cloudinary::Api::Response]
875
+ #
357
876
  # @raise [Cloudinary::Api::Error]
877
+ #
878
+ # @see https://cloudinary.com/documentation/admin_api#get_metadata_fields
358
879
  def self.list_metadata_fields(options = {})
359
880
  call_metadata_api(:get, [], {}, options)
360
881
  end
361
882
 
362
- # Gets a metadata field by external id.
883
+ # Gets a single metadata field definition by external ID.
363
884
  #
364
- # @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.
365
887
  #
366
- # @param [String] field_external_id The ID of the metadata field to retrieve
367
- # @param [Hash] options Additional options
368
888
  # @return [Cloudinary::Api::Response]
889
+ #
369
890
  # @raise [Cloudinary::Api::Error]
891
+ #
892
+ # @see https://cloudinary.com/documentation/admin_api#get_a_metadata_field_by_external_id
370
893
  def self.metadata_field_by_field_id(field_external_id, options = {})
371
894
  uri = [field_external_id]
372
895
 
@@ -375,31 +898,33 @@ class Cloudinary::Api
375
898
 
376
899
  # Creates a new metadata field definition.
377
900
  #
378
- # @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.
379
903
  #
380
- # @param [Hash] field The field to add
381
- # @param [Hash] options Additional options
382
904
  # @return [Cloudinary::Api::Response]
905
+ #
383
906
  # @raise [Cloudinary::Api::Error]
907
+ #
908
+ # @see https://cloudinary.com/documentation/admin_api#create_a_metadata_field
384
909
  def self.add_metadata_field(field, options = {})
385
910
  params = only(field, :type, :external_id, :label, :mandatory, :default_value, :validation, :datasource)
386
911
 
387
912
  call_metadata_api(:post, [], params, options)
388
913
  end
389
914
 
390
- # Updates a metadata field by external id.
915
+ # Updates a metadata field by external ID.
391
916
  #
392
917
  # Updates a metadata field definition (partially, no need to pass the entire object) passed as JSON data.
393
- # See https://cloudinary.com/documentation/admin_api#generic_structure_of_a_metadata_field for the generic structure
394
- # of a metadata field.
395
918
  #
396
- # @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.
397
922
  #
398
- # @param [String] field_external_id The id of the metadata field to update
399
- # @param [Hash] field The field definition
400
- # @param [Hash] options Additional options
401
923
  # @return [Cloudinary::Api::Response]
924
+ #
402
925
  # @raise [Cloudinary::Api::Error]
926
+ #
927
+ # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_by_external_id
403
928
  def self.update_metadata_field(field_external_id, field, options = {})
404
929
  uri = [field_external_id]
405
930
  params = only(field, :label, :mandatory, :default_value, :validation)
@@ -407,35 +932,40 @@ class Cloudinary::Api
407
932
  call_metadata_api(:put, uri, params, options)
408
933
  end
409
934
 
410
- # Deletes a metadata field definition.
935
+ # Deletes a metadata field definition by external ID.
411
936
  #
412
- # 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.
413
939
  #
414
- # @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]
415
944
  #
416
- # @param [String] field_external_id The external id of the field to delete
417
- # @param [Hash] options Additional options
418
- # @return [Cloudinary::Api::Response] A hash with a "message" key. "ok" value indicates a successful deletion
419
945
  # @raise [Cloudinary::Api::Error]
946
+ #
947
+ # @see https://cloudinary.com/documentation/admin_api#delete_a_metadata_field_by_external_id
420
948
  def self.delete_metadata_field(field_external_id, options = {})
421
949
  uri = [field_external_id]
422
950
 
423
951
  call_metadata_api(:delete, uri, {}, options)
424
952
  end
425
953
 
426
- # Deletes entries in a metadata field datasource.
954
+ # Deletes entries in a metadata single or multi-select field's datasource.
955
+ #
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.
427
959
  #
428
- # Deletes (blocks) the datasource entries for a specified metadata field definition. Sets the state of the
429
- # entries to inactive. This is a soft delete, the entries still exist under the hood and can be activated
430
- # again with the restore datasource entries method.
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.
431
963
  #
432
- # @see https://cloudinary.com/documentation/admin_api#delete_entries_in_a_metadata_field_datasource Delete entries in a metadata field datasource API reference
964
+ # @return [Cloudinary::Api::Response]
433
965
  #
434
- # @param [String] field_external_id The id of the field to update
435
- # @param [Array] entries_external_id The ids of all the entries to delete from the datasource
436
- # @param [Hash] options Additional options
437
- # @return [Cloudinary::Api::Response] The remaining datasource entries
438
966
  # @raise [Cloudinary::Api::Error]
967
+ #
968
+ # @see https://cloudinary.com/documentation/admin_api#delete_entries_in_a_metadata_field_datasource
439
969
  def self.delete_datasource_entries(field_external_id, entries_external_id, options = {})
440
970
  uri = [field_external_id, "datasource"]
441
971
  params = {:external_ids => entries_external_id }
@@ -445,17 +975,20 @@ class Cloudinary::Api
445
975
 
446
976
  # Updates a metadata field datasource.
447
977
  #
448
- # 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
449
979
  # update is partial: datasource entries with an existing external_id will be updated and entries with new
450
980
  # external_id’s (or without external_id’s) will be appended.
451
981
  #
452
- # @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.
453
986
  #
454
- # @param [String] field_external_id The external id of the field to update
455
- # @param [Array] entries_external_id
456
- # @param [Hash] options Additional options
457
987
  # @return [Cloudinary::Api::Response]
988
+ #
458
989
  # @raise [Cloudinary::Api::Error]
990
+ #
991
+ # @see https://cloudinary.com/documentation/admin_api#update_a_metadata_field_datasource
459
992
  def self.update_metadata_field_datasource(field_external_id, entries_external_id, options = {})
460
993
  uri = [field_external_id, "datasource"]
461
994
 
@@ -467,18 +1000,20 @@ class Cloudinary::Api
467
1000
  call_metadata_api(:put, uri, params, options)
468
1001
  end
469
1002
 
470
- # Restores entries in a metadata field datasource.
1003
+ # Restore entries in a metadata field datasource.
471
1004
  #
472
1005
  # Restores (unblocks) any previously deleted datasource entries for a specified metadata field definition.
473
1006
  # Sets the state of the entries to active.
474
1007
  #
475
- # @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.
476
1011
  #
477
- # @param [String] field_external_id The ID of the metadata field
478
- # @param [Array] entries_external_ids An array of IDs of datasource entries to restore (unblock)
479
- # @param [Hash] options Additional options
480
1012
  # @return [Cloudinary::Api::Response]
1013
+ #
481
1014
  # @raise [Cloudinary::Api::Error]
1015
+ #
1016
+ # @see https://cloudinary.com/documentation/admin_api#restore_entries_in_a_metadata_field_datasource
482
1017
  def self.restore_metadata_field_datasource(field_external_id, entries_external_ids, options = {})
483
1018
  uri = [field_external_id, "datasource_restore"]
484
1019
  params = {:external_ids => entries_external_ids }
@@ -503,18 +1038,50 @@ class Cloudinary::Api
503
1038
  call_metadata_api(:post, uri, params, options)
504
1039
  end
505
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
+
506
1057
  protected
507
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]
508
1066
  def self.call_api(method, uri, params, options)
509
- cloud_name = options[:cloud_name] || Cloudinary.config.cloud_name || raise('Must supply cloud_name')
510
- api_key = options[:api_key] || Cloudinary.config.api_key || raise('Must supply api_key')
511
- 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)
512
1073
 
513
- call_cloudinary_api(method, uri, api_key, api_secret, params, options) do |cloudinary, inner_uri|
1074
+ auth = { :key => api_key, :secret => api_secret, :oauth_token => oauth_token }
1075
+
1076
+ call_cloudinary_api(method, uri, auth, params, options) do |cloudinary, inner_uri|
514
1077
  [cloudinary, 'v1_1', cloud_name, inner_uri]
515
1078
  end
516
1079
  end
517
1080
 
1081
+ # Parse a json response.
1082
+ # @param [Object] response Returned response from Cloudinary
1083
+ # @return [Hash] Decoded string
1084
+ # @raise [Cloudinary::Api::GeneralError]
518
1085
  def self.parse_json_response(response)
519
1086
  return Cloudinary::Utils.json_decode(response.body)
520
1087
  rescue => e
@@ -529,7 +1096,7 @@ class Cloudinary::Api
529
1096
  # @param [Array] uri REST endpoint of the API (without 'metadata_fields')
530
1097
  # @param [Hash] params Query/body parameters passed to the method
531
1098
  # @param [Hash] options Additional options. Can be an override of the configuration, headers, etc.
532
- # @return [Cloudinary::Api::Response]
1099
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
533
1100
  # @raise [Cloudinary::Api::Error]
534
1101
  def self.call_metadata_api(method, uri, params, options)
535
1102
  options[:content_type] = :json
@@ -538,6 +1105,31 @@ class Cloudinary::Api
538
1105
  call_api(method, uri, params, options)
539
1106
  end
540
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
541
1133
  def self.only(hash, *keys)
542
1134
  result = {}
543
1135
  keys.each do |key|
@@ -547,32 +1139,65 @@ class Cloudinary::Api
547
1139
  result
548
1140
  end
549
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
550
1146
  def self.delete_resource_params(options, params ={})
551
1147
  params.merge(only(options, :keep_original, :next_cursor, :invalidate, :transformations))
552
1148
  end
553
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
554
1153
  def self.transformation_string(transformation)
555
1154
  transformation.is_a?(String) ? transformation : Cloudinary::Utils.generate_transformation_string(transformation.clone)
556
1155
  end
557
1156
 
1157
+ # Publish resources.
1158
+ # @param [Hash] options Additional options
1159
+ # @return [Cloudinary::Api::Response] Returned response from Cloudinary
1160
+ # @raise [Cloudinary::Api::Error]
558
1161
  def self.publish_resources(options = {})
559
1162
  resource_type = options[:resource_type] || "image"
560
1163
  params = only(options, :public_ids, :prefix, :tag, :type, :overwrite, :invalidate)
561
1164
  call_api("post", "resources/#{resource_type}/publish_resources", params, options)
562
1165
  end
563
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]
564
1172
  def self.publish_by_prefix(prefix, options = {})
565
1173
  return self.publish_resources(options.merge(:prefix => prefix))
566
1174
  end
567
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]
568
1181
  def self.publish_by_tag(tag, options = {})
569
1182
  return self.publish_resources(options.merge(:tag => tag))
570
1183
  end
571
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]
572
1190
  def self.publish_by_ids(publicIds, options = {})
573
1191
  return self.publish_resources(options.merge(:public_ids => publicIds))
574
1192
  end
575
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]
576
1201
  def self.update_resources_access_mode(access_mode, by_key, value, options = {})
577
1202
  resource_type = options[:resource_type] || "image"
578
1203
  type = options[:type] || "upload"