lib/bearcat/client/canvas_files.rb in bearcat-0.9.17 vs lib/bearcat/client/canvas_files.rb in bearcat-0.9.18

- old
+ new

@@ -6,46 +6,8 @@ declare_response = declare_file(api_path, file_params(file_path).merge(params)) confirmation_url = post_file(declare_response['upload_url'], declare_response['upload_params'], file_path) confirm_file_upload(confirmation_url) end - private - - def file_params(file_path) - { - size: File.open(file_path).size, - name: File.basename(file_path) - } - end - - def declare_file(api_path, params) - post(api_path, params) - end - - def post_file(url, params, file_path) - params['Filename'] = File.basename(file_path) - params['file'] = Faraday::UploadIO.new(file_path, params['content-type']) - - response = upload_connection.post(url, params) - if response.status == (302 || 303) #success if it is a redirect - response.headers['Location'] - else - raise 'FailedFileUpload' - end - end - - def confirm_file_upload(url) - uri = URI(url) - post(uri.path, CGI::parse(uri.query)) - end - - def upload_connection - Faraday.new do |f| - f.request :multipart - f.request :url_encoded - f.adapter :net_http - end - end - end end -end \ No newline at end of file +end