Class: CoreLibrary::FileHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/utilities/file_helper.rb

Overview

A utility for file-specific operations.

Class Method Summary collapse

Class Method Details

.get_file(url) ⇒ String

Class method which takes a URL, downloads the file (if not already downloaded for this test session), and returns the file path.

Parameters:

  • url (String)

    The URL of the required file.

Returns:

  • (String)

    The path of the downloaded file.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/apimatic-core/utilities/file_helper.rb', line 13

def self.get_file(url)
  return @cache[url] if @cache.key?(url)

  tempfile = Tempfile.new('APIMatic')
  tempfile.binmode
  tempfile.write(URI.parse(url).open(ssl_ca_cert: Certifi.where).read)
  tempfile.flush
  tempfile.close

  raise 'Tempfile path is nil!' if tempfile.path.nil?

  @cache[url] = tempfile.path.to_s # Store only the file path
end