Module | Net |
In: |
lib/standard/facets/net/http.rb
|
Returns a response object for the given URL or raises an exception with the appropriate error status code if unable to complete the request
Net.download('http://example.com/') Net.download('http://example.com/', 2) # fail after 2 redirects
CREDIT: Daniel Huckstep
Downloads a given URL and saves it to disk at the specified path. If path is not provided or nil, then the last segment in the path of the URL is used as the file name.
Takes a third parameters as a hash of options:
# Saves robots.txt to PWD as robots.txt Net.download_and_save(‘example.com/robots.txt’)
# Saves robots.txt to PWD as example.txt Net.download_and_save(‘example.com/robots.txt’, ‘example.txt’)
# Saves robots.txt to PWD as robots.txt, and writes the result as binary Net.download_and_save(‘example.com/robots.txt’, nil, mode: ‘wb’)
CREDIT: Daniel Huckstep