lib/ayadn/fileops.rb in ayadn-1.3.2 vs lib/ayadn/fileops.rb in ayadn-1.4.0

- old
+ new

@@ -32,9 +32,39 @@ def self.old_ayadn? Dir.exist?(Dir.home + "/ayadn/data") end + def self.upload_files files + files.map do |file| + puts "\n#{file}\n\n" + JSON.load(self.upload(file, Settings.user_token)) + end + end + + def self.upload(path, token) + begin + file = Regexp.escape(path).gsub!('\.', '.') + case File.extname(path).downcase + when ".png" + `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file};type=image/png" -F 'public=true' -X POST` + when ".gif" + `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file};type=image/gif" -F 'public=true' -X POST` + else #jpg or jpeg or JPG or JPEG, automatically recognized as such + `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F content=@#{file} -F 'public=true' -X POST` + end + rescue Errno::ENOENT + abort(Status.no_curl) + end + end + + def self.make_paths(files_array) + files_array.map do |file| + abort(Status.bad_path) unless File.exist?(file) + File.absolute_path(file) + end + end + private def get_users(list) h = {} list.each {|k,v| h[k] = { username: v[0], name: v[1] }}