Skip to content

Commit 0f376a8

Browse files
committed
refactor and add tests
1 parent 0136f62 commit 0f376a8

File tree

2 files changed

+312
-218
lines changed

2 files changed

+312
-218
lines changed

lib/imagekitio/file.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def upload(file, file_name, options)
4545
end
4646

4747
def update_details(file_id, options)
48-
# Update file detail by file_id and options
4948
unless options.fetch(:tags, []).is_a?(Array)
5049
raise ArgumentError, constants.UPDATE_DATA_TAGS_INVALID
5150
end
@@ -226,13 +225,16 @@ def create_custom_metadata(name, label, schema)
226225
@req_obj.request('post', url, @req_obj.create_headers, payload)
227226
end
228227

229-
def get_custom_metadata(options)
228+
def get_custom_metadata(options = {})
230229
url = "#{constants.API_BASE_URL}/customMetadataFields"
231230
payload = request_formatter(options)
232231
@req_obj.request('get', url, @req_obj.create_headers, payload)
233232
end
234233

235234
def update_custom_metadata(id, label, schema)
235+
if id == '' || id.nil?
236+
raise ArgumentError, 'id is required'
237+
end
236238
url = "#{constants.API_BASE_URL}/customMetadataFields/#{id}"
237239
payload = {}
238240
payload = payload.merge({ 'label': label }) unless label.nil?
@@ -241,6 +243,9 @@ def update_custom_metadata(id, label, schema)
241243
end
242244

243245
def delete_custom_metadata(id)
246+
if id == '' || id.nil?
247+
raise ArgumentError, 'id is required'
248+
end
244249
url = "#{constants.API_BASE_URL}/customMetadataFields/#{id}"
245250
@req_obj.request('delete', url, @req_obj.create_headers)
246251
end

0 commit comments

Comments
 (0)