swarley

Coggle#download

Nov 24th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.35 KB | None | 0 0
  1. require 'net/http'
  2.  
  3. module Coggle
  4.   def Coggle.download(url, path, name=nil)
  5.     Net::HTTP.start(url.split('/').first) do |http|
  6.     resp = http.get('/' + url.split('/', 2).last)
  7.     if name == nil then; name = path + url.split('/').last; else; name = path + name; end
  8.     open(name, "wb") do |file|
  9.       file.write(resp.body)
  10.     end
  11.     end
  12.   end
  13. end
  14.  
  15.  
Add Comment
Please, Sign In to add comment