Permalink
Browse files

Changed name from 'iconoclast' to 'iconoclasm'

There was already a gem named 'iconoclast' on gemcutter.
  • Loading branch information...
Sander Hartlage
Sander Hartlage committed Dec 28, 2009
1 parent ddc5d1a commit 5aa1031dcd86fbf83e3d23cec4b070f7a965b503
View
@@ -1,19 +1,21 @@
-# iconoclast
+# iconoclasm
Finds favorites icons for web pages on the world wide internets by checking the HTML head or the standard favicon location. Then, do with them what you will.
+Called "iconoclasm" because there was already a gem on gemcutter called "iconoclast". Boo! Hiss!
+
### Usage
To get the favicon for a page, do:
-`favicon = Iconoclast.extract('www.website.com')`
+`favicon = Iconoclasm.extract('www.website.com')`
This will go and do a bunch of GETs (two or three, actually) on the url given. If you've already got the content and want to skip one of the GETs, you can pass the content in as the second argument.
`content = get_some_content('www.website.com')`<br/>
-`favicon = Iconoclast.extract('www.website.com', content)`
+`favicon = Iconoclasm.extract('www.website.com', content)`
-`Iconoclast.extract` returns an `Iconoclast::Favicon` instance, from which you can get the URL, content type, size, or access the binary image data. By calling `valid?`, you can check if the favicon is valid based on whatever my standards were when I wrote this (basically, whether or not it's actually an image).
+`Iconoclasm.extract` returns an `Iconoclasm::Favicon` instance, from which you can get the URL, content type, size, or access the binary image data. By calling `valid?`, you can check if the favicon is valid based on whatever my standards were when I wrote this (basically, whether or not it's actually an image).
You can save the image to a tempfile using `favicon.save`, or more usefully, to a file at `favicon.save('path/to/file')`. Fun times had by all.
View
@@ -4,11 +4,11 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.name = "iconoclast"
+ gem.name = "iconoclas,"
gem.summary = %Q{Finds favicons and DESTROYS THEM (well, not really, but it will download and save them)}
gem.description = %Q{Finds favorites icons for web pages on the world wide internets by checking the HTML head or the standard favicon location. Then, do with them what you will.}
gem.email = "sander.hartlage@gmail.com"
- gem.homepage = "http://github.com/sander6/iconoclast"
+ gem.homepage = "http://github.com/sander6/iconoclasm"
gem.authors = ["Sander Hartlage"]
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
View
@@ -0,0 +1,18 @@
+$:.unshift(File.dirname(__FILE__))
+require 'iconoclasm/downloader'
+require 'iconoclasm/errors'
+require 'iconoclasm/extractor'
+require 'iconoclasm/favicon'
+require 'iconoclasm/headers'
+
+module Iconoclasm
+
+ class << self
+ include Iconoclasm::Extractor
+
+ def extract(url, content = nil)
+ Iconoclasm::Favicon.new(extract_favicon_from(url, content))
+ end
+ end
+
+end
@@ -1,6 +1,6 @@
require 'curl'
-module Iconoclast
+module Iconoclasm
module Downloader
@@user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
@@ -15,14 +15,14 @@ def self.user_agent
def get(url)
Curl::Easy.http_get(url) do |curl|
- curl.headers['User-Agent'] = Iconoclast::Downloader.user_agent
+ curl.headers['User-Agent'] = Iconoclasm::Downloader.user_agent
curl.follow_location = true
end
end
def head(url)
Curl::Easy.http_head(url) do |curl|
- curl.headers['User-Agent'] = Iconoclast::Downloader.user_agent
+ curl.headers['User-Agent'] = Iconoclasm::Downloader.user_agent
end
end
@@ -1,18 +1,18 @@
-module Iconoclast
+module Iconoclasm
class Error < StandardError
def initialize(url)
@url = url
end
end
- class MissingFavicon < Iconoclast::Error
+ class MissingFavicon < Iconoclasm::Error
def message
"#{@url} doesn't seem to have a favicon"
end
end
- class HTTPError < Iconoclast::Error
+ class HTTPError < Iconoclasm::Error
def initialize(url, response)
super(url)
@response = response
@@ -38,17 +38,17 @@ def http_error_message
end
end
- class RTFMError < Iconoclast::Error
+ class RTFMError < Iconoclasm::Error
def initialize(reason)
@reason = reason
end
def message
- "Iconoclast doesn't work that way (#{@reason})"
+ "Iconoclasm doesn't work that way (#{@reason})"
end
end
- class InvalidFavicon < Iconoclast::Error
+ class InvalidFavicon < Iconoclasm::Error
def initialize(url, content_type)
super(url)
@content_type = content_type
@@ -1,19 +1,19 @@
require 'nokogiri'
require 'uri'
-module Iconoclast
+module Iconoclasm
module Extractor
def self.included(base)
- base.class_eval { include Iconoclast::Downloader }
+ base.class_eval { include Iconoclasm::Downloader }
end
def extract_favicon_from(url, content = nil)
catch(:done) do
base_url = base_url_of(url)
extract_favicon_from_head_of(base_url, content)
extract_favicon_from_naive_guess(base_url)
- raise Iconoclast::MissingFavicon.new(base_url)
+ raise Iconoclasm::MissingFavicon.new(base_url)
end
end
@@ -41,7 +41,7 @@ def document_from(base_url, content = nil)
def extract_favicon_from_naive_guess(base_url)
naive_url = "#{base_url}/favicon.ico"
response = get(naive_url)
- headers = Iconoclast::Headers.new(response.header_str)
+ headers = Iconoclasm::Headers.new(response.header_str)
if response.response_code == 200
throw(:done, {
:url => naive_url,
@@ -2,9 +2,9 @@
require 'mime/types'
require 'uri'
-module Iconoclast
+module Iconoclasm
class Favicon
- include Iconoclast::Downloader
+ include Iconoclasm::Downloader
attr_reader :content_type, :url, :save_path
attr_accessor :name
@@ -20,7 +20,7 @@ def initialize(attributes = {})
end
def inspect
- "#<Iconoclast::Favicon @url=#{url}, @name=#{name}, @content_type=#{content_type}, @size=#{size}, @save_path=#{save_path ? save_path : "nil"}>"
+ "#<Iconoclasm::Favicon @url=#{url}, @name=#{name}, @content_type=#{content_type}, @size=#{size}, @save_path=#{save_path ? save_path : "nil"}>"
end
def size
@@ -61,7 +61,7 @@ def fetch_data
if response.response_code == 200
response.body_str
else
- raise Iconoclast::HTTPError.new(url, response)
+ raise Iconoclasm::HTTPError.new(url, response)
end
end
@@ -73,10 +73,10 @@ def save(path_or_storage = nil, force = false)
elsif path_or_storage.is_a?(String)
save_to_file(path_or_storage)
else
- raise Iconoclast::RTFMError.new("invalid storage type")
+ raise Iconoclasm::RTFMError.new("invalid storage type")
end
else
- raise Iconoclast::InvalidFavicon.new(url, content_type)
+ raise Iconoclasm::InvalidFavicon.new(url, content_type)
end
end
@@ -1,4 +1,4 @@
-module Iconoclast
+module Iconoclasm
class Headers
attr_reader :version, :code, :message
@@ -52,7 +52,7 @@ def parse_http_response(response)
@code = $2.to_i
@message = $3.strip
else
- raise Iconoclast::HTTPError.new(nil, response)
+ raise Iconoclasm::HTTPError.new(nil, response)
end
end
end
View
@@ -1,18 +0,0 @@
-$:.unshift(File.dirname(__FILE__))
-require 'iconoclast/downloader'
-require 'iconoclast/errors'
-require 'iconoclast/extractor'
-require 'iconoclast/favicon'
-require 'iconoclast/headers'
-
-module Iconoclast
-
- class << self
- include Iconoclast::Extractor
-
- def extract(url, content = nil)
- Iconoclast::Favicon.new(extract_favicon_from(url, content))
- end
- end
-
-end
View
@@ -4,7 +4,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'iconoclast'
+require 'iconoclasm'
Spec::Runner.configure do |config|
config.mock_with :mocha
@@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../helper')
-describe Iconoclast::Downloader do
+describe Iconoclasm::Downloader do
before do
- class Thing; include Iconoclast::Downloader; end
+ class Thing; include Iconoclasm::Downloader; end
@thing = Thing.new
@url = 'http://www.website.com'
@curl = mock('curl')
@@ -20,7 +20,7 @@ class Thing; include Iconoclast::Downloader; end
headers = mock('headers')
Curl::Easy.stubs(:http_get).yields(@curl)
@curl.expects(:headers).returns(headers)
- headers.expects(:[]=).with('User-Agent', Iconoclast::Downloader.user_agent)
+ headers.expects(:[]=).with('User-Agent', Iconoclasm::Downloader.user_agent)
@thing.get(@url)
end
@@ -42,7 +42,7 @@ class Thing; include Iconoclast::Downloader; end
headers = mock('headers')
Curl::Easy.stubs(:http_head).yields(@curl)
@curl.expects(:headers).returns(headers)
- headers.expects(:[]=).with('User-Agent', Iconoclast::Downloader.user_agent)
+ headers.expects(:[]=).with('User-Agent', Iconoclasm::Downloader.user_agent)
@thing.head(@url)
end
end
File renamed without changes.
@@ -1,15 +1,15 @@
require File.expand_path(File.dirname(__FILE__) + '/../helper')
-describe Iconoclast::Extractor do
+describe Iconoclasm::Extractor do
before do
- class Thing; include Iconoclast::Extractor; end
+ class Thing; include Iconoclasm::Extractor; end
@thing = Thing.new
end
describe "requiring the module" do
it "should also require the Downloader module" do
- Thing.included_modules.should include(Iconoclast::Downloader)
+ Thing.included_modules.should include(Iconoclasm::Downloader)
end
end
@@ -42,7 +42,7 @@ class Thing; include Iconoclast::Extractor; end
end
it "should raise an error" do
- lambda { @thing.extract_favicon_from(@url) }.should raise_error(Iconoclast::MissingFavicon)
+ lambda { @thing.extract_favicon_from(@url) }.should raise_error(Iconoclasm::MissingFavicon)
end
end
end
Oops, something went wrong.

0 comments on commit 5aa1031

Please sign in to comment.