uploadcare-ruby 4.4.0 → 4.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/CHANGELOG.md +24 -2
  4. data/README.md +83 -38
  5. data/api_examples/rest_api/delete_files_storage.rb +6 -0
  6. data/api_examples/rest_api/delete_files_uuid_metadata_key.rb +5 -0
  7. data/api_examples/rest_api/delete_files_uuid_storage.rb +5 -0
  8. data/api_examples/rest_api/delete_groups_uuid.rb +5 -0
  9. data/api_examples/rest_api/delete_webhooks_unsubscribe.rb +5 -0
  10. data/api_examples/rest_api/get_addons_aws_rekognition_detect_labels_execute_status.rb +7 -0
  11. data/api_examples/rest_api/get_addons_aws_rekognition_detect_moderation_labels_execute_status.rb +7 -0
  12. data/api_examples/rest_api/get_addons_remove_bg_execute_status.rb +7 -0
  13. data/api_examples/rest_api/get_addons_uc_clamav_virus_scan_execute_status.rb +7 -0
  14. data/api_examples/rest_api/get_convert_document_status_token.rb +6 -0
  15. data/api_examples/rest_api/get_convert_document_uuid.rb +6 -0
  16. data/api_examples/rest_api/get_convert_video_status_token.rb +6 -0
  17. data/api_examples/rest_api/get_files.rb +6 -0
  18. data/api_examples/rest_api/get_files_uuid.rb +6 -0
  19. data/api_examples/rest_api/get_files_uuid_metadata.rb +6 -0
  20. data/api_examples/rest_api/get_files_uuid_metadata_key.rb +6 -0
  21. data/api_examples/rest_api/get_groups.rb +6 -0
  22. data/api_examples/rest_api/get_groups_uuid.rb +6 -0
  23. data/api_examples/rest_api/get_project.rb +6 -0
  24. data/api_examples/rest_api/get_webhooks.rb +6 -0
  25. data/api_examples/rest_api/post_addons_aws_rekognition_detect_labels_execute.rb +6 -0
  26. data/api_examples/rest_api/post_addons_aws_rekognition_detect_moderation_labels_execute.rb +6 -0
  27. data/api_examples/rest_api/post_addons_remove_bg_execute.rb +6 -0
  28. data/api_examples/rest_api/post_addons_uc_clamav_virus_scan_execute.rb +6 -0
  29. data/api_examples/rest_api/post_convert_document.rb +7 -0
  30. data/api_examples/rest_api/post_convert_video.rb +11 -0
  31. data/api_examples/rest_api/post_files_local_copy.rb +7 -0
  32. data/api_examples/rest_api/post_files_remote_copy.rb +8 -0
  33. data/api_examples/rest_api/post_webhooks.rb +10 -0
  34. data/api_examples/rest_api/put_files_storage.rb +9 -0
  35. data/api_examples/rest_api/put_files_uuid_metadata_key.rb +8 -0
  36. data/api_examples/rest_api/put_files_uuid_storage.rb +6 -0
  37. data/api_examples/rest_api/put_webhooks_id.rb +12 -0
  38. data/api_examples/upload_api/get_from_url_status.rb +6 -0
  39. data/api_examples/upload_api/get_group_info.rb +7 -0
  40. data/api_examples/upload_api/get_info.rb +7 -0
  41. data/api_examples/upload_api/post_base.rb +6 -0
  42. data/api_examples/upload_api/post_from_url.rb +6 -0
  43. data/api_examples/upload_api/post_group.rb +9 -0
  44. data/api_examples/upload_api/post_multipart_complete.rb +8 -0
  45. data/api_examples/upload_api/post_multipart_start.rb +8 -0
  46. data/api_examples/upload_api/put_presigned_url_x.rb +8 -0
  47. data/lib/uploadcare/client/addons_client.rb +13 -0
  48. data/lib/uploadcare/client/conversion/document_conversion_client.rb +4 -0
  49. data/lib/uploadcare/client/multipart_upload_client.rb +1 -1
  50. data/lib/uploadcare/entity/conversion/base_converter.rb +8 -1
  51. data/lib/uploadcare/entity/file.rb +6 -2
  52. data/lib/uploadcare/exception/auth_error.rb +8 -0
  53. data/lib/uploadcare/param/authentication_header.rb +12 -0
  54. data/lib/uploadcare/ruby/version.rb +1 -1
  55. data/lib/uploadcare/signed_url_generators/{amakai_generator.rb → akamai_generator.rb} +16 -6
  56. data/lib/uploadcare.rb +3 -1
  57. metadata +47 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35dc34779d62684051b582e460d75f4e58acaa5f2c7372869b9fa753eea117e6
4
- data.tar.gz: ac06dcf3b4921a8199849111bbd38d1ae7cfad4ad1f5d0adb43a06c885102045
3
+ metadata.gz: b627592459c5fd8142372876e62f4888aa9ce94139011e583b72746ed68063b7
4
+ data.tar.gz: b695ed1e4ee129f82e589470930b2b84d58fac576f0f676095c1decc56226a1f
5
5
  SHA512:
6
- metadata.gz: f189a6b962f27441c40f40f56db9fda78aa492e8d1ad1703663b85a6f6eb7df35f23fdab89c475ecbaec5701c0fc838d8d80f68ca7ee780c9037843906ade31c
7
- data.tar.gz: cf4a88871447ed9733cfc777486ee77d6113a55f523b3a6e6eac0ec9340f0652ec85c01434544352094f7672283879a130d6816df31c2a1ba5d8897176ed7dbb
6
+ metadata.gz: f5db8bdd4c9b77826087a6cd83c578e823abb8d1d212cf283baf887b841ba7fc643f35c41df98fa473daaf4614a7f1427cdd28da16df120effedf62e357cf5bb
7
+ data.tar.gz: 8772728c7606f69d5d8166a0a928862d6fde6849b91622022d6b0ba0814a4e9e2a586acf1e35a873cc7c835c33d28e4b197df9aebb94be89af0dc74de61b509e
data/.rubocop.yml CHANGED
@@ -4,6 +4,8 @@ AllCops:
4
4
 
5
5
  Layout/LineLength:
6
6
  Max: 120
7
+ Exclude:
8
+ - 'spec/**/*'
7
9
 
8
10
  Lint/IneffectiveAccessModifier:
9
11
  Enabled: false
@@ -20,6 +22,10 @@ Metrics/BlockLength:
20
22
  - 'spec/**/*'
21
23
  - 'uploadcare-ruby.gemspec'
22
24
 
25
+ Metrics/ModuleLength:
26
+ Exclude:
27
+ - 'spec/**/*'
28
+
23
29
  Metrics/MethodLength:
24
30
  Max: 20
25
31
 
@@ -28,3 +34,7 @@ Style/Documentation:
28
34
 
29
35
  Style/OptionalBooleanParameter:
30
36
  AllowedMethods: ['create']
37
+
38
+ Style/FrozenStringLiteralComment:
39
+ Exclude:
40
+ - 'api_examples/**/*'
data/CHANGELOG.md CHANGED
@@ -1,8 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.2 — 2024-05-29
4
+
5
+ ### Fixed
6
+ * Fixed the `Uploadcare::File.remote_copy` method which raised an `ApiStruct::EntityError: {url} must be Hash`. Now returns a string instead of a `File` entity instance.
7
+
8
+ ### Added
9
+ * `Document Info` API added in `DocumentConverter`.
10
+
11
+ ## 4.4.1 — 2024-04-27
12
+
13
+ ### Added
14
+ * Added `AWS Rekognition Moderation` Add-On.
15
+ * Added an optional `wildcard` boolean parameter to the `generate_url` method of `AkamaiGenerator`.
16
+
17
+ ### Changed
18
+ * File attribute `datetime_stored` is deprecated and will warn on usage from `File` object properties.
19
+
20
+ ### Fixed
21
+
22
+ * Throw `AuthError` if current public key or secret key config are empty when accessing any of the APIs.
23
+ * `AmakaiGenerator` has been renamed to `AkamaiGenerator` to fix typo in class name.
24
+
3
25
  ## 4.4.0 — 2024-03-09
4
26
 
5
- ### Breaking
27
+ ### Breaking
6
28
 
7
29
  * Drop support of unmaintainable Ruby versions < 3.x.
8
30
 
@@ -68,7 +90,7 @@ Add support of new ruby versions
68
90
  ### Breaking Сhanges
69
91
 
70
92
  - Drop support of unmaintainable Ruby versions (2.4, 2.5, 2.6).
71
- - Replace unmaintainable `api_struct` with `uploadcare-api_struct`
93
+ - Replace unmaintainable `api_struct` with `uploadcare-api_struct`
72
94
 
73
95
  ### Added
74
96
 
data/README.md CHANGED
@@ -95,7 +95,7 @@ Using Uploadcare is simple, and here are the basics of handling files.
95
95
  ```ruby
96
96
  @file_to_upload = File.open("your-file.png")
97
97
 
98
- @uc_file = Uploadcare::Uploader.upload(@file_to_upload)
98
+ @uc_file = Uploadcare::Uploader.upload(@file_to_upload, store: "auto")
99
99
 
100
100
  @uc_file.uuid
101
101
  # => "dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
@@ -105,13 +105,15 @@ Using Uploadcare is simple, and here are the basics of handling files.
105
105
  # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/your-file.png"
106
106
  ```
107
107
 
108
- Your might then want to store or delete the uploaded file. Storing files could
109
- be crucial if you aren't using the “Automatic file storing” option for your
110
- Uploadcare project. If not stored manually or automatically, files get deleted
111
- within a 24-hour period.
108
+ The `store` option can have these possible values:
109
+ - `true`: mark the uploaded file as stored.
110
+ - `false`: do not mark the uploaded file as stored and remove it after 24 hours.
111
+ - `"auto"`: defers the choice of storage behavior to the [auto-store setting](https://app.uploadcare.com/projects/-/settings/#storage) for your Uploadcare project. This is the default behavior.
112
+
113
+ Your might then want to store or delete the uploaded file.
112
114
 
113
115
  ```ruby
114
- # that's how you store a file
116
+ # that's how you store a file, if you have uploaded the file using store: false and changed your mind later
115
117
  @uc_file.store
116
118
  # => #<Uploadcare::Api::File ...
117
119
 
@@ -128,16 +130,16 @@ Uploadcare supports multiple ways to upload files:
128
130
  # Smart upload - detects type of passed object and picks appropriate upload method
129
131
  # If you have a large file (more than 100Mb / 10485760 bytes), the uploader will automatically process it with a multipart upload
130
132
 
131
- Uploadcare::Uploader.upload("https://placekitten.com/96/139")
133
+ Uploadcare::Uploader.upload("https://placekitten.com/96/139", store: "auto")
132
134
  ```
133
135
 
134
136
  There are explicit ways to select upload type:
135
137
 
136
138
  ```ruby
137
139
  files = [File.open("1.jpg"), File.open("1.jpg")]
138
- Uploadcare::Uploader.upload_files(files)
140
+ Uploadcare::Uploader.upload_files(files, store: 'auto')
139
141
 
140
- Uploadcare::Uploader.upload_from_url("https://placekitten.com/96/139")
142
+ Uploadcare::Uploader.upload_from_url("https://placekitten.com/96/139", store: "auto")
141
143
  ```
142
144
  It is possible to track progress of the upload-from-URL process. To do that, you should specify the `async` option and get a token:
143
145
 
@@ -188,11 +190,12 @@ Options available in a block:
188
190
 
189
191
  #### Uploading options
190
192
 
191
- You can override global [`:autostore`](#initialization) option for each upload request:
193
+ You can override [auto-store setting](https://app.uploadcare.com/projects/-/settings/#storage) from your Uploadcare project for each upload request:
192
194
 
193
195
  ```ruby
194
- @api.upload(files, store: true)
195
- @api.upload_from_url(url, store: :auto)
196
+ @api.upload(files, store: true) # mark the uploaded file as stored.
197
+ @api.upload(files, store: false) # do not mark the uploaded file as stored and remove it after 24 hours.
198
+ @api.upload_from_url(url, store: "auto") # defers the choice of storage behavior to the auto-store setting.
196
199
  ```
197
200
 
198
201
  You can upload file with custom metadata, for example `subsystem` and `pet`:
@@ -208,10 +211,10 @@ Entities are representations of objects in Uploadcare cloud.
208
211
 
209
212
  #### File
210
213
 
211
- File entity contains its metadata. It also supports `include` param to include additional fields to the file object, such as: "appdata".
214
+ File entity contains its metadata. It also supports `include` param to include additional fields to the file object, such as: "appdata".
212
215
 
213
216
  ```ruby
214
- @file = Uploadcare::File.file("FILE_ID_IN_YOUR_PROJECT", include: "appdata")
217
+ @file = Uploadcare::File.file("FILE_UUID", include: "appdata")
215
218
  {
216
219
  "datetime_removed"=>nil,
217
220
  "datetime_stored"=>"2018-11-26T12:49:10.477888Z",
@@ -219,11 +222,11 @@ File entity contains its metadata. It also supports `include` param to include a
219
222
  "is_image"=>true,
220
223
  "is_ready"=>true,
221
224
  "mime_type"=>"image/jpeg",
222
- "original_file_url"=>"https://ucarecdn.com/FILE_ID_IN_YOUR_PROJECT/pineapple.jpg",
225
+ "original_file_url"=>"https://ucarecdn.com/FILE_UUID/pineapple.jpg",
223
226
  "original_filename"=>"pineapple.jpg",
224
227
  "size"=>642,
225
- "url"=>"https://api.uploadcare.com/files/FILE_ID_IN_YOUR_PROJECT/",
226
- "uuid"=>"FILE_ID_IN_YOUR_PROJECT",
228
+ "url"=>"https://api.uploadcare.com/files/FILE_UUID/",
229
+ "uuid"=>"FILE_UUID",
227
230
  "variations"=>nil,
228
231
  "content_info"=>{
229
232
  "mime"=>{
@@ -322,7 +325,7 @@ File entity contains its metadata. It also supports `include` param to include a
322
325
  The File object is also can be converted if it is a document or a video file. Imagine, you have a document file:
323
326
 
324
327
  ```ruby
325
- @file = Uploadcare::File.file("FILE_ID_IN_YOUR_PROJECT")
328
+ @file = Uploadcare::File.file("FILE_UUID")
326
329
  ```
327
330
 
328
331
  To convert it to an another file, just do:
@@ -437,16 +440,16 @@ As an example, you could store unique file identifier from your system.
437
440
 
438
441
  ```ruby
439
442
  # Get file's metadata keys and values.
440
- Uploadcare::FileMetadata.index('FILE_ID_IN_YOUR_PROJECT')
443
+ Uploadcare::FileMetadata.index('FILE_UUID')
441
444
 
442
445
  # Get the value of a single metadata key.
443
- Uploadcare::FileMetadata.show('FILE_ID_IN_YOUR_PROJECT', 'KEY')
446
+ Uploadcare::FileMetadata.show('FILE_UUID', 'KEY')
444
447
 
445
448
  # Update the value of a single metadata key. If the key does not exist, it will be created.
446
- Uploadcare::FileMetadata.update('FILE_ID_IN_YOUR_PROJECT', 'KEY', 'VALUE')
449
+ Uploadcare::FileMetadata.update('FILE_UUID', 'KEY', 'VALUE')
447
450
 
448
451
  # Delete a file's metadata key.
449
- Uploadcare::FileMetadata.delete('FILE_ID_IN_YOUR_PROJECT', 'KEY')
452
+ Uploadcare::FileMetadata.delete('FILE_UUID', 'KEY')
450
453
  ```
451
454
 
452
455
  #### Group
@@ -470,6 +473,7 @@ Uploadcare::Group.rest_info(group.id)
470
473
 
471
474
  # group can be deleted by group ID.
472
475
  Uploadcare::Group.delete(group.id)
476
+ # Note: This operation only removes the group object itself. All the files that were part of the group are left as is.
473
477
  ```
474
478
 
475
479
  #### GroupList
@@ -552,37 +556,50 @@ An `Add-On` is an application implemented by Uploadcare that accepts uploaded fi
552
556
  ##### AWS Rekognition
553
557
 
554
558
  ```ruby
555
- # 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.
556
- Uploadcare::Addons.ws_rekognition_detect_labels('FILE_ID_IN_YOUR_PROJECT')
559
+ # Execute AWS Rekognition Add-On for a given target to detect labels in an image.
560
+ # Note: Detected labels are stored in the file's appdata.
561
+ Uploadcare::Addons.ws_rekognition_detect_labels('FILE_UUID')
557
562
 
558
563
  # Check the status of AWS Rekognition.
559
564
  Uploadcare::Addons.ws_rekognition_detect_labels_status('RETURNED_ID_FROM_WS_REKOGNITION_DETECT_LABELS')
560
565
  ```
561
566
 
567
+ ##### AWS Rekognition Moderation
568
+
569
+ ```ruby
570
+ # Execute AWS Rekognition Moderation Add-On for a given target to detect moderation labels in an image.
571
+ # Note: Detected moderation labels are stored in the file's appdata.
572
+
573
+ Uploadcare::Addons.ws_rekognition_detect_moderation_labels('FILE_UUID')
574
+
575
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
576
+ Uploadcare::Addons.ws_rekognition_detect_moderation_labels_status('RETURNED_ID_FROM_WS_REKOGNITION_DETECT_MODERATION_LABELS')
577
+ ```
578
+
562
579
  ##### ClamAV
563
580
 
564
581
  ```ruby
565
582
  # ClamAV virus checking Add-On for a given target.
566
- Uploadcare::Addons.uc_clamav_virus_scan('FILE_ID_IN_YOUR_PROJECT')
583
+ Uploadcare::Addons.uc_clamav_virus_scan('FILE_UUID')
567
584
 
568
- # Checking and purge infected file.
569
- Uploadcare::Addons.uc_clamav_virus_scan('FILE_ID_IN_YOUR_PROJECT', purge_infected: true )
585
+ # Check and purge infected file.
586
+ Uploadcare::Addons.uc_clamav_virus_scan('FILE_UUID', purge_infected: true )
570
587
 
571
- # Check the status ClamAV virus scan.
588
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
572
589
  Uploadcare::Addons.uc_clamav_virus_scan_status('RETURNED_ID_FROM_UC_CLAMAV_VIRUS_SCAN')
573
590
  ```
574
591
 
575
592
  ##### Remove.bg
576
593
 
577
594
  ```ruby
578
- # Remove background image removal Add-On for a given target.
579
- Uploadcare::Addons.remove_bg('FILE_ID_IN_YOUR_PROJECT')
595
+ # Execute remove.bg background image removal Add-On for a given target.
596
+ Uploadcare::Addons.remove_bg('FILE_UUID')
580
597
 
581
598
  # You can pass optional parameters.
582
599
  # See the full list of parameters here: https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/removeBgExecute
583
- Uploadcare::Addons.remove_bg('FILE_ID_IN_YOUR_PROJECT', crop: true, type_level: '2')
600
+ Uploadcare::Addons.remove_bg('FILE_UUID', crop: true, type_level: '2')
584
601
 
585
- # Check the status of background image removal.
602
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
586
603
  Uploadcare::Addons.remove_bg_status('RETURNED_ID_FROM_REMOVE_BG')
587
604
  ```
588
605
 
@@ -721,6 +738,20 @@ More examples and options can be found [here](https://uploadcare.com/docs/transf
721
738
  ##### Document
722
739
 
723
740
  After each document file upload you obtain a file identifier in UUID format.
741
+
742
+ You can use file identifier to determine the document format and possible conversion formats.
743
+ ```ruby
744
+ Uploadcare::DocumentConverter.info("dc99200d-9bd6-4b43-bfa9-aa7bfaefca40")
745
+
746
+ # Response
747
+ {:error=>nil, :format=>{
748
+ :name=>"jpg",
749
+ :conversion_formats=>[
750
+ {:name=>"avif"}, {:name=>"bmp"}, {:name=>"gif"}, {:name=>"ico"}, {:name=>"pcx"}, {:name=>"pdf"}, {:name=>"png"}, {:name=>"ps"}, {:name=>"svg"}, {:name=>"tga"}, {:name=>"thumbnail"}, {:name=>"tiff"}, {:name=>"wbmp"}, {:name=>"webp"}
751
+ ]
752
+ }}
753
+ ```
754
+
724
755
  Then you can use this file identifier to convert your document to a new format:
725
756
 
726
757
  ```ruby
@@ -821,15 +852,29 @@ More examples and options can be found [here](https://uploadcare.com/docs/transf
821
852
 
822
853
  You can use custom domain and CDN provider to deliver files with authenticated URLs (see [original documentation](https://uploadcare.com/docs/security/secure_delivery/)).
823
854
 
824
- To generate authenticated URL from the library, you should choose `Uploadcare::SignedUrlGenerators::AmakaiGenerator` (or create your generator implementation):
855
+ To generate authenticated URL from the library, you should choose `Uploadcare::SignedUrlGenerators::AkamaiGenerator` (or create your own generator implementation):
856
+
825
857
  ```ruby
826
- generator = Uploadcare::SignedUrlGenerators::AmakaiGenerator.new(cdn_host: 'example.com', secret_key: 'secret_key'). Optional parameters: ttl: 300, algorithm: 'sha256'
858
+ generator = Uploadcare::SignedUrlGenerators::AkamaiGenerator.new(cdn_host: 'example.com', secret_key: 'secret_key')
859
+ # Optional parameters: ttl: 300, algorithm: 'sha256'
827
860
  generator.generate_url(uuid, acl = optional)
828
861
 
829
- generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3") ->
830
- https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/a7d5645e-5cd7-4046-819f-a6a2933bafe3/~hmac=a989cae5342f17013677f5a0e6577fc5594cc4e238fb4c95eda36634eb47018b
831
- generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3", '/*/') ->
832
- https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/*/~hmac=3ce1152c6af8864b36d4dc721f08ca3cf0b3a20278d7f849e82c6c930d48ccc1
862
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3")
863
+ # https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/a7d5645e-5cd7-4046-819f-a6a2933bafe3/~hmac=a989cae5342f17013677f5a0e6577fc5594cc4e238fb4c95eda36634eb47018b
864
+
865
+ # You can pass in ACL as a second parameter to generate_url. See https://uploadcare.com/docs/security/secure-delivery/#authenticated-urls for supported acl formats
866
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3", '/*/')
867
+ # https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1649405263~acl=/*/~hmac=3ce1152c6af8864b36d4dc721f08ca3cf0b3a20278d7f849e82c6c930d48ccc1
868
+
869
+ # Optionally you can use wildcard: true to generate a wildcard acl token
870
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3", wildcard: true)
871
+ # https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1714233449~acl=/a7d5645e-5cd7-4046-819f-a6a2933bafe3/*~hmac=a568ee2a85dd90a8a8a1ef35ea0cc0ef0acb84fe81990edd3a06eacf10a52b4e
872
+
873
+ # You can also pass in a custom ttl and algorithm to AkamaiGenerator
874
+ generator = Uploadcare::SignedUrlGenerators::AkamaiGenerator.new(cdn_host: 'example.com', secret_key: 'secret_key', ttl: 10)
875
+ generator.generate_url("a7d5645e-5cd7-4046-819f-a6a2933bafe3")
876
+ # This generates a URL that expires in 10 seconds
877
+ # https://example.com/a7d5645e-5cd7-4046-819f-a6a2933bafe3/?token=exp=1714233277~acl=/a7d5645e-5cd7-4046-819f-a6a2933bafe3/~hmac=f25343104aeced3004d2cc4d49807d8d7c732300b54b154c319da5283a871a71
833
878
  ```
834
879
  ## Useful links
835
880
 
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuids = %w[21975c81-7f57-4c7a-aef9-acfe28779f78 cbaf2d73-5169-4b2b-a543-496cf2813dff]
6
+ puts Uploadcare::FileList.batch_delete(uuids)
@@ -0,0 +1,5 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ puts Uploadcare::FileMetadata.delete('1bac376c-aa7e-4356-861b-dd2657b5bfd2', 'pet')
@@ -0,0 +1,5 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ puts Uploadcare::File.delete('1bac376c-aa7e-4356-861b-dd2657b5bfd2')
@@ -0,0 +1,5 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ puts Uploadcare::Group.delete('c5bec8c7-d4b6-4921-9e55-6edb027546bc~1')
@@ -0,0 +1,5 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ puts Uploadcare::Webhook.delete('https://yourwebhook.com')
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ request_id = 'd1fb31c6-ed34-4e21-bdc3-4f1485f58e21'
6
+ result = Uploadcare::Addons.ws_rekognition_detect_labels_status(request_id)
7
+ puts result.status
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ request_id = 'd1fb31c6-ed34-4e21-bdc3-4f1485f58e21'
6
+ result = Uploadcare::Addons.ws_rekognition_detect_moderation_labels_status(request_id)
7
+ puts result.status
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ request_id = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ result = Uploadcare::Addons.remove_bg_status(request_id)
7
+ puts result.status
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ request_id = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ result = Uploadcare::Addons.uc_clamav_virus_scan_status(request_id)
7
+ puts result.status
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ token = 32_921_143
6
+ puts Uploadcare::DocumentConverter.status(token)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '740e1b8c-1ad8-4324-b7ec-112c79d8eac2'
6
+ puts Uploadcare::DocumentConverter.info(uuid)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ token = 1_201_016_744
6
+ puts Uploadcare::VideoConverter.status(token)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ list = Uploadcare::FileList.file_list(stored: true, removed: false, limit: 100)
6
+ list.each { |file| puts file.inspect }
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ puts Uploadcare::File.info(uuid).inspect
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ puts Uploadcare::FileMetadata.show(uuid, 'pet')
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ puts Uploadcare::FileMetadata.index(uuid).inspect
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ groups = Uploadcare::GroupList.list(limit: 10)
6
+ groups.each { |group| puts group.inspect }
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = 'c5bec8c7-d4b6-4921-9e55-6edb027546bc~1'
6
+ puts Uploadcare::Group.info(uuid).inspect
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ project_info = Uploadcare::Project.show
6
+ puts project_info.inspect
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ webhooks = Uploadcare::Webhook.list
6
+ webhooks.each { |webhook| puts webhook.inspect }
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ Uploadcare::Addons.ws_rekognition_detect_labels(uuid)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ Uploadcare::Addons.ws_rekognition_detect_moderation_labels(uuid)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ Uploadcare::Addons.remove_bg(uuid, crop: true)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ Uploadcare::Addons.uc_clamav_virus_scan(uuid, purge_infected: true)
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ document_params = { uuid: '1bac376c-aa7e-4356-861b-dd2657b5bfd2', format: :pdf }
6
+ options = { store: true }
7
+ Uploadcare::DocumentConverter.convert(document_params, options)
@@ -0,0 +1,11 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ video_params = {
6
+ uuid: '1bac376c-aa7e-4356-861b-dd2657b5bfd2',
7
+ format: :mp4,
8
+ quality: :lighter
9
+ }
10
+ options = { store: true }
11
+ Uploadcare::VideoConverter.convert(video_params, options)
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ source = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ copied_file = Uploadcare::File.local_copy(source, store: true)
7
+ puts copied_file.uuid
@@ -0,0 +1,8 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ source_object = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ target = 'custom_storage_connected_to_the_project'
7
+ copied_file_url = Uploadcare::File.remote_copy(source_object, target, make_public: true)
8
+ puts copied_file_url
@@ -0,0 +1,10 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ options = {
6
+ target_url: 'https://yourwebhook.com',
7
+ event: 'file.uploaded',
8
+ is_active: true
9
+ }
10
+ Uploadcare::Webhook.create(**options)
@@ -0,0 +1,9 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuids = %w[
6
+ b7a301d1-1bd0-473d-8d32-708dd55addc0
7
+ 1bac376c-aa7e-4356-861b-dd2657b5bfd2
8
+ ]
9
+ Uploadcare::FileList.batch_store(uuids)
@@ -0,0 +1,8 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ key = 'pet'
7
+ value = 'dog'
8
+ Uploadcare::FileMetadata.update(uuid, key, value)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
6
+ Uploadcare::File.store(uuid)
@@ -0,0 +1,12 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ webhook_id = 1_473_151
6
+ options = {
7
+ target_url: 'https://yourwebhook.com',
8
+ event: 'file.uploaded',
9
+ is_active: true,
10
+ signing_secret: 'webhook-secret'
11
+ }
12
+ Uploadcare::Webhook.update(webhook_id, options)
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ token = '945ebb27-1fd6-46c6-a859-b9893712d650'
6
+ puts Uploadcare::Uploader.get_upload_from_url_status(token)
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '0d712319-b970-4602-850c-bae1ced521a6~1'
6
+ info = Uploadcare::Group.info(uuid)
7
+ puts info.inspect
@@ -0,0 +1,7 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuid = '740e1b8c-1ad8-4324-b7ec-112c79d8eac2'
6
+ info = Uploadcare::File.info(uuid)
7
+ puts info.inspect
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ source_file = File.open('image.png')
6
+ Uploadcare::Uploader.upload(source_file, store: 'auto')
@@ -0,0 +1,6 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ source_url = 'https://source.unsplash.com/featured'
6
+ Uploadcare::Uploader.upload(source_url, store: 'auto')
@@ -0,0 +1,9 @@
1
+ require 'uploadcare'
2
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
3
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
4
+
5
+ uuids = [
6
+ 'd6d34fa9-addd-472c-868d-2e5c105f9fcd',
7
+ 'b1026315-8116-4632-8364-607e64fca723/-/resize/x800/'
8
+ ]
9
+ Uploadcare::Group.create(uuids)
@@ -0,0 +1,8 @@
1
+ # Uploadcare lib provides high level API for multipart uploads that does everything for you
2
+
3
+ require 'uploadcare'
4
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
5
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
6
+
7
+ source_file = File.open('image.png')
8
+ Uploadcare::Uploader.upload(source_file, store: 'auto')
@@ -0,0 +1,8 @@
1
+ # Uploadcare lib provides high level API for multipart uploads that does everything for you
2
+
3
+ require 'uploadcare'
4
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
5
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
6
+
7
+ source_file = File.open('image.png')
8
+ Uploadcare::Uploader.upload(source_file, store: 'auto')
@@ -0,0 +1,8 @@
1
+ # Uploadcare lib provides high level API for multipart uploads that does everything for you
2
+
3
+ require 'uploadcare'
4
+ Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
5
+ Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'
6
+
7
+ source_file = File.open('image.png')
8
+ Uploadcare::Uploader.upload(source_file, store: 'auto')
@@ -46,6 +46,19 @@ module Uploadcare
46
46
  get(uri: "/addons/remove_bg/execute/status/#{query_params(uuid)}")
47
47
  end
48
48
 
49
+ # Execute AWS Rekognition Moderation Add-On for a given target to detect labels in an image.
50
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionDetectModerationLabelsExecute
51
+ def ws_rekognition_detect_moderation_labels(uuid)
52
+ content = { target: uuid }.to_json
53
+ post(uri: '/addons/aws_rekognition_detect_moderation_labels/execute/', content: content)
54
+ end
55
+
56
+ # Check the status of an Add-On execution request that had been started using the Execute Add-On operation.
57
+ # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionDetectModerationLabelsExecutionStatus
58
+ def ws_rekognition_detect_moderation_labels_status(uuid)
59
+ get(uri: "/addons/aws_rekognition_detect_moderation_labels/execute/status/#{query_params(uuid)}")
60
+ end
61
+
49
62
  private
50
63
 
51
64
  def query_params(uuid)
@@ -22,6 +22,10 @@ module Uploadcare
22
22
  get(uri: "/convert/document/status/#{token}/")
23
23
  end
24
24
 
25
+ def document_info(uuid)
26
+ get(uri: "/convert/document/#{uuid}/")
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def convert_uri
@@ -47,7 +47,7 @@ module Uploadcare
47
47
  private
48
48
 
49
49
  def form_data_for(file)
50
- form_data_file = super(file)
50
+ form_data_file = super
51
51
  {
52
52
  filename: form_data_file.filename,
53
53
  size: form_data_file.size,
@@ -9,7 +9,7 @@ module Uploadcare
9
9
  class << self
10
10
  # Converts files
11
11
  #
12
- # @param doc_params [Array] of hashes with params or [Hash]
12
+ # @param params [Array] of hashes with params or [Hash]
13
13
  # @option options [Boolean] :store whether to store file on servers.
14
14
  def convert(params, options = {})
15
15
  files_params = params.is_a?(Hash) ? [params] : params
@@ -23,6 +23,13 @@ module Uploadcare
23
23
  conversion_client.new.get_conversion_status(token)
24
24
  end
25
25
 
26
+ # Returns the document format and possible conversion formats.
27
+ #
28
+ # @param uuid [String] UUID of the document
29
+ def info(uuid)
30
+ conversion_client.new.document_info(uuid)
31
+ end
32
+
26
33
  private
27
34
 
28
35
  def conversion_client
@@ -15,6 +15,11 @@ module Uploadcare
15
15
 
16
16
  attr_entity(*RESPONSE_PARAMS)
17
17
 
18
+ def datetime_stored
19
+ Uploadcare.config.logger&.warn 'datetime_stored property has been deprecated, and will be removed without a replacement in future.' # rubocop:disable Layout/LineLength
20
+ @entity.datetime_stored
21
+ end
22
+
18
23
  # gets file's uuid - even if it's only initialized with url
19
24
  # @returns [String]
20
25
  def uuid
@@ -59,8 +64,7 @@ module Uploadcare
59
64
  #
60
65
  # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createRemoteCopy
61
66
  def self.remote_copy(source, target, args = {})
62
- response = FileClient.new.remote_copy(source: source, target: target, **args).success[:result]
63
- File.new(response)
67
+ FileClient.new.remote_copy(source: source, target: target, **args).success[:result]
64
68
  end
65
69
 
66
70
  # Instance version of {internal_copy}
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uploadcare
4
+ module Exception
5
+ # Invalid Auth configuration error
6
+ class AuthError < StandardError; end
7
+ end
8
+ end
@@ -11,6 +11,7 @@ module Uploadcare
11
11
  class AuthenticationHeader
12
12
  # @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare
13
13
  def self.call(options = {})
14
+ validate_auth_config
14
15
  case Uploadcare.config.auth_type
15
16
  when 'Uploadcare'
16
17
  SecureAuthHeader.call(options)
@@ -20,6 +21,17 @@ module Uploadcare
20
21
  raise ArgumentError, "Unknown auth_scheme: '#{Uploadcare.config.auth_type}'"
21
22
  end
22
23
  end
24
+
25
+ def self.validate_auth_config
26
+ raise Uploadcare::Exception::AuthError, 'Public Key is blank.' if is_blank?(Uploadcare.config.public_key)
27
+ raise Uploadcare::Exception::AuthError, 'Secret Key is blank.' if is_blank?(Uploadcare.config.secret_key)
28
+ end
29
+
30
+ # rubocop:disable Naming/PredicateName
31
+ def self.is_blank?(value)
32
+ value.nil? || value.empty?
33
+ end
34
+ # rubocop:enable Naming/PredicateName
23
35
  end
24
36
  end
25
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploadcare
4
- VERSION = '4.4.0'
4
+ VERSION = '4.4.2'
5
5
  end
@@ -4,20 +4,21 @@ require_relative 'base_generator'
4
4
 
5
5
  module Uploadcare
6
6
  module SignedUrlGenerators
7
- class AmakaiGenerator < Uploadcare::SignedUrlGenerators::BaseGenerator
7
+ class AkamaiGenerator < Uploadcare::SignedUrlGenerators::BaseGenerator
8
8
  UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}'
9
9
  TEMPLATE = 'https://{cdn_host}/{uuid}/?token=exp={expiration}{delimiter}acl={acl}{delimiter}hmac={token}'
10
10
 
11
- def generate_url(uuid, acl = uuid)
11
+ def generate_url(uuid, acl = uuid, wildcard: false)
12
12
  raise ArgumentError, 'Must contain valid UUID' unless valid?(uuid)
13
13
 
14
+ formatted_acl = build_acl(uuid, acl, wildcard: wildcard)
14
15
  expire = build_expire
15
- signature = build_signature(expire, acl)
16
+ signature = build_signature(expire, formatted_acl)
16
17
 
17
18
  TEMPLATE.gsub('{delimiter}', delimiter)
18
19
  .sub('{cdn_host}', sanitized_string(cdn_host))
19
20
  .sub('{uuid}', sanitized_string(uuid))
20
- .sub('{acl}', "/#{sanitized_string(acl)}/")
21
+ .sub('{acl}', formatted_acl)
21
22
  .sub('{expiration}', expire)
22
23
  .sub('{token}', signature)
23
24
  end
@@ -32,13 +33,22 @@ module Uploadcare
32
33
  '~'
33
34
  end
34
35
 
36
+ def build_acl(uuid, acl, wildcard: false)
37
+ if wildcard
38
+ "/#{sanitized_string(uuid)}/*"
39
+ else
40
+ "/#{sanitized_string(acl)}/"
41
+ end
42
+ end
43
+
35
44
  def build_expire
36
45
  (Time.now.to_i + ttl).to_s
37
46
  end
38
47
 
39
48
  def build_signature(expire, acl)
40
- signature = ["exp=#{expire}", "acl=/#{sanitized_string(acl)}/"].join(delimiter)
41
- OpenSSL::HMAC.hexdigest(algorithm, secret_key, signature)
49
+ signature = ["exp=#{expire}", "acl=#{acl}"].join(delimiter)
50
+ secret_key_bin = Array(secret_key.gsub(/\s/, '')).pack('H*')
51
+ OpenSSL::HMAC.hexdigest(algorithm, secret_key_bin, signature)
42
52
  end
43
53
 
44
54
  # rubocop:disable Style/SlicingWithRange
data/lib/uploadcare.rb CHANGED
@@ -7,6 +7,7 @@ require 'ruby/version'
7
7
  require 'exception/throttle_error'
8
8
  require 'exception/request_error'
9
9
  require 'exception/retry_error'
10
+ require 'exception/auth_error'
10
11
 
11
12
  # Entities
12
13
  require 'entity/entity'
@@ -25,7 +26,7 @@ require 'param/webhook_signature_verifier'
25
26
  require 'api/api'
26
27
 
27
28
  # SignedUrlGenerators
28
- require 'signed_url_generators/amakai_generator'
29
+ require 'signed_url_generators/akamai_generator'
29
30
  require 'signed_url_generators/base_generator'
30
31
 
31
32
  # Ruby wrapper for Uploadcare API
@@ -49,4 +50,5 @@ module Uploadcare
49
50
  setting :upload_threads, default: 2 # used for multiupload only ATM
50
51
  setting :framework_data, default: ''
51
52
  setting :file_chunk_size, default: 100
53
+ setting :logger, default: Logger.new($stdout)
52
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@dmitrijivanchenko (Dmitrij Ivanchenko), @T0mbery (Andrey Aksenov)"
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-03-09 00:00:00.000000000 Z
12
+ date: 2024-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mimemagic
@@ -93,6 +93,48 @@ files:
93
93
  - LICENSE
94
94
  - README.md
95
95
  - Rakefile
96
+ - api_examples/rest_api/delete_files_storage.rb
97
+ - api_examples/rest_api/delete_files_uuid_metadata_key.rb
98
+ - api_examples/rest_api/delete_files_uuid_storage.rb
99
+ - api_examples/rest_api/delete_groups_uuid.rb
100
+ - api_examples/rest_api/delete_webhooks_unsubscribe.rb
101
+ - api_examples/rest_api/get_addons_aws_rekognition_detect_labels_execute_status.rb
102
+ - api_examples/rest_api/get_addons_aws_rekognition_detect_moderation_labels_execute_status.rb
103
+ - api_examples/rest_api/get_addons_remove_bg_execute_status.rb
104
+ - api_examples/rest_api/get_addons_uc_clamav_virus_scan_execute_status.rb
105
+ - api_examples/rest_api/get_convert_document_status_token.rb
106
+ - api_examples/rest_api/get_convert_document_uuid.rb
107
+ - api_examples/rest_api/get_convert_video_status_token.rb
108
+ - api_examples/rest_api/get_files.rb
109
+ - api_examples/rest_api/get_files_uuid.rb
110
+ - api_examples/rest_api/get_files_uuid_metadata.rb
111
+ - api_examples/rest_api/get_files_uuid_metadata_key.rb
112
+ - api_examples/rest_api/get_groups.rb
113
+ - api_examples/rest_api/get_groups_uuid.rb
114
+ - api_examples/rest_api/get_project.rb
115
+ - api_examples/rest_api/get_webhooks.rb
116
+ - api_examples/rest_api/post_addons_aws_rekognition_detect_labels_execute.rb
117
+ - api_examples/rest_api/post_addons_aws_rekognition_detect_moderation_labels_execute.rb
118
+ - api_examples/rest_api/post_addons_remove_bg_execute.rb
119
+ - api_examples/rest_api/post_addons_uc_clamav_virus_scan_execute.rb
120
+ - api_examples/rest_api/post_convert_document.rb
121
+ - api_examples/rest_api/post_convert_video.rb
122
+ - api_examples/rest_api/post_files_local_copy.rb
123
+ - api_examples/rest_api/post_files_remote_copy.rb
124
+ - api_examples/rest_api/post_webhooks.rb
125
+ - api_examples/rest_api/put_files_storage.rb
126
+ - api_examples/rest_api/put_files_uuid_metadata_key.rb
127
+ - api_examples/rest_api/put_files_uuid_storage.rb
128
+ - api_examples/rest_api/put_webhooks_id.rb
129
+ - api_examples/upload_api/get_from_url_status.rb
130
+ - api_examples/upload_api/get_group_info.rb
131
+ - api_examples/upload_api/get_info.rb
132
+ - api_examples/upload_api/post_base.rb
133
+ - api_examples/upload_api/post_from_url.rb
134
+ - api_examples/upload_api/post_group.rb
135
+ - api_examples/upload_api/post_multipart_complete.rb
136
+ - api_examples/upload_api/post_multipart_start.rb
137
+ - api_examples/upload_api/put_presigned_url_x.rb
96
138
  - bin/console
97
139
  - bin/setup
98
140
  - lib/uploadcare.rb
@@ -130,6 +172,7 @@ files:
130
172
  - lib/uploadcare/entity/project.rb
131
173
  - lib/uploadcare/entity/uploader.rb
132
174
  - lib/uploadcare/entity/webhook.rb
175
+ - lib/uploadcare/exception/auth_error.rb
133
176
  - lib/uploadcare/exception/conversion_error.rb
134
177
  - lib/uploadcare/exception/request_error.rb
135
178
  - lib/uploadcare/exception/retry_error.rb
@@ -145,7 +188,7 @@ files:
145
188
  - lib/uploadcare/param/user_agent.rb
146
189
  - lib/uploadcare/param/webhook_signature_verifier.rb
147
190
  - lib/uploadcare/ruby/version.rb
148
- - lib/uploadcare/signed_url_generators/amakai_generator.rb
191
+ - lib/uploadcare/signed_url_generators/akamai_generator.rb
149
192
  - lib/uploadcare/signed_url_generators/base_generator.rb
150
193
  - uploadcare-ruby.gemspec
151
194
  homepage: https://uploadcare.com/
@@ -176,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
219
  - !ruby/object:Gem::Version
177
220
  version: '0'
178
221
  requirements: []
179
- rubygems_version: 3.5.3
222
+ rubygems_version: 3.5.9
180
223
  signing_key:
181
224
  specification_version: 4
182
225
  summary: Ruby wrapper for uploadcare API