This example shows how to copy library item files to the client system, using an HTTP transfer.

This example uses the steps that are described in the Download Files to a Local System from a Library Item procedure.

require 'Com/Vmware/Content/Library/Item'
require 'Com/Vmware/Content/Library/Item/Downloadsession'
require 'securerandom'
require 'net/http'

# 1 - Create a new download session model.
download_session_model =
   Com::Vmware::Content::Library::Item::DownloadSessionModel.new
download_session_model.library_item_id = $my_library_item_id
download_session_stub =
   Com::Vmware::Content::Library::Item::DownloadSession.new $my_stub_config
idem_token = SecureRandom.uuid
download_session_id =
   download_session_stub.create(create_spec=download_session_model,
                                client_token=idem_token)

# 2 - Access the File service and retrieve the files you want to export.
download_session_file_stub =
   Com::Vmware::Content::Library::Item::Downloadsession::File.new $my_stub_config
file_infos = download_session_file_stub.list download_session_id
file_infos.each do |info|
  download_session_file_stub.prepare download_session_id, info.name

# 3 - Wait until the file is in the prepared state before downloading.
  download_info =
     download_session_file_stub.get download_session_id, info.name
  sleep 30 while download_info.status !=
Com::Vmware::Content::Library::Item::Downloadsession::File::PrepareStatus::PREPARED

# 4 - Download the file with an HTTP GET request.
  uri = URI.parse download_info.download_endpoint.uri
  request = Net::HTTP::Get.new uri.to_s
  response = Net::HTTP.start(uri.host, uri.port) do |http|
    http.request request
  end

# 5 - Delete the download session after all files are downloaded.
end  # |info|
download_session_stub.delete download_session_id

puts "\n\nCompleted download session #{download_session_id}.\n"