lib/fetch.rb
# Fetches a MARC file given the URL and the prefix you'd like to save it to
Fetches a MARC file given the URL and the prefix you'd like to save it to
Fetches a MARC file given the URL and the prefix you ' d like to save it to
def fetch_http urls, prefix, opts = {}
        if urls.kind_of? Proc
            urls_to_fetch = [urls.call].flatten(1)
	else
            urls_to_fetch = [urls].flatten(1)
	end
        files_written = []
        filename = 'new/' + prefix + '_' + date_downloaded + '.mrc'
        if File.exist? filename
            File.delete filename
        end
        urls_to_fetch.each do |url|
	    uri = URI url
            http = Net::HTTP.new(uri.hostname, uri.port)
            request = Net::HTTP::Get.new(uri.path)
            if opts.key? 'user'
                request.basic_auth opts['user'], opts['pass']
            end
            res = http.request request
            open(filename, 'ab') do |file|
                file.write res.body
            end
            files_written << (filename)
        end
        return files_written.uniq
    end
def fetch_http urls , prefix , opts = { } if urls . kind_of? Proc urls_to_fetch = [ urls . call ] . flatten ( 1 ) else urls_to_fetch = [ urls ] . flatten ( 1 ) end files_written = [ ] filename = 'new/' + prefix + '_' + date_downloaded + '.mrc' if File . exist? filename File . delete filename end urls_to_fetch . each do | url | uri = URI url http = Net :: HTTP . new ( uri . hostname , uri . port ) request = Net :: HTTP :: Get . new ( uri . path ) if opts . key? 'user' request . basic_auth opts [ 'user' ] , opts [ 'pass' ] end res = http . request request open ( filename , 'ab' ) do | file | file . write res . body end files_written << ( filename ) end return files_written . uniq end
Fetches a MARC file given the URL and the prefix you'd like to save it to
Fetches a MARC file given the URL and the prefix you ' d like to save it to
urls
prefix
opts