Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Terry Donaghe http://www.rubynoob.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

How to download files with Ruby

// Note: the "b" in "wb" in the open method may not be needed in
// non-Windows environments. In Windows it indicates that you're writing
// binary information. You probably won't need it for downloading straight text
// or html either.

require 'net/http'

Net::HTTP.start("static.flickr.com") { |http|
  resp = http.get("/92/218926700_ecedc5fef7_o.jpg")
  open("fun.jpg", "wb") { |file|
    file.write(resp.body)
   }
}
puts "Yay!!"
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS