Skip to content

Commit 97b7fe5

Browse files
committed
updated copy file and folder options
1 parent b45c4ef commit 97b7fe5

File tree

8 files changed

+19
-13
lines changed

8 files changed

+19
-13
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ Copy file from one path to another path using the source file path and the desti
443443
```ruby
444444
imagekitio.copy_file(
445445
source_file_path: '/path/to/file.jpg',
446-
destination_path: '/folder/to/copy/into'
446+
destination_path: '/folder/to/copy/into',
447+
include_file_versions: true #default false
447448
)
448449
```
449450

@@ -604,7 +605,8 @@ Copy folder as per the [API documentation here](https://docs.imagekit.io/api-ref
604605
```ruby
605606
imagekitio.copy_folder(
606607
source_folder_path: '/folder/to/copy',
607-
destination_path: '/folder/to/copy/into'
608+
destination_path: '/folder/to/copy/into',
609+
include_file_versions: true #default false
608610
)
609611
```
610612

lib/imagekitio/api_service/file.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ def stream_file(remote_file_url: nil, &block)
183183
@req_obj.request_stream('get', remote_file_url, headers: @req_obj.create_headers, &block)
184184
end
185185

186-
def copy(source_file_path: nil, destination_path: nil)
186+
def copy(source_file_path: nil, destination_path: nil, include_file_versions: false)
187187
if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
188188
raise ArgumentError, 'parameters required'
189189
end
190190
url = "#{constants.BASE_URL}/copy"
191-
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
191+
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path, 'includeFileVersions': include_file_versions }.to_json
192192
@req_obj.request('post', url, @req_obj.create_headers, payload)
193193
end
194194

lib/imagekitio/api_service/folder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def delete(folder_path: nil)
2727
@req_obj.request('delete', url, @req_obj.create_headers, payload)
2828
end
2929

30-
def copy(source_folder_path: nil, destination_path: nil)
30+
def copy(source_folder_path: nil, destination_path: nil, include_file_versions: false)
3131
if source_folder_path == '' || source_folder_path.nil? || destination_path == '' || destination_path.nil?
3232
raise ArgumentError, 'Parameters required'
3333
end
3434
url = "#{constants.BULK_BASE_URL}/copyFolder"
35-
payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path }
35+
payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path, 'includeFileVersions': include_file_versions }.to_json
3636
@req_obj.request('post', url, @req_obj.create_headers, payload)
3737
end
3838

lib/imagekitio/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def stream_file(file_url: nil, &block)
120120
@file_service.stream_file(remote_file_url: file_url, &block)
121121
end
122122

123-
def copy_file(source_file_path: nil, destination_path: nil)
124-
@file_service.copy(source_file_path: source_file_path, destination_path: destination_path)
123+
def copy_file(source_file_path: nil, destination_path: nil, include_file_versions: false)
124+
@file_service.copy(source_file_path: source_file_path, destination_path: destination_path, include_file_versions: include_file_versions)
125125
end
126126

127127
def move_file(source_file_path: nil, destination_path: nil)
@@ -161,8 +161,8 @@ def delete_folder(folder_path: nil)
161161
@folder_service.delete(folder_path: folder_path)
162162
end
163163

164-
def copy_folder(source_folder_path: nil, destination_path: nil)
165-
@folder_service.copy(source_folder_path: source_folder_path, destination_path: destination_path)
164+
def copy_folder(source_folder_path: nil, destination_path: nil, include_file_versions: false)
165+
@folder_service.copy(source_folder_path: source_folder_path, destination_path: destination_path, include_file_versions: include_file_versions)
166166
end
167167

168168
def move_folder(source_folder_path: nil, destination_path: nil)

lib/imagekitio/request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def request(method, url, headers = create_headers, payload = nil)
4949
raise RestClient::ExceptionWithResponse, OpenStruct.new({ body: resp.body, code: resp_c })
5050
end
5151
else
52+
RestClient.log = STDOUT
5253
resp = RestClient::Request.new(method: method,
5354
url: url,
5455
headers: headers,

lib/imagekitio/sdk/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ImageKitIo
22
module Sdk
3-
VERSION = '2.2.0'
3+
VERSION = '2.1.2'
44
end
55
end

test/imagekit/api_service/file_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,10 @@
961961
destination_path = '/my_image'
962962
resp = @sut.copy(source_file_path: source_file, destination_path: destination_path)
963963
expect(@ac[:url]).to eq("https://api.imagekit.io/v1/files/copy")
964-
expect(@ac[:payload]).to eq({:sourceFilePath=>"test/dummy.png", :destinationPath=>"/my_image"})
964+
expect(@ac[:payload]).to eq("{\"sourceFilePath\":\"test/dummy.png\",\"destinationPath\":\"/my_image\",\"includeFileVersions\":false}")
965+
expect(resp[:code]).to eq(200)
966+
resp = @sut.copy(source_file_path: source_file, destination_path: destination_path, include_folder_versions: true)
967+
expect(@ac[:payload]).to eq("{\"sourceFilePath\":\"test/dummy.png\",\"destinationPath\":\"/my_image\",\"includeFileVersions\":false}")
965968
expect(resp[:code]).to eq(200)
966969
end
967970
end

test/imagekit/api_service/folder_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
resp = @sut.copy(source_folder_path: source_folder, destination_path: destination_path)
8383
expect(@ac[:url]).to eq("https://api.imagekit.io/v1/bulkJobs/copyFolder")
8484
expect(@ac[:method]).to eq('post')
85-
expect(@ac[:payload]).to eq({:sourceFolderPath=>"my_folder", :destinationPath=>"copied"})
85+
expect(@ac[:payload]).to eq("{\"sourceFolderPath\":\"my_folder\",\"destinationPath\":\"copied\",\"includeFileVersions\":false}")
8686
expect(resp[:body][:jobId]).to eq('123456')
8787
end
8888
end

0 commit comments

Comments
 (0)