Skip to content
Browse files

Changed name from 'iconoclast' to 'iconoclasm'

There was already a gem named 'iconoclast' on gemcutter.
  • Loading branch information...
1 parent ddc5d1a commit 5aa1031dcd86fbf83e3d23cec4b070f7a965b503 Sander Hartlage committed Dec 28, 2009
View
10 README.markdown
@@ -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 Rakefile
@@ -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
18 lib/iconoclasm.rb
@@ -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
View
6 lib/iconoclast/downloader.rb → lib/iconoclasm/downloader.rb
@@ -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
View
12 lib/iconoclast/errors.rb → lib/iconoclasm/errors.rb
@@ -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
View
8 lib/iconoclast/extractor.rb → lib/iconoclasm/extractor.rb
@@ -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,
View
12 lib/iconoclast/favicon.rb → lib/iconoclasm/favicon.rb
@@ -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
View
4 lib/iconoclast/headers.rb → lib/iconoclasm/headers.rb
@@ -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
18 lib/iconoclast.rb
@@ -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
2 spec/helper.rb
@@ -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
View
8 spec/iconoclast/downloader_spec.rb → spec/iconoclasm/downloader_spec.rb
@@ -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
View
0 spec/iconoclast/errors_spec.rb → spec/iconoclasm/errors_spec.rb
File renamed without changes.
View
8 spec/iconoclast/extractor_spec.rb → spec/iconoclasm/extractor_spec.rb
@@ -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
View
26 spec/iconoclast/favicon_spec.rb → spec/iconoclasm/favicon_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../helper')
-describe Iconoclast::Favicon do
+describe Iconoclasm::Favicon do
before do
@size = 100
@@ -15,7 +15,7 @@
describe "initialization" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes)
+ @favicon = Iconoclasm::Favicon.new(@attributes)
end
it "should set the content type to the content type supplied in the headers" do
@@ -42,7 +42,7 @@
describe "when the data was supplied on intialization" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => @data}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => @data}))
end
it "should return the supplied data" do
@@ -57,7 +57,7 @@
describe "when data was not supplied on initialization" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => nil}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => nil}))
end
it "should fetch the data from the internets and return it" do
@@ -81,7 +81,7 @@
describe "when the size was supplied on initialization" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => @data, :content_length => @size}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => @data, :content_length => @size}))
end
it "should return the supplied size" do
@@ -97,7 +97,7 @@
describe "when the size was not supplied on initialization" do
before do
@headers.stubs(:content_length).returns(nil)
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => @data, :content_length => nil}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => @data, :content_length => nil}))
@favicon.instance_variable_get(:@size).should be_nil
end
@@ -114,7 +114,7 @@
describe "when the content type was supplied on initialization" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:content_type => @content_type}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:content_type => @content_type}))
end
it "should return the supplied content_type" do
@@ -130,7 +130,7 @@
describe "when the content type was not supplied on initialization" do
before do
@headers.stubs(:content_type).returns(nil)
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:content_type => nil}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:content_type => nil}))
@mime = mock('mime type', :content_type => @content_type)
end
@@ -143,7 +143,7 @@
describe "fetching the image data" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes)
+ @favicon = Iconoclasm::Favicon.new(@attributes)
@response = mock('http response')
end
@@ -173,14 +173,14 @@
end
it "should raise an HTTP error" do
- lambda { @favicon.fetch_data }.should raise_error(Iconoclast::HTTPError)
+ lambda { @favicon.fetch_data }.should raise_error(Iconoclasm::HTTPError)
end
end
end
describe "determining the validity of the favicon" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => "IMAGE DATA!"}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => "IMAGE DATA!"}))
end
describe "when the content is zero-length" do
@@ -239,7 +239,7 @@
describe "saving the favicon" do
before do
- @favicon = Iconoclast::Favicon.new(@attributes.merge({:data => "IMAGE DATA!"}))
+ @favicon = Iconoclasm::Favicon.new(@attributes.merge({:data => "IMAGE DATA!"}))
end
describe "to a tempfile" do
@@ -297,7 +297,7 @@
end
it "should raise an error" do
- lambda { @favicon.save(@storage) }.should raise_error(Iconoclast::RTFMError)
+ lambda { @favicon.save(@storage) }.should raise_error(Iconoclasm::RTFMError)
end
end
end
View
4 spec/iconoclast/headers_spec.rb → spec/iconoclasm/headers_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../helper')
-describe Iconoclast::Headers do
+describe Iconoclasm::Headers do
before do
@http_response = "HTTP/1.1 200 OK"
@@ -9,7 +9,7 @@
@content_type = "image/x-icon"
@content_length = 3638
@header_string = "#{@http_response}\r\nDate: Tue, 22 Dec 2009 21:15:31 GMT\r\nServer: #{@server}\r\nVary: Host,User-Agent\r\nLast-Modified: #{@last_modified}\r\nETag: \"e36-432ce70534600\"\r\nAccept-Ranges: bytes\r\nContent-Length: #{@content_length}\r\nContent-Type: #{@content_type}\r\n\r\n"
- @headers = Iconoclast::Headers.new(@header_string)
+ @headers = Iconoclasm::Headers.new(@header_string)
end
describe "parsing the HTTP response" do
View
14 spec/iconoclast_spec.rb → spec/iconoclasm_spec.rb
@@ -1,23 +1,23 @@
require File.expand_path(File.dirname(__FILE__) + '/helper')
-describe Iconoclast do
+describe Iconoclasm do
describe "#extract" do
before do
@url = 'http://www.website.com/some-crappy-blog-post'
end
it "should extract the favicon for the given url" do
- Iconoclast.expects(:extract_favicon_from).with(@url, nil)
- Iconoclast::Favicon.stubs(:new)
- Iconoclast.extract(@url)
+ Iconoclasm.expects(:extract_favicon_from).with(@url, nil)
+ Iconoclasm::Favicon.stubs(:new)
+ Iconoclasm.extract(@url)
end
it "should make a new Favicon instance" do
favicon = stub('favicon')
- Iconoclast.stubs(:extract_favicon_from).returns(favicon)
- Iconoclast::Favicon.expects(:new).with(favicon)
- Iconoclast.extract(@url)
+ Iconoclasm.stubs(:extract_favicon_from).returns(favicon)
+ Iconoclasm::Favicon.expects(:new).with(favicon)
+ Iconoclasm.extract(@url)
end
end

0 comments on commit 5aa1031

Please sign in to comment.
Something went wrong with that request. Please try again.