Skip to content

Commit 8321e96

Browse files
committed
add rename file method
1 parent c17947d commit 8321e96

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/imagekitio/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ def move_file(source_file_path, destination_path)
124124
@file.move(source_file_path, destination_path)
125125
end
126126

127+
def rename_file(file_path, new_file_name, **options)
128+
@file.rename(file_path, new_file_name, **options)
129+
end
130+
127131
def phash_distance(first, second)
128132
# Get hamming distance between two phash(image hash) to check
129133
# similarity between images

lib/imagekitio/file.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,32 @@ def batch_ai_tags_remove(file_ids, ai_tags)
143143
end
144144

145145
def copy(source_file_path, destination_path)
146+
if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
147+
raise ArgumentError, 'parameters required'
148+
end
146149
url = "#{constants.BASE_URL}/copy"
147150
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
148151
@req_obj.request('post', url, @req_obj.create_headers, payload)
149152
end
150153

151154
def move(source_file_path, destination_path)
155+
if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
156+
raise ArgumentError, 'parameters required'
157+
end
152158
url = "#{constants.BASE_URL}/move"
153159
payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
154160
@req_obj.request('post', url, @req_obj.create_headers, payload)
155161
end
156162

163+
def rename(file_path, new_file_name, **options)
164+
if file_path == '' || file_path.nil? || new_file_name == '' || new_file_name.nil?
165+
raise ArgumentError, 'parameters required'
166+
end
167+
url = "#{constans.BASE_URL}/rename"
168+
payload = { 'filePath': file_path, 'newFileName': new_file_name }.merge(request_formatter(options))
169+
@req_obj.request('put', url, @req_obj.create_headers, payload)
170+
end
171+
157172
def validate_upload_options(options)
158173

159174
# Validates upload value, checks if params are valid,

0 commit comments

Comments
 (0)