faviconduit
Attempts to download a URL’s favicon.
Synopsis
raise "url missing" unless uri = ARGV[0]
begin
fav = Faviconduit.get(uri)
puts "found favicon at #{fav.url}"
File.open('favicon.ico', 'w') do |file|
file.write(fav.data)
end
rescue Faviconduit::MissingFavicon
puts "favicon missing"
rescue Faviconduit::InvalidFavicon
puts "favicon invalid"
end
Methods
Faviconduit.get(uri)
Takes a url and attempts to returns the favicon object. The url can be fairly loosely specified because Addressable::URI.heuristic_parse is used to figure it out.
obj.url
The favicon url it was ultimately found at.
obj.data
The favicon image data.
Exceptions
Faviconduit::MissingFavicon
Raises this if the favicon simply isn’t found.
Faviconduit::InvalidFavicon
Raises this if the favicon is determined to be not a valid favicon. Currently (0.1) determins this if the content-type is not /^image/ or the size is 0 bytes.
Faviconduit::Error
This is the parent of all faviconduit exceptions and can be caught instead of the more specific exceptions.
Copyright
Copyright © 2010 Kevin Swope. See LICENSE for details.