class Ezid::BatchDownload
Constants
- ANVL
- ARK
- BOOLEANS
- CSV
- DOI
- DOWNLOAD_RETRY_INTERVAL
- FORMATS
- ID
CSV
Columns- MAPPED_CREATOR
- MAPPED_DATE
- MAPPED_PUBLISHER
- MAPPED_TITLE
- MAPPED_TYPE
- MAX_DOWNLOAD_TRIES
- NO
- PERMANENCE
- REAL
- TEST
- TYPES
- URN
- XML
- YES
Public Class Methods
new(format, args={})
click to toggle source
Calls superclass method
# File lib/ezid/batch_download.rb, line 67 def initialize(format, args={}) super(args.merge(format: format)) end
Public Instance Methods
download_file(path: nil)
click to toggle source
# File lib/ezid/batch_download.rb, line 89 def download_file(path: nil) path ||= Dir.getwd fullpath = File.directory?(path) ? File.join(path, download_filename) : path tries = 0 ready = false print "Checking for download " Net::HTTP.start(download_uri.host, download_uri.port) do |http| while tries < MAX_DOWNLOAD_TRIES tries += 1 sleep DOWNLOAD_RETRY_INTERVAL print "." response = http.head(download_uri.path) if response.code == '200' ready = true break end end end puts unless ready raise BatchDownloadError, "Download not ready after checking #{MAX_DOWNLOAD_TRIES} times." end File.open(fullpath, "wb") do |f| Net::HTTP.start(download_uri.host, download_uri.port) do |http| http.request_get(download_uri.path) do |response| response.read_body do |chunk| f.write(chunk) end end end end fullpath end
Also aliased as: file
download_url()
click to toggle source
# File lib/ezid/batch_download.rb, line 83 def download_url get_response.download_url end
Also aliased as: url
get_response()
click to toggle source
# File lib/ezid/batch_download.rb, line 75 def get_response @response ||= client.batch_download(params) end
params()
click to toggle source
# File lib/ezid/batch_download.rb, line 71 def params to_h end
reload()
click to toggle source
# File lib/ezid/batch_download.rb, line 79 def reload @response = nil end
Private Instance Methods
client()
click to toggle source
# File lib/ezid/batch_download.rb, line 140 def client Client.new end
download_filename()
click to toggle source
# File lib/ezid/batch_download.rb, line 136 def download_filename File.basename(download_uri.path) end
download_uri()
click to toggle source
# File lib/ezid/batch_download.rb, line 132 def download_uri @download_uri ||= URI(download_url) end