Skip to content

Commit 7f36c9d

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
added publish option during update
1 parent 6d7fcce commit 7f36c9d

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ imagekitio.upload_file(
454454
]
455455
},
456456
checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
457+
is_published: true
457458
)
458459

459460
```
@@ -480,6 +481,7 @@ imagekitio.list_files(
480481
)
481482
```
482483
**Get File Details**
484+
483485
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)
484486

485487
```ruby
@@ -489,6 +491,7 @@ imagekitio.get_file_details(
489491
```
490492

491493
**Get File Metadata**
494+
492495
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)
493496
```ruby
494497
imagekit.get_file_metadata(
@@ -497,6 +500,7 @@ imagekit.get_file_metadata(
497500
```
498501

499502
**Get File Metadata from remote url**
503+
500504
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)
501505

502506
```ruby
@@ -506,6 +510,7 @@ imagekit.get_remote_file_url_metadata(
506510
```
507511

508512
**Update File Details**
513+
509514
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
510515
The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
511516
parameters to be updated.
@@ -518,6 +523,21 @@ imagekitio.update_file_details(
518523
)
519524
```
520525

526+
527+
**Update publish status**
528+
529+
If `publish` is included in the update options, no other parameters are allowed. If any are present, an error will be returned: `Your request cannot contain any other parameters when publish is present`.
530+
531+
```ruby
532+
imagekitio.update_file_details(
533+
file_id: '598821f949c0a938d57563bd',
534+
publish:{
535+
isPublished: true,
536+
includeFileVersions: true
537+
}
538+
)
539+
```
540+
521541
**Copy File**
522542

523543
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)

lib/imagekitio/constants/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module File
55

66
VALID_FILE_DETAIL_OPTIONS = ["fileID"]
77

8-
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type transformation checks]
8+
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type transformation checks is_published]
99
end
1010
end
1111
end

test/imagekit/api_service/file_test.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,32 @@
278278
expect(upload[:status_code]).to eq(200)
279279

280280
end
281+
282+
it "test_upload_with_is_published" do
283+
request_obj = double
284+
allow(ImageKitIo::Request)
285+
.to receive(:new)
286+
.with(private_key, public_key, url_endpoint)
287+
.and_return(request_obj)
288+
289+
allow(request_obj)
290+
.to receive(:create_headers)
291+
.and_return({})
292+
@ac={}
293+
allow(request_obj)
294+
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
295+
.and_return({status_code: 200})
296+
297+
SUT = file_api_service.new(request_obj)
298+
299+
upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", is_published: true )
300+
301+
expect(@ac[:payload]['isPublished']).to eq("true")
302+
303+
expect(upload[:status_code]).to eq(200)
304+
305+
end
306+
281307
end
282308

283309
describe 'FileListTest' do
@@ -812,6 +838,31 @@
812838
expect(resp[:body]).to eq(options)
813839
end
814840

841+
it "test_update_file_publication_status" do
842+
options = { publish: { isPublished: true, includeFileVersions: true }}
843+
request_obj = double
844+
allow(ImageKitIo::Request)
845+
.to receive(:new)
846+
.with(private_key, public_key, url_endpoint)
847+
.and_return(request_obj)
848+
849+
allow(request_obj)
850+
.to receive(:create_headers)
851+
.and_return({})
852+
853+
allow(request_obj)
854+
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
855+
.and_return({status_code: 200, body: options})
856+
857+
SUT = file_api_service.new(request_obj)
858+
resp = SUT.update_details(file_id: "file_id", **options)
859+
860+
expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:isPublished])
861+
expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:includeFileVersions])
862+
expect(resp[:status_code]).to eq(200)
863+
expect(resp[:body]).to eq(options)
864+
end
865+
815866
it "test_update_file_details_fails_missing_arguments" do
816867
options = { tags: 'custom tag' }
817868
request_obj = double

0 commit comments

Comments
 (0)