Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Macagare
Created October 6, 2013 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Macagare/6854209 to your computer and use it in GitHub Desktop.
Save Macagare/6854209 to your computer and use it in GitHub Desktop.
load xml via ruby Net:HTTP and write into local file
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