uploadcare-ruby 3.3.2 → 4.2.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -1
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +30 -0
  5. data/README.md +198 -36
  6. data/lib/uploadcare/client/addons_client.rb +56 -0
  7. data/lib/uploadcare/client/conversion/base_conversion_client.rb +1 -1
  8. data/lib/uploadcare/client/conversion/document_conversion_client.rb +1 -1
  9. data/lib/uploadcare/client/conversion/video_conversion_client.rb +1 -1
  10. data/lib/uploadcare/client/file_client.rb +14 -10
  11. data/lib/uploadcare/client/file_list_client.rb +4 -4
  12. data/lib/uploadcare/client/file_metadata_client.rb +36 -0
  13. data/lib/uploadcare/client/group_client.rb +4 -4
  14. data/lib/uploadcare/client/multipart_upload/chunks_client.rb +1 -0
  15. data/lib/uploadcare/client/multipart_upload_client.rb +7 -6
  16. data/lib/uploadcare/client/project_client.rb +1 -1
  17. data/lib/uploadcare/client/rest_client.rb +6 -5
  18. data/lib/uploadcare/client/rest_group_client.rb +24 -4
  19. data/lib/uploadcare/client/upload_client.rb +4 -1
  20. data/lib/uploadcare/client/uploader_client.rb +11 -10
  21. data/lib/uploadcare/client/webhook_client.rb +3 -3
  22. data/lib/uploadcare/entity/addons.rb +14 -0
  23. data/lib/uploadcare/entity/conversion/base_converter.rb +1 -1
  24. data/lib/uploadcare/entity/file.rb +19 -37
  25. data/lib/uploadcare/entity/file_list.rb +1 -0
  26. data/lib/uploadcare/entity/file_metadata.rb +30 -0
  27. data/lib/uploadcare/entity/group.rb +11 -2
  28. data/lib/uploadcare/entity/uploader.rb +13 -13
  29. data/lib/uploadcare/param/authentication_header.rb +2 -2
  30. data/lib/uploadcare/param/secure_auth_header.rb +1 -1
  31. data/lib/uploadcare/param/upload/upload_params_generator.rb +25 -8
  32. data/lib/uploadcare/ruby/version.rb +1 -1
  33. data/lib/uploadcare.rb +1 -0
  34. data/uploadcare-ruby.gemspec +10 -3
  35. metadata +27 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3c7c464a8d89a9451f4205ba7f82b3c270d2431eb2b9cf9e31f64fc0542e032
4
- data.tar.gz: 5ee0ef07f9194986eaf3742a5a80d01be38cd69a7e951551b791bcf479cf17f0
3
+ metadata.gz: ed47599fddd9c9b01dc434fffcffc0a323231396105fb028c6c6234ff0faaa6a
4
+ data.tar.gz: a9c20611bc482f6ee7454616dfdc54995d00a31f5159e943b60af71de4982792
5
5
  SHA512:
6
- metadata.gz: 6accbd5a9c9c593c252a370947f42756a477cb47d6d1261a54a17df6f7026f9dd5e49ded174718ce159e6f3da9638744c4520673cfc0c81dcac381f129de2016
7
- data.tar.gz: c383653917bab7dbc417eeccd16b800066ee07cf3741f3734361b8ae9da2935e369442711071a0ab0453860321b21a7a979265fa2a7f19daaaefb9fd4c5add20
6
+ metadata.gz: dba20c7fc6fea99e6b487e77dcec4477ec613f925d1dc2e4a1fd33caa6e8ba8844db2e7c579ac7e40427d24c4c88a4742967086face3c1a9d638815ed3d5c3e4
7
+ data.tar.gz: a4303e9e5b7584b3e5db4f346aff6e1a4bb44be843a762a95edaceec1b04a0400f2ceeb9945b0cfecd03a9ebceb855cc2b126b89f789987d40088f3ecf00eae3
@@ -12,7 +12,7 @@ on: [push, pull_request]
12
12
  jobs:
13
13
  test:
14
14
 
15
- runs-on: ubuntu-latest
15
+ runs-on: ubuntu-20.04
16
16
  strategy:
17
17
  matrix:
18
18
  ruby-version: [
@@ -25,6 +25,7 @@ jobs:
25
25
  - name: Set up Ruby
26
26
  uses: ruby/setup-ruby@v1
27
27
  with:
28
+ bundler: 1.17.3
28
29
  ruby-version: ${{ matrix.ruby-version }}
29
30
  bundler-cache: true
30
31
  - name: Run tests
data/.gitignore CHANGED
@@ -11,4 +11,6 @@
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
13
  .byebug_history
14
+
15
+ .idea
14
16
  Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Breaking Сhanges
6
+
7
+ - For `Uploadcare::File#info`
8
+ - File information doesn't return `image_info` and `video_info` fields anymore
9
+ - Removed `rekognition_info` in favor of `appdata`
10
+ - Parameter `add_fields` was renamed to `include`
11
+ - For `Uploadcare::FileList#file_list`
12
+ - Removed the option of sorting the file list by file size
13
+ - For `Uploadcare::Group#store`
14
+ - Changed response format
15
+ - For `Uploadcare::File`
16
+ - Removed method `copy` in favor of `local_copy` and `remote_copy` methods
17
+
18
+ ### Changed
19
+
20
+ - For `Uploadcare::File#info`
21
+ - Field `content_info` that includes mime-type, image (dimensions, format, etc), video information (duration, format, bitrate, etc), audio information, etc
22
+ - Field `metadata` that includes arbitrary metadata associated with a file
23
+ - Field `appdata` that includes dictionary of application names and data associated with these applications
24
+
25
+ ### Added
26
+
27
+ - Add Uploadcare API interface:
28
+ - `Uploadcare::FileMetadata`
29
+ - `Uploadcare::Addons`
30
+ - Added an option to delete a Group
31
+ - For `Uploadcare::File` add `local_copy` and `remote_copy` methods
32
+
3
33
  ## 3.3.2 - 2022-07-18
4
34
 
5
35
  - Fixes dry-configurable deprecation warnings
data/README.md CHANGED
@@ -25,9 +25,11 @@ wrapping Upload and REST APIs.
25
25
  * [File](#file)
26
26
  * [FileList](#filelist)
27
27
  * [Pagination](#pagination)
28
+ * [Custom File Metadata](#custom-file-metadata)
28
29
  * [Group](#group)
29
30
  * [GroupList](#grouplist)
30
31
  * [Webhook](#webhook)
32
+ * [Add-Ons](#add-ons)
31
33
  * [Project](#project)
32
34
  * [Conversion](#conversion)
33
35
  * [Useful links](#useful-links)
@@ -52,13 +54,24 @@ And then execute:
52
54
 
53
55
  $ bundle
54
56
 
57
+ If you have Ruby version >= 3, then you probably will get error:
58
+ ```
59
+ ArgumentError: wrong number of arguments (given 2, expected 1)
60
+ ```
61
+
62
+ To fix this errors, add this line to your application's Gemfile:
63
+ ```ruby
64
+ gem 'dry-configurable', '0.13.0'
65
+ ```
66
+ and run `bundle install`
67
+
55
68
  If already not, create your project in [Uploadcare dashboard](https://app.uploadcare.com/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby) and copy
56
- its API keys from there.
69
+ its [API keys](https://app.uploadcare.com/projects/-/api-keys/) from there.
57
70
 
58
71
  Set your Uploadcare keys in config file or through environment variables:
59
72
  ```bash
60
- export UPLOADCARE_PUBLIC_KEY=demopublickey
61
- export UPLOADCARE_SECRET_KEY=demoprivatekey
73
+ export UPLOADCARE_PUBLIC_KEY=your_public_key
74
+ export UPLOADCARE_SECRET_KEY=your_private_key
62
75
  ```
63
76
 
64
77
  Or configure your app yourself if you are using different way of storing keys.
@@ -67,8 +80,8 @@ settings can be seen in [`lib/uploadcare.rb`](lib/uploadcare.rb)
67
80
 
68
81
  ```ruby
69
82
  # your_config_initializer_file.rb
70
- Uploadcare.config.public_key = "demopublickey"
71
- Uploadcare.config.secret_key = "demoprivatekey"
83
+ Uploadcare.config.public_key = "your_public_key"
84
+ Uploadcare.config.secret_key = "your_private_key"
72
85
  ```
73
86
 
74
87
  ## Usage
@@ -143,7 +156,7 @@ After the request for uploading-from-URL is sent, you can check the progress of
143
156
 
144
157
  ```ruby
145
158
  Uploadcare::Uploader.get_upload_from_url_status("1251ee66-3631-4416-a2fb-96ba59f5a515")
146
- # => Success({:size=>28511, :total=>28511, :done=>28511, :uuid=>"b829753b-6b64-4989-a167-ef15e4f3d190", :file_id=>"b859753b-zb64-4989-a167-ef15e4f3a190", :original_filename=>"video.ogg", :is_image=>false, :is_stored=>false, :image_info=>nil, :video_info=>nil, :is_ready=>true, :filename=>"video.ogg", :mime_type=>"audio/ogg", :status=>"success"})
159
+ # => Success({:size=>453543, :total=>453543, :done=>453543, :uuid=>"5c51a7fe-e45d-42a2-ba5e-79957ff4bdab", :file_id=>"5c51a7fe-e45d-42a2-ba5e-79957ff4bdab", :original_filename=>"2250", :is_image=>true, :is_stored=>false, :image_info=>{:dpi=>[96, 96], :width=>2250, :format=>"JPEG", :height=>2250, :sequence=>false, :color_mode=>"RGB", :orientation=>nil, :geo_location=>nil, :datetime_original=>nil}, :video_info=>nil, :content_info=>{:mime=>{:mime=>"image/jpeg", :type=>"image", :subtype=>"jpeg"}, :image=>{:dpi=>[96, 96], :width=>2250, :format=>"JPEG", :height=>2250, :sequence=>false, :color_mode=>"RGB", :orientation=>nil, :geo_location=>nil, :datetime_original=>nil}}, :is_ready=>true, :filename=>"2250", :mime_type=>"image/jpeg", :metadata=>{}, :status=>"success"})
147
160
  ```
148
161
 
149
162
  In case of the `async` option is disabled, uploadcare-ruby tries to request the upload status several times (depending on the `max_request_tries` config param) and then returns uploaded file attributes.
@@ -188,6 +201,13 @@ You can override global [`:autostore`](#initialization) option for each upload r
188
201
  @api.upload_from_url(url, store: :auto)
189
202
  ```
190
203
 
204
+ You can upload file with custom metadata, for example `subsystem` and `pet`:
205
+
206
+ ```ruby
207
+ @api.upload(files, metadata: { subsystem: 'my_subsystem', pet: 'cat' } )
208
+ @api.upload_from_url(url, metadata: { subsystem: 'my_subsystem', pet: 'cat' })
209
+ ```
210
+
191
211
  ### File management
192
212
 
193
213
  Entities are representations of objects in Uploadcare cloud.
@@ -198,31 +218,107 @@ File entity contains its metadata.
198
218
 
199
219
  ```ruby
200
220
  @file = Uploadcare::File.file("FILE_ID_IN_YOUR_PROJECT")
201
- {"datetime_removed"=>nil,
202
- "datetime_stored"=>"2020-01-16T15:03:15.315064Z",
203
- "datetime_uploaded"=>"2020-01-16T15:03:14.676902Z",
204
- "image_info"=>
205
- {"color_mode"=>"RGB",
206
- "orientation"=>nil,
207
- "format"=>"JPEG",
208
- "sequence"=>false,
209
- "height"=>183,
210
- "width"=>190,
211
- "geo_location"=>nil,
212
- "datetime_original"=>nil,
213
- "dpi"=>nil},
214
- "is_image"=>true,
215
- "is_ready"=>true,
216
- "mime_type"=>"image/jpeg",
217
- "original_file_url"=>
218
- "https://ucarecdn.com/FILE_ID_IN_YOUR_PROJECT/imagepng.jpeg",
219
- "original_filename"=>"image.png.jpeg",
220
- "size"=>5345,
221
- "url"=>
222
- "https://api.uploadcare.com/files/FILE_ID_IN_YOUR_PROJECT/",
223
- "uuid"=>"8f64f313-e6b1-4731-96c0-6751f1e7a50a"}
224
-
225
- @file.copy # copies file, returns a new (copied) file metadata
221
+ {
222
+ "datetime_removed"=>nil,
223
+ "datetime_stored"=>"2018-11-26T12:49:10.477888Z",
224
+ "datetime_uploaded"=>"2018-11-26T12:49:09.945335Z",
225
+ "is_image"=>true,
226
+ "is_ready"=>true,
227
+ "mime_type"=>"image/jpeg",
228
+ "original_file_url"=>"https://ucarecdn.com/FILE_ID_IN_YOUR_PROJECT/pineapple.jpg",
229
+ "original_filename"=>"pineapple.jpg",
230
+ "size"=>642,
231
+ "url"=>"https://api.uploadcare.com/files/FILE_ID_IN_YOUR_PROJECT/",
232
+ "uuid"=>"FILE_ID_IN_YOUR_PROJECT",
233
+ "variations"=>nil,
234
+ "content_info"=>{
235
+ "mime"=>{
236
+ "mime"=>"image/jpeg",
237
+ "type"=>"image",
238
+ "subtype"=>"jpeg"
239
+ },
240
+ "image"=>{
241
+ "format"=>"JPEG",
242
+ "width"=>500,
243
+ "height"=>500,
244
+ "sequence"=>false,
245
+ "orientation"=>6,
246
+ "geo_location"=>{
247
+ "latitude"=>55.62013611111111,
248
+ "longitude"=>37.66299166666666
249
+ },
250
+ "datetime_original"=>"2018-08-20T08:59:50",
251
+ "dpi"=>[72, 72]
252
+ }
253
+ },
254
+ "metadata"=>{
255
+ "subsystem"=>"uploader",
256
+ "pet"=>"cat"
257
+ },
258
+ "appdata"=>{
259
+ "uc_clamav_virus_scan"=>{
260
+ "data"=>{
261
+ "infected"=>true,
262
+ "infected_with"=>"Win.Test.EICAR_HDB-1"
263
+ },
264
+ "version"=>"0.104.2",
265
+ "datetime_created"=>"2021-09-21T11:24:33.159663Z",
266
+ "datetime_updated"=>"2021-09-21T11:24:33.159663Z"
267
+ },
268
+ "remove_bg"=>{
269
+ "data"=>{
270
+ "foreground_type"=>"person"
271
+ },
272
+ "version"=>"1.0",
273
+ "datetime_created"=>"2021-07-25T12:24:33.159663Z",
274
+ "datetime_updated"=>"2021-07-25T12:24:33.159663Z"
275
+ },
276
+ "aws_rekognition_detect_labels"=>{
277
+ "data"=>{
278
+ "LabelModelVersion"=>"2.0",
279
+ "Labels"=>[
280
+ {
281
+ "Confidence"=>93.41645812988281,
282
+ "Instances"=>[],
283
+ "Name"=>"Home Decor",
284
+ "Parents"=>[]
285
+ },
286
+ {
287
+ "Confidence"=>70.75951385498047,
288
+ "Instances"=>[],
289
+ "Name"=>"Linen",
290
+ "Parents"=>[{ "Name"=>"Home Decor" }]
291
+ },
292
+ {
293
+ "Confidence"=>64.7123794555664,
294
+ "Instances"=>[],
295
+ "Name"=>"Sunlight",
296
+ "Parents"=>[]
297
+ },
298
+ {
299
+ "Confidence"=>56.264793395996094,
300
+ "Instances"=>[],
301
+ "Name"=>"Flare",
302
+ "Parents"=>[{ "Name"=>"Light" }]
303
+ },
304
+ {
305
+ "Confidence"=>50.47153854370117,
306
+ "Instances"=>[],
307
+ "Name"=>"Tree",
308
+ "Parents"=>[{ "Name"=>"Plant" }]
309
+ }
310
+ ]
311
+ },
312
+ "version"=>"2016-06-27",
313
+ "datetime_created"=>"2021-09-21T11:25:31.259763Z",
314
+ "datetime_updated"=>"2021-09-21T11:27:33.359763Z"
315
+ }
316
+ }
317
+ }
318
+
319
+ @file.local_copy # copy file to local storage
320
+
321
+ @file.remote_copy # copy file to remote storage
226
322
 
227
323
  @file.store # stores file, returns updated metadata
228
324
 
@@ -300,8 +396,8 @@ how they should be fetched:
300
396
  - **:limit** — Controls page size. Accepts values from 1 to 1000, defaults to 100.
301
397
  - **:stored** — Can be either `true` or `false`. When true, file list will contain only stored files. When false — only not stored.
302
398
  - **:removed** — Can be either `true` or `false`. When true, file list will contain only removed files. When false — all except removed. Defaults to false.
303
- - **:ordering** — Controls the order of returned files. Available values: `datetime_updated`, `-datetime_updated`, `size`, `-size`. Defaults to `datetime_uploaded`. More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/filesList).
304
- - **:from** — Specifies the starting point for a collection. Resulting collection will contain files from the given value and to the end in a direction set by an **ordering** option. When files are ordered by `datetime_updated` in any direction, accepts either a `DateTime` object or an ISO 8601 string. When files are ordered by size, accepts non-negative integers (size in bytes). More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/filesList).
399
+ - **:ordering** — Controls the order of returned files. Available values: `datetime_uploaded`, `-datetime_uploaded`. Defaults to `datetime_uploaded`. More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/filesList).
400
+ - **:from** — Specifies the starting point for a collection. Resulting collection will contain files from the given value and to the end in a direction set by an **ordering** option. When files are ordered by `datetime_updated` in any direction, accepts either a `DateTime` object or an ISO 8601 string. When files are ordered by size, accepts non-negative integers (size in bytes). More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/filesList).
305
401
 
306
402
  Options used to create a file list can be accessed through `#options` method.
307
403
  Note that, once set, they don't affect file fetching process anymore and are
@@ -340,6 +436,25 @@ Alternatively, it's possible to iterate through full list of groups or files wit
340
436
  end
341
437
  ```
342
438
 
439
+ #### Custom File Metadata
440
+
441
+ File metadata is additional, arbitrary data, associated with uploaded file.
442
+ As an example, you could store unique file identifier from your system.
443
+
444
+ ```ruby
445
+ # Get file's metadata keys and values.
446
+ Uploadcare::FileMetadata.index('FILE_ID_IN_YOUR_PROJECT')
447
+
448
+ # Get the value of a single metadata key.
449
+ Uploadcare::FileMetadata.show('FILE_ID_IN_YOUR_PROJECT', 'KEY')
450
+
451
+ # Update the value of a single metadata key. If the key does not exist, it will be created.
452
+ Uploadcare::FileMetadata.update('FILE_ID_IN_YOUR_PROJECT', 'KEY', 'VALUE')
453
+
454
+ # Delete a file's metadata key.
455
+ Uploadcare::FileMetadata.delete('FILE_ID_IN_YOUR_PROJECT', 'KEY')
456
+ ```
457
+
343
458
  #### Group
344
459
 
345
460
  Groups are structures intended to organize sets of separate files. Each group is
@@ -355,6 +470,12 @@ That's a requirement of our API.
355
470
 
356
471
  # group can be stored by group ID. It means that all files of a group will be stored on Uploadcare servers permanently
357
472
  Uploadcare::Group.store(group.id)
473
+
474
+ # get a file group by its ID.
475
+ Uploadcare::Group.rest_info(group.id)
476
+
477
+ # group can be deleted by group ID.
478
+ Uploadcare::Group.delete(group.id)
358
479
  ```
359
480
 
360
481
  #### GroupList
@@ -430,15 +551,56 @@ else
430
551
  end
431
552
  ```
432
553
 
554
+ #### Add-Ons
555
+
556
+ An `Add-On` is an application implemented by Uploadcare that accepts uploaded files as an input and can produce other files and/or appdata as an output.
557
+
558
+ ##### AWS Rekognition
559
+
560
+ ```ruby
561
+ # Execute AWS Rekognition Add-On for a given target to detect labels in an image. Note: Detected labels are stored in the file's appdata.
562
+ Uploadcare::Addons.ws_rekognition_detect_labels('FILE_ID_IN_YOUR_PROJECT')
563
+
564
+ # Check the status of AWS Rekognition.
565
+ Uploadcare::Addons.ws_rekognition_detect_labels_status('RETURNED_ID_FROM_WS_REKOGNITION_DETECT_LABELS')
566
+ ```
567
+
568
+ ##### ClamAV
569
+
570
+ ```ruby
571
+ # ClamAV virus checking Add-On for a given target.
572
+ Uploadcare::Addons.uc_clamav_virus_scan('FILE_ID_IN_YOUR_PROJECT')
573
+
574
+ # Checking and purge infected file.
575
+ Uploadcare::Addons.uc_clamav_virus_scan('FILE_ID_IN_YOUR_PROJECT', purge_infected: true )
576
+
577
+ # Check the status ClamAV virus scan.
578
+ Uploadcare::Addons.uc_clamav_virus_scan_status('RETURNED_ID_FROM_UC_CLAMAV_VIRUS_SCAN')
579
+ ```
580
+
581
+ ##### Remove.bg
582
+
583
+ ```ruby
584
+ # Remove background image removal Add-On for a given target.
585
+ Uploadcare::Addons.remove_bg('FILE_ID_IN_YOUR_PROJECT')
586
+
587
+ # You can pass optional parameters.
588
+ # See the full list of parameters here: https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/removeBgExecute
589
+ Uploadcare::Addons.remove_bg('FILE_ID_IN_YOUR_PROJECT', crop: true, type_level: '2')
590
+
591
+ # Check the status of background image removal.
592
+ Uploadcare::Addons.remove_bg_status('RETURNED_ID_FROM_REMOVE_BG')
593
+ ```
594
+
433
595
  #### Project
434
596
 
435
597
  `Project` provides basic info about the connected Uploadcare project. That
436
598
  object is also an Hashie::Mash, so every methods out of
437
- [these](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/projectInfo) will work.
599
+ [these](https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/projectInfo) will work.
438
600
 
439
601
  ```ruby
440
602
  @project = Uploadcare::Project.project
441
- # => #<Uploadcare::Api::Project collaborators=[], name="demo", pub_key="demopublickey", autostore_enabled=true>
603
+ # => #<Uploadcare::Api::Project collaborators=[], name="demo", pub_key="your_public_key", autostore_enabled=true>
442
604
 
443
605
  @project.name
444
606
  # => "demo"
@@ -513,7 +675,7 @@ Params in the response:
513
675
  - **original_source** - built path for a particular video with all the conversion operations and parameters.
514
676
  - **token** - a processing job token that can be used to get a [job status](https://uploadcare.com/docs/transformations/video-encoding/#status) (see below).
515
677
  - **uuid** - UUID of your processed video file.
516
- - **thumbnails_group_uuid** - holds :uuid-thumb-group, a UUID of a [file group](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/groupsList) with thumbnails for an output video, based on the thumbs [operation](https://uploadcare.com/docs/transformations/video-encoding/#operation-thumbs) parameters.
678
+ - **thumbnails_group_uuid** - holds :uuid-thumb-group, a UUID of a [file group](https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/groupsList) with thumbnails for an output video, based on the thumbs [operation](https://uploadcare.com/docs/transformations/video-encoding/#operation-thumbs) parameters.
517
679
  - **problems** - problems related to your processing job, if any.
518
680
 
519
681
  To convert multiple videos just add params as a hash for each video to the first argument of the `Uploadcare::VideoConverter#convert` method:
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rest_client'
4
+
5
+ module Uploadcare
6
+ module Client
7
+ # API client for handling uploaded files
8
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons
9
+ class AddonsClient < RestClient
10
+ # Execute ClamAV virus checking Add-On for a given target.
11
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/ucClamavVirusScanExecute
12
+ def uc_clamav_virus_scan(uuid, params = {})
13
+ content = { target: uuid, params: params }.to_json
14
+ post(uri: '/addons/uc_clamav_virus_scan/execute/', content: content)
15
+ end
16
+
17
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
18
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/ucClamavVirusScanExecutionStatus
19
+ def uc_clamav_virus_scan_status(uuid)
20
+ get(uri: "/addons/uc_clamav_virus_scan/execute/status/#{query_params(uuid)}")
21
+ end
22
+
23
+ # Execute AWS Rekognition Add-On for a given target to detect labels in an image.
24
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/awsRekognitionExecute
25
+ def ws_rekognition_detect_labels(uuid)
26
+ content = { target: uuid }.to_json
27
+ post(uri: '/addons/aws_rekognition_detect_labels/execute/', content: content)
28
+ end
29
+
30
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
31
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/awsRekognitionExecutionStatus
32
+ def ws_rekognition_detect_labels_status(uuid)
33
+ get(uri: "/addons/aws_rekognition_detect_labels/execute/status/#{query_params(uuid)}")
34
+ end
35
+
36
+ # Execute remove.bg background image removal Add-On for a given target.
37
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/removeBgExecute
38
+ def remove_bg(uuid, params = {})
39
+ content = { target: uuid, params: params }.to_json
40
+ post(uri: '/addons/remove_bg/execute/', content: content)
41
+ end
42
+
43
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
44
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/removeBgExecutionStatus
45
+ def remove_bg_status(uuid)
46
+ get(uri: "/addons/remove_bg/execute/status/#{query_params(uuid)}")
47
+ end
48
+
49
+ private
50
+
51
+ def query_params(uuid)
52
+ "?#{URI.encode_www_form(request_id: uuid)}"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -8,7 +8,7 @@ module Uploadcare
8
8
  module Conversion
9
9
  # This is a base client for conversion operations
10
10
  #
11
- # @see https://uploadcare.com/api-refs/rest-api/v0.6.0/#tag/Conversion
11
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion
12
12
  class BaseConversionClient < RestClient
13
13
  API_VERSION_HEADER_VALUE = 'application/vnd.uploadcare-v0.5+json'
14
14
 
@@ -8,7 +8,7 @@ module Uploadcare
8
8
  module Conversion
9
9
  # This is client for document conversion
10
10
  #
11
- # @see https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/documentConvert
11
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/documentConvert
12
12
  class DocumentConversionClient < BaseConversionClient
13
13
  def convert_many(
14
14
  arr,
@@ -9,7 +9,7 @@ module Uploadcare
9
9
  module Conversion
10
10
  # This is client for video conversion
11
11
  #
12
- # @see https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/videoConvert
12
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/videoConvert
13
13
  class VideoConversionClient < BaseConversionClient
14
14
  def convert_many(
15
15
  params,
@@ -6,7 +6,7 @@ module Uploadcare
6
6
  module Client
7
7
  # API client for handling single files
8
8
  # @see https://uploadcare.com/docs/api_reference/rest/accessing_files/
9
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#tag/File
9
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File
10
10
  class FileClient < RestClient
11
11
  # Gets list of files without pagination fields
12
12
  def index
@@ -15,27 +15,31 @@ module Uploadcare
15
15
  end
16
16
 
17
17
  # Acquire file info
18
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/fileInfo
18
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/fileInfo
19
19
  def info(uuid)
20
20
  get(uri: "/files/#{uuid}/")
21
21
  end
22
22
  alias file info
23
23
 
24
- # 'copy' method is used to copy original files or their modified versions to default storage.
25
- # Source files MAY either be stored or just uploaded and MUST NOT be deleted.
26
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/copyFile
27
- def copy(**options)
24
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createLocalCopy
25
+ def local_copy(options = {})
28
26
  body = options.compact.to_json
29
- post(uri: '/files/', content: body)
27
+ post(uri: '/files/local_copy/', content: body)
30
28
  end
31
29
 
32
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/deleteFile
30
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createRemoteCopy
31
+ def remote_copy(options = {})
32
+ body = options.compact.to_json
33
+ post(uri: '/files/remote_copy/', content: body)
34
+ end
35
+
36
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/deleteFileStorage
33
37
  def delete(uuid)
34
- request(method: 'DELETE', uri: "/files/#{uuid}/")
38
+ request(method: 'DELETE', uri: "/files/#{uuid}/storage/")
35
39
  end
36
40
 
37
41
  # Store a single file, preventing it from being deleted in 2 weeks
38
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/storeFile
42
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/storeFile
39
43
  def store(uuid)
40
44
  put(uri: "/files/#{uuid}/storage/")
41
45
  end
@@ -7,13 +7,13 @@ module Uploadcare
7
7
  # API client for handling file lists
8
8
  class FileListClient < RestClient
9
9
  # Returns a pagination json of files stored in project
10
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesList
10
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/filesList
11
11
  #
12
12
  # valid options:
13
13
  # removed: [true|false]
14
14
  # stored: [true|false]
15
15
  # limit: (1..1000)
16
- # ordering: ["datetime_uploaded"|"-datetime_uploaded"|"size"|"-size"]
16
+ # ordering: ["datetime_uploaded"|"-datetime_uploaded"]
17
17
  # from: number of files skipped
18
18
  def file_list(options = {})
19
19
  query = options.empty? ? '' : "?#{URI.encode_www_form(options)}"
@@ -21,7 +21,7 @@ module Uploadcare
21
21
  end
22
22
 
23
23
  # Make a set of files "stored". This will prevent them from being deleted automatically
24
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesStoring
24
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/filesStoring
25
25
  # uuids: Array
26
26
  def batch_store(uuids)
27
27
  body = uuids.to_json
@@ -31,7 +31,7 @@ module Uploadcare
31
31
  alias request_delete delete
32
32
 
33
33
  # Delete several files by list of uids
34
- # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesDelete
34
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/filesDelete
35
35
  # uuids: Array
36
36
  def batch_delete(uuids)
37
37
  body = uuids.to_json
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rest_client'
4
+
5
+ module Uploadcare
6
+ module Client
7
+ # API client for handling single metadata_files
8
+ # @see https://uploadcare.com/docs/file-metadata/
9
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-metadata
10
+ class FileMetadataClient < RestClient
11
+ # Get file's metadata keys and values
12
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/fileMetadata
13
+ def index(uuid)
14
+ get(uri: "/files/#{uuid}/metadata/")
15
+ end
16
+
17
+ # Get the value of a single metadata key.
18
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/fileMetadataKey
19
+ def show(uuid, key)
20
+ get(uri: "/files/#{uuid}/metadata/#{key}/")
21
+ end
22
+
23
+ # Update the value of a single metadata key. If the key does not exist, it will be created.
24
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/updateFileMetadataKey
25
+ def update(uuid, key, value)
26
+ put(uri: "/files/#{uuid}/metadata/#{key}/", content: value.to_json)
27
+ end
28
+
29
+ # Delete a file's metadata key.
30
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/deleteFileMetadataKey
31
+ def delete(uuid, key)
32
+ request(method: 'DELETE', uri: "/files/#{uuid}/metadata/#{key}/")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -10,8 +10,8 @@ module Uploadcare
10
10
  class GroupClient < UploadClient
11
11
  # Create files group from a set of files by using their UUIDs.
12
12
  # @see https://uploadcare.com/api-refs/upload-api/#operation/createFilesGroup
13
- def create(file_list, **options)
14
- body_hash = group_body_hash(file_list, **options)
13
+ def create(file_list, options = {})
14
+ body_hash = group_body_hash(file_list, options)
15
15
  body = HTTP::FormData::Multipart.new(body_hash)
16
16
  post(path: 'group/',
17
17
  headers: { 'Content-Type': body.content_type },
@@ -31,8 +31,8 @@ module Uploadcare
31
31
  ids.zip(file_ids).to_h
32
32
  end
33
33
 
34
- def group_body_hash(file_list, **options)
35
- { pub_key: Uploadcare.config.public_key }.merge(file_params(parse_file_list(file_list))).merge(**options)
34
+ def group_body_hash(file_list, options = {})
35
+ { pub_key: Uploadcare.config.public_key }.merge(file_params(parse_file_list(file_list))).merge(options)
36
36
  end
37
37
 
38
38
  # API accepts only list of ids, but some users may want to upload list of files
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'parallel'
4
+ require 'dry/monads'
4
5
  require 'api_struct'
5
6
 
6
7
  module Uploadcare