lib/vkontakte_api/uploading.rb in vkontakte_api-1.3 vs lib/vkontakte_api/uploading.rb in vkontakte_api-1.3.1
- old
+ new
@@ -12,12 +12,26 @@
# VkontakteApi.upload(
# url: 'http://example.com/upload',
# file1: ['/path/to/file1.jpg', 'image/jpeg'],
# file2: [io_object, 'image/png', '/path/to/file2.png']
# )
+ # # alternative syntax
+ # VkontakteApi.upload(
+ # url: 'http://example.com/upload',
+ # files: [
+ # ['/path/to/file1.jpg', 'image/jpeg'],
+ # [io_object, 'image/png', '/path/to/file2.png']
+ # ]
+ # )
+
def upload(params = {})
url = params.delete(:url)
raise ArgumentError, 'You should pass :url parameter' unless url
+
+ (params.delete(:files) || []).each_with_index do |file, index|
+ key = "file#{index.succ}"
+ params[key.to_sym] = file
+ end
files = {}
params.each do |param_name, (file_path_or_io, file_type, file_path)|
files[param_name] = Faraday::UploadIO.new(file_path_or_io, file_type, file_path)
end