module SolveBio::APIOperations::Download

Public Instance Methods

download(path=nil) click to toggle source
# File lib/solvebio/api_operations.rb, line 43
def download(path=nil)
    download_url = url + '/download'
    response = Client.get(download_url, :raw => true)

    if response.code != 302
        # Some kind of error. We expect a redirect
        raise SolveError('Could not download file: response code' %
                         response.status_code)
    end

    download_url = response.headers[:location]
    filename = download_url.split('%3B%20filename%3D')[1]

    path = Dir.tmpdir unless path
    filename = File.join(path, filename)
    response = Client.get(download_url, :raw => true, :auth => false, :default_headers => false)

    File.open(filename, 'wb') do |fh|
        fh.write(response.body)
    end

    self['filename'] = filename
    self['code'] = response.code
    self
end