imagekitio 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +113 -39
- data/lib/imagekitio/api_service/file.rb +47 -2
- data/lib/imagekitio/api_service/folder.rb +2 -2
- data/lib/imagekitio/client.rb +20 -4
- data/lib/imagekitio/request.rb +10 -3
- data/lib/imagekitio/sdk/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aabd0c2da76f3f7008b3315212cc04f81434c6bb372dff4448176cf014db01c9
|
4
|
+
data.tar.gz: a9d42b5d5c729fc600ee01361dc78ee97200518f17bd196498a0ae543623b0b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1bdc9b382371fe0620bb4f0f834037d823063ae924c2806cf78f09ffa644308b0f7739484da388a279b48913ab79fe29228b0328c8d4c8c15674e0a293a7d7b
|
7
|
+
data.tar.gz: 5395acd1194c6a218de14e86cc9e60a3bfb06bb048743967c6645f7452cff7b1978a3fa2bbd72cd8508f061ffa08b4947c12b3f986638b04bd7fa4458b32f222
|
data/README.md
CHANGED
@@ -8,7 +8,9 @@
|
|
8
8
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
9
9
|
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
|
10
10
|
|
11
|
-
|
11
|
+
Ruby on Rails gem for [ImageKit](https://imagekit.io/) implements the new APIs and interface for different file operations.
|
12
|
+
|
13
|
+
ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
|
12
14
|
|
13
15
|
Table of contents -
|
14
16
|
* [Installation](#Installation)
|
@@ -155,20 +157,17 @@ imagekitio:
|
|
155
157
|
|
156
158
|
## Usage
|
157
159
|
|
158
|
-
You can use this Ruby SDK for three different methods - URL generation, file upload, and
|
160
|
+
You can use this Ruby SDK for three different methods - URL generation, file upload, and media management operations. The usage of the SDK has been explained below.
|
159
161
|
|
160
|
-
|
162
|
+
* `URL Generation`
|
163
|
+
* `File Upload`
|
164
|
+
* `File Management`
|
161
165
|
|
162
166
|
## URL generation
|
163
167
|
|
164
168
|
**1. Using Image path and image hostname or endpoint**
|
165
169
|
|
166
|
-
This method allows you to create
|
167
|
-
endpoint(url_endpoint) you want to use to access the image. You can refer to the documentation
|
168
|
-
[here](https://docs.imagekit.io/integration/url-endpoints) to read more about URL endpoints
|
169
|
-
in ImageKit and the section about [image origins](https://docs.imagekit.io/integration/configure-origin) to understand
|
170
|
-
about paths with different kinds of origins.
|
171
|
-
|
170
|
+
This method allows you to create an URL to access a file using the relative file path and the ImageKit URL endpoint (`urlEndpoint`). The file can be an image, video or any other static file supported by ImageKit.
|
172
171
|
|
173
172
|
```ruby
|
174
173
|
imagekitio = ImageKitIo.client
|
@@ -185,8 +184,7 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/defa
|
|
185
184
|
```
|
186
185
|
|
187
186
|
**2.Using full image URL**
|
188
|
-
This method allows you to add transformation parameters to an
|
189
|
-
database.
|
187
|
+
This method allows you to add transformation parameters to an absolute URL. For example, if you have configured a custom CNAME and have absolute asset URLs in your database or CMS, you will often need this.
|
190
188
|
|
191
189
|
|
192
190
|
```ruby
|
@@ -286,8 +284,7 @@ https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&i
|
|
286
284
|
|
287
285
|
**List of transformations**
|
288
286
|
|
289
|
-
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations).
|
290
|
-
The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
|
287
|
+
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations). The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
|
291
288
|
|
292
289
|
If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using the `url` function.
|
293
290
|
|
@@ -385,7 +382,7 @@ be `None`.
|
|
385
382
|
The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
|
386
383
|
to manage your files. This also returns `error` and `result`. The `error` will be `None` if API succeeds.
|
387
384
|
|
388
|
-
**
|
385
|
+
**List & Search Files**
|
389
386
|
|
390
387
|
Accepts an object specifying the parameters to be used to list and search files. All parameters specified
|
391
388
|
in the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files#list-and-search-file-api) can be passed with the
|
@@ -397,7 +394,7 @@ imagekitio.list_files(
|
|
397
394
|
limit: 5
|
398
395
|
)
|
399
396
|
```
|
400
|
-
**
|
397
|
+
**Get File Details**
|
401
398
|
Accepts the file ID and fetches the details as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-details)
|
402
399
|
|
403
400
|
```ruby
|
@@ -406,7 +403,7 @@ imagekitio.get_file_details(
|
|
406
403
|
)
|
407
404
|
```
|
408
405
|
|
409
|
-
**
|
406
|
+
**Get File Metadata**
|
410
407
|
Accepts the file ID and fetches the metadata as per the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files)
|
411
408
|
```ruby
|
412
409
|
imagekit.get_file_metadata(
|
@@ -414,7 +411,7 @@ imagekit.get_file_metadata(
|
|
414
411
|
)
|
415
412
|
```
|
416
413
|
|
417
|
-
**
|
414
|
+
**Get File Metadata from remote url**
|
418
415
|
Accepts the remote file url and fetches the metadata as per the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-from-remote-url)
|
419
416
|
|
420
417
|
```ruby
|
@@ -423,7 +420,7 @@ imagekit.get_remote_file_url_metadata(
|
|
423
420
|
)
|
424
421
|
```
|
425
422
|
|
426
|
-
**
|
423
|
+
**Update File Details**
|
427
424
|
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
|
428
425
|
The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
|
429
426
|
parameters to be updated.
|
@@ -436,18 +433,19 @@ imagekitio.update_file_details(
|
|
436
433
|
)
|
437
434
|
```
|
438
435
|
|
439
|
-
**
|
436
|
+
**Copy File**
|
440
437
|
|
441
438
|
Copy file from one path to another path using the source file path and the destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-file)
|
442
439
|
|
443
440
|
```ruby
|
444
441
|
imagekitio.copy_file(
|
445
442
|
source_file_path: '/path/to/file.jpg',
|
446
|
-
destination_path: '/folder/to/copy/into'
|
443
|
+
destination_path: '/folder/to/copy/into',
|
444
|
+
include_file_versions: true #default false
|
447
445
|
)
|
448
446
|
```
|
449
447
|
|
450
|
-
**
|
448
|
+
**Move File**
|
451
449
|
|
452
450
|
Move file from one folder to another folder using the source file path and destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file)
|
453
451
|
|
@@ -458,7 +456,7 @@ imagekitio.move_file(
|
|
458
456
|
)
|
459
457
|
```
|
460
458
|
|
461
|
-
**
|
459
|
+
**Rename File**
|
462
460
|
|
463
461
|
Rename file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/rename-file)
|
464
462
|
|
@@ -470,7 +468,8 @@ imagekitio.rename_file(
|
|
470
468
|
)
|
471
469
|
```
|
472
470
|
|
473
|
-
**
|
471
|
+
**Delete File**
|
472
|
+
|
474
473
|
Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). The method accepts the file ID of the file that has to be deleted.
|
475
474
|
|
476
475
|
```ruby
|
@@ -478,8 +477,50 @@ imagekitio.delete_file(
|
|
478
477
|
file_id: '598821f949c0a938d57563bd'
|
479
478
|
)
|
480
479
|
```
|
480
|
+
**File versions**
|
481
|
+
|
482
|
+
Get all file versions as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-versions). The method accepts the file ID of the file.
|
483
|
+
|
484
|
+
```ruby
|
485
|
+
imagekitio.file_versions(
|
486
|
+
file_id: '598821f949c0a938d57563bd'
|
487
|
+
)
|
488
|
+
```
|
489
|
+
**File version details**
|
490
|
+
|
491
|
+
Get all file version detail as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details). The method accepts the file ID and version ID of the file.
|
492
|
+
|
493
|
+
```ruby
|
494
|
+
imagekitio.file_version_detail(
|
495
|
+
file_id: '598821f949c0a938d57563bd',
|
496
|
+
version_id: '846321f949c0a938d57567ty'
|
497
|
+
)
|
498
|
+
```
|
499
|
+
|
500
|
+
**Delete file version**
|
501
|
+
|
502
|
+
Delete file version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file-version). The method accepts the file ID and version ID of the file.
|
503
|
+
|
504
|
+
```ruby
|
505
|
+
imagekitio.delete_file_version(
|
506
|
+
file_id: '598821f949c0a938d57563bd',
|
507
|
+
version_id: '846321f949c0a938d57567ty'
|
508
|
+
)
|
509
|
+
```
|
510
|
+
|
511
|
+
**Restore file version**
|
512
|
+
|
513
|
+
Restore deleted file version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/restore-file-version). The method accepts the file ID and version ID of the file.
|
514
|
+
|
515
|
+
```ruby
|
516
|
+
imagekitio.restore_file_version(
|
517
|
+
file_id: '598821f949c0a938d57563bd',
|
518
|
+
version_id: '846321f949c0a938d57567ty'
|
519
|
+
)
|
520
|
+
```
|
521
|
+
|
522
|
+
**Bulk File Delete by IDs**
|
481
523
|
|
482
|
-
**9. Bulk File Delete by IDs**
|
483
524
|
Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-files-bulk). The method accepts a list of file IDs of files that has to be
|
484
525
|
deleted.
|
485
526
|
|
@@ -489,7 +530,7 @@ imagekitio.delete_bulk_files(
|
|
489
530
|
)
|
490
531
|
```
|
491
532
|
|
492
|
-
**
|
533
|
+
**Purge Cache**
|
493
534
|
Programmatically issue a clear cache request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
|
494
535
|
Accepts the full URL of the file for which the cache has to be cleared.
|
495
536
|
|
@@ -498,7 +539,7 @@ imagekitio.purge_file_cache(
|
|
498
539
|
file_url: 'https://ik.imagekit.io/demo/logo-white_SJwqB4Nfe.png'
|
499
540
|
)
|
500
541
|
```
|
501
|
-
**
|
542
|
+
**Purge Cache Status**
|
502
543
|
|
503
544
|
Get the purge cache request status using the request ID returned when a purge cache request gets submitted as per the
|
504
545
|
[API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)
|
@@ -509,7 +550,7 @@ imagekitio.purge_file_cache_status(
|
|
509
550
|
)
|
510
551
|
```
|
511
552
|
|
512
|
-
**
|
553
|
+
**Add Bulk Tags**
|
513
554
|
|
514
555
|
Add multiple tags on multiple files using an array of file ids and an array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/add-tags-bulk)
|
515
556
|
|
@@ -520,7 +561,7 @@ imagekitio.add_bulk_tags(
|
|
520
561
|
)
|
521
562
|
```
|
522
563
|
|
523
|
-
**
|
564
|
+
**Delete Bulk Tags**
|
524
565
|
|
525
566
|
Remove multiple tags from multiple files using an array of file ids and an array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-tags-bulk)
|
526
567
|
|
@@ -531,7 +572,7 @@ imagekitio.delete_bulk_tags(
|
|
531
572
|
)
|
532
573
|
```
|
533
574
|
|
534
|
-
**
|
575
|
+
**Delete Bulk AI Tags**
|
535
576
|
|
536
577
|
Delete bulk ai tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk)
|
537
578
|
|
@@ -542,7 +583,7 @@ imagekitio.delete_bulk_ai_tags(
|
|
542
583
|
)
|
543
584
|
```
|
544
585
|
|
545
|
-
**
|
586
|
+
**Create Folder**
|
546
587
|
|
547
588
|
Create folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/create-folder)
|
548
589
|
|
@@ -554,18 +595,19 @@ imagekitio.create_folder(
|
|
554
595
|
```
|
555
596
|
|
556
597
|
|
557
|
-
**
|
598
|
+
**Copy Folder**
|
558
599
|
|
559
600
|
Copy folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder)
|
560
601
|
|
561
602
|
```ruby
|
562
603
|
imagekitio.copy_folder(
|
563
604
|
source_folder_path: '/folder/to/copy',
|
564
|
-
destination_path: '/folder/to/copy/into'
|
605
|
+
destination_path: '/folder/to/copy/into',
|
606
|
+
include_file_versions: true #default false
|
565
607
|
)
|
566
608
|
```
|
567
609
|
|
568
|
-
**
|
610
|
+
**Move Folder**
|
569
611
|
|
570
612
|
Move folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder)
|
571
613
|
|
@@ -576,7 +618,7 @@ imagekitio.move_folder(
|
|
576
618
|
)
|
577
619
|
```
|
578
620
|
|
579
|
-
**
|
621
|
+
**Delete Folder**
|
580
622
|
|
581
623
|
Delete folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder)
|
582
624
|
|
@@ -586,7 +628,7 @@ imagekitio.delete_folder(
|
|
586
628
|
)
|
587
629
|
```
|
588
630
|
|
589
|
-
**
|
631
|
+
**Bulk Job Status**
|
590
632
|
|
591
633
|
Get the bulk job status as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status)
|
592
634
|
|
@@ -596,7 +638,7 @@ imagekitio.bulk_job_status(
|
|
596
638
|
)
|
597
639
|
```
|
598
640
|
|
599
|
-
**
|
641
|
+
**Create a custom metadata field**
|
600
642
|
|
601
643
|
Create custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
|
602
644
|
|
@@ -613,7 +655,7 @@ imagekitio.create_custom_metadata_field(
|
|
613
655
|
)
|
614
656
|
```
|
615
657
|
|
616
|
-
**
|
658
|
+
**Get Custom Metadata Fields**
|
617
659
|
|
618
660
|
Get the custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field)
|
619
661
|
|
@@ -623,7 +665,7 @@ imagekitio.get_custom_metadata_fields(
|
|
623
665
|
)
|
624
666
|
```
|
625
667
|
|
626
|
-
**
|
668
|
+
**Update Custom Metadata Fields**
|
627
669
|
|
628
670
|
Update custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)
|
629
671
|
|
@@ -635,7 +677,7 @@ imagekitio.update_custom_metadata_field(
|
|
635
677
|
)
|
636
678
|
```
|
637
679
|
|
638
|
-
**
|
680
|
+
**Delete Custom Metadata Fields**
|
639
681
|
|
640
682
|
Delete custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
|
641
683
|
|
@@ -645,6 +687,38 @@ imagekitio.delete_custom_metadata_field(
|
|
645
687
|
)
|
646
688
|
```
|
647
689
|
|
690
|
+
## Access request-id, other response headers and HTTP status code
|
691
|
+
|
692
|
+
Each media management function returns a hash with `response`, `error`, `status_code`, `headers`, `raw_body` keys with respective values.
|
693
|
+
|
694
|
+
```ruby
|
695
|
+
upload = imagekitio.upload_file(
|
696
|
+
file: file,
|
697
|
+
file_name: "default.jpg",
|
698
|
+
folder: '/test',
|
699
|
+
response_fields: 'tags,customCoordinates,isPrivateFile,metadata',
|
700
|
+
tags: %w[abc def],
|
701
|
+
use_unique_file_name: false,
|
702
|
+
is_private_file: true
|
703
|
+
)
|
704
|
+
puts upload[:status_code] # 200
|
705
|
+
puts upload[:headers]
|
706
|
+
|
707
|
+
# {
|
708
|
+
# "access-control-allow-origin"=>["*"],
|
709
|
+
# "x-ik-requestid"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
|
710
|
+
# "content-type"=>["application/json; charset=utf-8"],
|
711
|
+
# "content-length"=>["611"],
|
712
|
+
# "etag"=>["W/\"859-GOeZiRFGOZERjHBgRUhG0EGcODs\""],
|
713
|
+
# "date"=>["Wed, 29 Jun 2022 07:04:33 GMT"],
|
714
|
+
# "x-request-id"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
|
715
|
+
# "connection"=>["close"]
|
716
|
+
# }
|
717
|
+
|
718
|
+
|
719
|
+
puts upload[:raw_body]
|
720
|
+
# "{\"fileId\":\"62bjf980rb886bd691b86760\",\"name\":\"default.jpg\",\"size\":102117,\"versionInfo\":{\"id\":\"62bjf980rb886bd691b86760\",\"name\":\"Version 1\"},\"filePath\":\"/test/default.jpg\",\"url\":\"https://ik.imagekit.io/46865sdf6sdf/test/default.jpg\",\"fileType\":\"image\",\"height\":700,\"width\":1050,\"thumbnailUrl\":\"https://ik.imagekit.io/46865sdf6sdf/tr:n-ik_ml_thumbnail/test/default.jpg\",\"tags\":[\"abc\",\"def\"],\"AITags\":null,\"isPrivateFile\":true,\"customCoordinates\":null,\"metadata\":{\"height\":700,\"width\":1050,\"size\":102117,\"format\":\"jpg\",\"hasColorProfile\":true,\"quality\":0,\"density\":72,\"hasTransparency\":false,\"exif\":{},\"pHash\":\"90249d9b1fc74367\"}}"
|
721
|
+
```
|
648
722
|
|
649
723
|
## Utility functions
|
650
724
|
|
@@ -75,6 +75,51 @@ module ImageKitIo
|
|
75
75
|
@req_obj.request("get", url, headers, formatted_options)
|
76
76
|
end
|
77
77
|
|
78
|
+
def get_file_versions(file_id: nil)
|
79
|
+
if file_id == '' || file_id.nil?
|
80
|
+
raise ArgumentError, 'file_id is required'
|
81
|
+
end
|
82
|
+
url = "#{constants.BASE_URL}/#{file_id}/versions"
|
83
|
+
headers = @req_obj.create_headers
|
84
|
+
@req_obj.request('get', url, headers)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_file_version_detail(file_id: nil, version_id: nil)
|
88
|
+
if file_id == "" || file_id.nil?
|
89
|
+
raise ArgumentError, "file_id is required"
|
90
|
+
end
|
91
|
+
if version_id == "" || version_id.nil?
|
92
|
+
raise ArgumentError, "version_id is required"
|
93
|
+
end
|
94
|
+
url = "#{constants.BASE_URL}/#{file_id}/versions/#{version_id}"
|
95
|
+
headers = @req_obj.create_headers
|
96
|
+
@req_obj.request('get', url, headers)
|
97
|
+
end
|
98
|
+
|
99
|
+
def delete_file_version(file_id: nil, version_id: nil)
|
100
|
+
if file_id == "" || file_id.nil?
|
101
|
+
raise ArgumentError, "file_id is required"
|
102
|
+
end
|
103
|
+
if version_id == "" || version_id.nil?
|
104
|
+
raise ArgumentError, "version_id is required"
|
105
|
+
end
|
106
|
+
url = "#{constants.BASE_URL}/#{file_id}/versions/#{version_id}"
|
107
|
+
headers = @req_obj.create_headers
|
108
|
+
@req_obj.request('delete', url, headers)
|
109
|
+
end
|
110
|
+
|
111
|
+
def restore_file_version(file_id: nil, version_id: nil)
|
112
|
+
if file_id == "" || file_id.nil?
|
113
|
+
raise ArgumentError, "file_id is required"
|
114
|
+
end
|
115
|
+
if version_id == "" || version_id.nil?
|
116
|
+
raise ArgumentError, "version_id is required"
|
117
|
+
end
|
118
|
+
url = "#{constants.BASE_URL}/#{file_id}/versions/#{version_id}/restore"
|
119
|
+
headers = @req_obj.create_headers
|
120
|
+
@req_obj.request('put', url, headers)
|
121
|
+
end
|
122
|
+
|
78
123
|
def details(file_identifier: nil)
|
79
124
|
# Get detail of file by file_identifier
|
80
125
|
if file_identifier == "" || file_identifier.nil?
|
@@ -138,12 +183,12 @@ module ImageKitIo
|
|
138
183
|
@req_obj.request_stream('get', remote_file_url, headers: @req_obj.create_headers, &block)
|
139
184
|
end
|
140
185
|
|
141
|
-
def copy(source_file_path: nil, destination_path: nil)
|
186
|
+
def copy(source_file_path: nil, destination_path: nil, include_file_versions: false)
|
142
187
|
if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
|
143
188
|
raise ArgumentError, 'parameters required'
|
144
189
|
end
|
145
190
|
url = "#{constants.BASE_URL}/copy"
|
146
|
-
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
|
191
|
+
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path, 'includeFileVersions': include_file_versions }.to_json
|
147
192
|
@req_obj.request('post', url, @req_obj.create_headers, payload)
|
148
193
|
end
|
149
194
|
|
@@ -27,12 +27,12 @@ module ImageKitIo
|
|
27
27
|
@req_obj.request('delete', url, @req_obj.create_headers, payload)
|
28
28
|
end
|
29
29
|
|
30
|
-
def copy(source_folder_path: nil, destination_path: nil)
|
30
|
+
def copy(source_folder_path: nil, destination_path: nil, include_file_versions: false)
|
31
31
|
if source_folder_path == '' || source_folder_path.nil? || destination_path == '' || destination_path.nil?
|
32
32
|
raise ArgumentError, 'Parameters required'
|
33
33
|
end
|
34
34
|
url = "#{constants.BULK_BASE_URL}/copyFolder"
|
35
|
-
payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path }
|
35
|
+
payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path, 'includeFileVersions': include_file_versions }.to_json
|
36
36
|
@req_obj.request('post', url, @req_obj.create_headers, payload)
|
37
37
|
end
|
38
38
|
|
data/lib/imagekitio/client.rb
CHANGED
@@ -65,6 +65,22 @@ module ImageKitIo
|
|
65
65
|
@file_service.list(**options)
|
66
66
|
end
|
67
67
|
|
68
|
+
def file_versions(file_id: nil)
|
69
|
+
@file_service.get_file_versions(file_id: file_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def file_version_detail(file_id: nil, version_id: nil)
|
73
|
+
@file_service.get_file_version_detail(file_id: file_id, version_id: version_id)
|
74
|
+
end
|
75
|
+
|
76
|
+
def delete_file_version(file_id: nil, version_id: nil)
|
77
|
+
@file_service.delete_file_version(file_id: file_id, version_id: version_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def restore_file_version(file_id: nil, version_id: nil)
|
81
|
+
@file_service.restore_file_version(file_id: file_id, version_id: version_id)
|
82
|
+
end
|
83
|
+
|
68
84
|
def get_file_details(file_id: nil)
|
69
85
|
# Get file detail by file-id or file_url
|
70
86
|
@file_service.details(file_identifier: file_id)
|
@@ -104,8 +120,8 @@ module ImageKitIo
|
|
104
120
|
@file_service.stream_file(remote_file_url: file_url, &block)
|
105
121
|
end
|
106
122
|
|
107
|
-
def copy_file(source_file_path: nil, destination_path: nil)
|
108
|
-
@file_service.copy(source_file_path: source_file_path, destination_path: destination_path)
|
123
|
+
def copy_file(source_file_path: nil, destination_path: nil, include_file_versions: false)
|
124
|
+
@file_service.copy(source_file_path: source_file_path, destination_path: destination_path, include_file_versions: include_file_versions)
|
109
125
|
end
|
110
126
|
|
111
127
|
def move_file(source_file_path: nil, destination_path: nil)
|
@@ -145,8 +161,8 @@ module ImageKitIo
|
|
145
161
|
@folder_service.delete(folder_path: folder_path)
|
146
162
|
end
|
147
163
|
|
148
|
-
def copy_folder(source_folder_path: nil, destination_path: nil)
|
149
|
-
@folder_service.copy(source_folder_path: source_folder_path, destination_path: destination_path)
|
164
|
+
def copy_folder(source_folder_path: nil, destination_path: nil, include_file_versions: false)
|
165
|
+
@folder_service.copy(source_folder_path: source_folder_path, destination_path: destination_path, include_file_versions: include_file_versions)
|
150
166
|
end
|
151
167
|
|
152
168
|
def move_folder(source_folder_path: nil, destination_path: nil)
|
data/lib/imagekitio/request.rb
CHANGED
@@ -42,14 +42,19 @@ module ImageKitIo
|
|
42
42
|
http.use_ssl = (uri.scheme == 'https')
|
43
43
|
req = Net::HTTP::Post::Multipart.new uri.path, payload, headers
|
44
44
|
resp = http.request(req)
|
45
|
-
|
46
|
-
raise RestClient::ExceptionWithResponse, OpenStruct.new(code: 400, body: resp.body)
|
47
|
-
end
|
45
|
+
response[:headers] = resp.to_hash
|
48
46
|
else
|
49
47
|
resp = RestClient::Request.new(method: method,
|
50
48
|
url: url,
|
51
49
|
headers: headers,
|
52
50
|
payload: payload).execute
|
51
|
+
response[:headers] = resp.raw_headers
|
52
|
+
end
|
53
|
+
response[:raw_body] = resp.body
|
54
|
+
response[:status_code] = resp.code
|
55
|
+
resp_c = resp.code.to_i
|
56
|
+
if [400, 403].include?(resp_c)
|
57
|
+
raise RestClient::ExceptionWithResponse, OpenStruct.new({ body: resp.body, code: resp_c, headers: response[:headers] })
|
53
58
|
end
|
54
59
|
if (resp.code.to_i >= 200) && (resp.code.to_i < 204)
|
55
60
|
content_type = resp.respond_to?(:headers) ? resp.headers[:content_type] : resp.content_type
|
@@ -63,6 +68,8 @@ module ImageKitIo
|
|
63
68
|
end
|
64
69
|
|
65
70
|
rescue RestClient::ExceptionWithResponse => err
|
71
|
+
response[:status_code] = err.http_code if response[:status_code].nil?
|
72
|
+
response[:headers] = err.http_headers if response[:headers].nil?
|
66
73
|
response[:error] = if err.http_code.to_i == 404
|
67
74
|
{'message': err.response.to_s}
|
68
75
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagekitio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ImageKit.io team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.3.7
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Automate image optimization on rails platforms.
|