Sha256: 0e92dfe11c4c2213c9ae1f5ead2139b7cd409031e15739e198b2c3c9bdadd151
Contents?: true
Size: 1.21 KB
Versions: 37
Compression:
Stored size: 1.21 KB
Contents
module Bearcat class Client < Footrest::Client module FileHelper def file_params(file_path) { size: File.open(file_path).size, name: File.basename(file_path) }.with_indifferent_access 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 [201, 302, 303].include? response.status #success if it is a redirect or 201 response.headers['Location'] else raise 'FailedFileUpload' end end def confirm_file_upload(url) uri = URI(url) uri.scheme = uri.host = uri.port = nil get(uri.to_s) end def upload_connection Faraday.new do |f| f.options[:open_timeout] = ENV.fetch('FARADAY_OPEN_TIMEOUT', 60).to_i f.options[:timeout] = ENV.fetch('FARADAY_TIMEOUT', 60).to_i f.request :multipart f.request :url_encoded f.adapter :net_http end end end end end
Version data entries
37 entries across 37 versions & 1 rubygems