diff --git a/Gemfile b/Gemfile index c0d710a9..c5777000 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/README.md b/README.md index dffb709c..20a7791d 100644 --- a/README.md +++ b/README.md @@ -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 ) ``` @@ -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 @@ -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( @@ -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 @@ -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. @@ -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) diff --git a/lib/imagekitio/constants/file.rb b/lib/imagekitio/constants/file.rb index 498e0d96..3af374dc 100644 --- a/lib/imagekitio/constants/file.rb +++ b/lib/imagekitio/constants/file.rb @@ -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 diff --git a/lib/imagekitio/sdk/version.rb b/lib/imagekitio/sdk/version.rb index c188581d..a9dac6ed 100644 --- a/lib/imagekitio/sdk/version.rb +++ b/lib/imagekitio/sdk/version.rb @@ -1,5 +1,5 @@ module ImageKitIo module Sdk - VERSION = '3.0.0' + VERSION = '3.1.0' end end diff --git a/test/imagekit/api_service/file_test.rb b/test/imagekit/api_service/file_test.rb index a2aa8cf4..8707faf3 100644 --- a/test/imagekit/api_service/file_test.rb +++ b/test/imagekit/api_service/file_test.rb @@ -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 @@ -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 diff --git a/test/imagekit/spec_helper.rb b/test/imagekit/spec_helper.rb index dc770008..433b4162 100644 --- a/test/imagekit/spec_helper.rb +++ b/test/imagekit/spec_helper.rb @@ -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'