Sha256: 7bb6819ee771ce41cb9fcea55c4259cbbf23dcbe60396bf762a4b66a90e0ce7e

Contents?: true

Size: 841 Bytes

Versions: 67

Compression:

Stored size: 841 Bytes

Contents

module FileHelper

  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 [302, 303].include? response.status #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

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
bearcat-1.3.16 lib/bearcat/client/file_helper.rb
bearcat-1.3.15 lib/bearcat/client/file_helper.rb
bearcat-1.3.14 lib/bearcat/client/file_helper.rb
bearcat-1.3.13 lib/bearcat/client/file_helper.rb
bearcat-1.3.12 lib/bearcat/client/file_helper.rb
bearcat-1.3.11 lib/bearcat/client/file_helper.rb
bearcat-1.3.10 lib/bearcat/client/file_helper.rb
bearcat-1.3.9 lib/bearcat/client/file_helper.rb
bearcat-1.3.8 lib/bearcat/client/file_helper.rb
bearcat-1.3.7 lib/bearcat/client/file_helper.rb
bearcat-1.3.6 lib/bearcat/client/file_helper.rb
bearcat-1.3.5 lib/bearcat/client/file_helper.rb
bearcat-1.3.4 lib/bearcat/client/file_helper.rb
bearcat-1.3.3 lib/bearcat/client/file_helper.rb
bearcat-1.3.2 lib/bearcat/client/file_helper.rb
bearcat-1.3.1 lib/bearcat/client/file_helper.rb
bearcat-1.2.18 lib/bearcat/client/file_helper.rb
bearcat-1.2.17 lib/bearcat/client/file_helper.rb
bearcat-1.2.16 lib/bearcat/client/file_helper.rb
bearcat-1.2.15 lib/bearcat/client/file_helper.rb