class TumblrSync::PhotoFetcher

Public Class Methods

new(directory = ".") click to toggle source
# File lib/tumblr-sync/photo_fetcher.rb, line 5
def initialize(directory = ".")
  @directory = directory
end

Public Instance Methods

fetch(url) click to toggle source
# File lib/tumblr-sync/photo_fetcher.rb, line 9
def fetch(url)
  return if File.exists? File.join(@directory, Mechanize::File.new(URI(url)).filename)
  http = Mechanize.new
  http.get(url) do |page|
    return if File.exists? filename = File.join(@directory, File.basename(page.uri.path))
    page.save filename
  end
end