Skip to content

Commit

Permalink
added publish option during update
Browse files Browse the repository at this point in the history
  • Loading branch information
ANKUR DWIVEDI authored and ANKUR DWIVEDI committed Sep 3, 2024
1 parent 6d7fcce commit 7f36c9d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ imagekitio.upload_file(
]
},
checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
is_published: true
)

```
Expand All @@ -480,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 @@ -489,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 @@ -497,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 @@ -506,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 @@ -518,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 checks]
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
51 changes: 51 additions & 0 deletions test/imagekit/api_service/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,32 @@
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 @@ -812,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

0 comments on commit 7f36c9d

Please sign in to comment.