Sha256: 52c51c9da9a1894ffaea131323922e8ba2336e0fbd5300c63dc8fea4091b1092

Contents?: true

Size: 550 Bytes

Versions: 44

Compression:

Stored size: 550 Bytes

Contents

module DownloadHelper
  TIMEOUT = 1
  PATH    = Rails.root.join("tmp/downloads")

  extend self

  def downloads
    Dir[PATH.join("*")]
  end

  def download
    downloads.first
  end

  def download_content
    wait_for_download
    File.read(download)
  end

  def wait_for_download
    Timeout.timeout(TIMEOUT) do
      sleep 0.1 until downloaded?
    end
  end

  def downloaded?
    !downloading? && downloads.any?
  end

  def downloading?
    downloads.grep(/\.part$/).any?
  end

  def clear_downloads
    FileUtils.rm_f(downloads)
  end
end

Version data entries

44 entries across 22 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-9.0.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-8.0.1 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-8.0.1 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-8.0.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-8.0.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.3.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-7.3.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.2.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.2.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-7.1.1 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.1.1 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-7.1.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-7.1.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.0.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-7.0.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-6.0.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-6.0.0 sample-apps/oauth-app/spec/support/download_helper.rb
hubspot-api-client-5.0.0 sample-apps/contacts-app/spec/support/download_helper.rb
hubspot-api-client-5.0.0 sample-apps/oauth-app/spec/support/download_helper.rb