def get(parameters)
params_desc = {
:url => { :mandatory => true, :type => :string },
:dest => { :mandatory => false, :type => :string },
:limit => { :mandatory => false, :type => :integer, :default => 10 }
}
check_parameters(parameters, params_desc)
url = parameters[:url]
dest = parameters[:dest]
if not dest
destination = File.basename(url)
elsif File.directory?(dest)
destination = File.join(dest, File.basename(url))
else
destination = dest
end
limit = parameters[:limit]
puts "Getting URL '#{url}'..."
begin
content = Util::fetch(url, limit)
rescue Exception
error "Error getting URL: #{$!}"
end
todir = File.dirname(destination)
begin
FileUtils.makedirs(todir) if not File.exists?(todir)
File.open(destination, 'w') { |file| file.write(content) }
rescue Exception
error "Error saving file: #{$!}"
end
end