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.2.14 lib/bearcat/client/file_helper.rb
bearcat-1.2.13 lib/bearcat/client/file_helper.rb
bearcat-1.2.12 lib/bearcat/client/file_helper.rb
bearcat-1.2.11 lib/bearcat/client/file_helper.rb
bearcat-1.2.10 lib/bearcat/client/file_helper.rb
bearcat-1.2.9 lib/bearcat/client/file_helper.rb
bearcat-1.2.7 lib/bearcat/client/file_helper.rb
bearcat-1.2.6 lib/bearcat/client/file_helper.rb
bearcat-1.2.5 lib/bearcat/client/file_helper.rb
bearcat-1.2.4 lib/bearcat/client/file_helper.rb
bearcat-1.2.3 lib/bearcat/client/file_helper.rb
bearcat-1.2.1 lib/bearcat/client/file_helper.rb
bearcat-1.2.0 lib/bearcat/client/file_helper.rb
bearcat-1.1.1 lib/bearcat/client/file_helper.rb
bearcat-1.1.0 lib/bearcat/client/file_helper.rb
bearcat-1.0.28 lib/bearcat/client/file_helper.rb
bearcat-1.0.27 lib/bearcat/client/file_helper.rb
bearcat-1.0.26 lib/bearcat/client/file_helper.rb
bearcat-1.0.25 lib/bearcat/client/file_helper.rb
bearcat-1.0.24 lib/bearcat/client/file_helper.rb