Skip to content

Commit 293bd86

Browse files
authored
Merge pull request #63 from imagekit-developer/IK-1499
added checks parameter
2 parents 316b1ae + 7f36c9d commit 293bd86

File tree

6 files changed

+104
-6
lines changed

6 files changed

+104
-6
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ gemspec
2020
group :test do
2121
gem "minitest", "~> 5.0"
2222
gem "rspec"
23-
gem 'codecov'
23+
gem 'simplecov'
24+
# gem 'codecov'
2425
gem 'webmock'
2526
gem 'byebug'
2627
end

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ imagekitio.upload_file(
452452
value: 'w-100'
453453
}
454454
]
455-
}
455+
},
456+
checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
457+
is_published: true
456458
)
457459

458460
```
@@ -479,6 +481,7 @@ imagekitio.list_files(
479481
)
480482
```
481483
**Get File Details**
484+
482485
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)
483486

484487
```ruby
@@ -488,6 +491,7 @@ imagekitio.get_file_details(
488491
```
489492

490493
**Get File Metadata**
494+
491495
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)
492496
```ruby
493497
imagekit.get_file_metadata(
@@ -496,6 +500,7 @@ imagekit.get_file_metadata(
496500
```
497501

498502
**Get File Metadata from remote url**
503+
499504
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)
500505

501506
```ruby
@@ -505,6 +510,7 @@ imagekit.get_remote_file_url_metadata(
505510
```
506511

507512
**Update File Details**
513+
508514
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
509515
The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
510516
parameters to be updated.
@@ -517,6 +523,21 @@ imagekitio.update_file_details(
517523
)
518524
```
519525

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+
520541
**Copy File**
521542

522543
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

+1-1
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 ]
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

lib/imagekitio/sdk/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ImageKitIo
22
module Sdk
3-
VERSION = '3.0.0'
3+
VERSION = '3.1.0'
44
end
55
end

test/imagekit/api_service/file_test.rb

+76
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,57 @@
253253
expect(upload[:status_code]).to eq(200)
254254

255255
end
256+
257+
it "test_upload_with_checks" do
258+
request_obj = double
259+
allow(ImageKitIo::Request)
260+
.to receive(:new)
261+
.with(private_key, public_key, url_endpoint)
262+
.and_return(request_obj)
263+
264+
allow(request_obj)
265+
.to receive(:create_headers)
266+
.and_return({})
267+
@ac={}
268+
allow(request_obj)
269+
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
270+
.and_return({status_code: 200})
271+
272+
SUT = file_api_service.new(request_obj)
273+
274+
upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", checks: '"file.size" < "1mb"')
275+
276+
expect(@ac[:payload]['checks']).to eq('"file.size" < "1mb"')
277+
278+
expect(upload[:status_code]).to eq(200)
279+
280+
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+
256307
end
257308

258309
describe 'FileListTest' do
@@ -787,6 +838,31 @@
787838
expect(resp[:body]).to eq(options)
788839
end
789840

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+
790866
it "test_update_file_details_fails_missing_arguments" do
791867
options = { tags: 'custom tag' }
792868
request_obj = double

test/imagekit/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require 'simplecov'
22
SimpleCov.start 'rails'
33

4-
require 'codecov'
5-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
4+
# require 'codecov'
5+
# SimpleCov.formatter = SimpleCov::Formatter::Codecov
66

77
require 'base64'
88
require 'rspec'

0 commit comments

Comments
 (0)