Skip to content

Commit

Permalink
Merge pull request #63 from imagekit-developer/IK-1499
Browse files Browse the repository at this point in the history
added checks parameter
  • Loading branch information
ahnv authored Sep 6, 2024
2 parents 316b1ae + 7f36c9d commit 293bd86
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ gemspec
group :test do
gem "minitest", "~> 5.0"
gem "rspec"
gem 'codecov'
gem 'simplecov'
# gem 'codecov'
gem 'webmock'
gem 'byebug'
end
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ imagekitio.upload_file(
value: 'w-100'
}
]
}
},
checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
is_published: true
)

```
Expand All @@ -479,6 +481,7 @@ imagekitio.list_files(
)
```
**Get File Details**

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)

```ruby
Expand All @@ -488,6 +491,7 @@ imagekitio.get_file_details(
```

**Get File Metadata**

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)
```ruby
imagekit.get_file_metadata(
Expand All @@ -496,6 +500,7 @@ imagekit.get_file_metadata(
```

**Get File Metadata from remote url**

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)

```ruby
Expand All @@ -505,6 +510,7 @@ imagekit.get_remote_file_url_metadata(
```

**Update File Details**

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


**Update publish status**

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`.

```ruby
imagekitio.update_file_details(
file_id: '598821f949c0a938d57563bd',
publish:{
isPublished: true,
includeFileVersions: true
}
)
```

**Copy File**

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)
Expand Down
2 changes: 1 addition & 1 deletion lib/imagekitio/constants/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module File

VALID_FILE_DETAIL_OPTIONS = ["fileID"]

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 ]
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]
end
end
end
2 changes: 1 addition & 1 deletion lib/imagekitio/sdk/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ImageKitIo
module Sdk
VERSION = '3.0.0'
VERSION = '3.1.0'
end
end
76 changes: 76 additions & 0 deletions test/imagekit/api_service/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,57 @@
expect(upload[:status_code]).to eq(200)

end

it "test_upload_with_checks" do
request_obj = double
allow(ImageKitIo::Request)
.to receive(:new)
.with(private_key, public_key, url_endpoint)
.and_return(request_obj)

allow(request_obj)
.to receive(:create_headers)
.and_return({})
@ac={}
allow(request_obj)
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
.and_return({status_code: 200})

SUT = file_api_service.new(request_obj)

upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", checks: '"file.size" < "1mb"')

expect(@ac[:payload]['checks']).to eq('"file.size" < "1mb"')

expect(upload[:status_code]).to eq(200)

end

it "test_upload_with_is_published" do
request_obj = double
allow(ImageKitIo::Request)
.to receive(:new)
.with(private_key, public_key, url_endpoint)
.and_return(request_obj)

allow(request_obj)
.to receive(:create_headers)
.and_return({})
@ac={}
allow(request_obj)
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
.and_return({status_code: 200})

SUT = file_api_service.new(request_obj)

upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", is_published: true )

expect(@ac[:payload]['isPublished']).to eq("true")

expect(upload[:status_code]).to eq(200)

end

end

describe 'FileListTest' do
Expand Down Expand Up @@ -787,6 +838,31 @@
expect(resp[:body]).to eq(options)
end

it "test_update_file_publication_status" do
options = { publish: { isPublished: true, includeFileVersions: true }}
request_obj = double
allow(ImageKitIo::Request)
.to receive(:new)
.with(private_key, public_key, url_endpoint)
.and_return(request_obj)

allow(request_obj)
.to receive(:create_headers)
.and_return({})

allow(request_obj)
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
.and_return({status_code: 200, body: options})

SUT = file_api_service.new(request_obj)
resp = SUT.update_details(file_id: "file_id", **options)

expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:isPublished])
expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:includeFileVersions])
expect(resp[:status_code]).to eq(200)
expect(resp[:body]).to eq(options)
end

it "test_update_file_details_fails_missing_arguments" do
options = { tags: 'custom tag' }
request_obj = double
Expand Down
4 changes: 2 additions & 2 deletions test/imagekit/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'simplecov'
SimpleCov.start 'rails'

require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
# require 'codecov'
# SimpleCov.formatter = SimpleCov::Formatter::Codecov

require 'base64'
require 'rspec'
Expand Down

0 comments on commit 293bd86

Please sign in to comment.