Created
October 6, 2013 13:39
-
-
Save Macagare/6854209 to your computer and use it in GitHub Desktop.
load xml via ruby Net:HTTP and write into local file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
def load_file(f_url) | |
load_content( URI.parse(f_url) ) | |
end | |
def load_content(uri) | |
resp = Net::HTTP.get_response(uri) | |
raise unless resp.code == "200" | |
write_file( get_filename(uri.to_s), resp.body) | |
end | |
def write_file(name, content) | |
t_file = File.new(name, "w") | |
t_file.write(content) | |
t_file.close | |
end | |
def get_filename(uri) | |
arr = uri.split("/") | |
return arr[arr.length - 1] | |
end | |
load_file("http://www.lorem.com/path/to/file.xml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment