www-favicon 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/README.rdoc +35 -0
- data/Rakefile +105 -0
- data/lib/www/favicon.rb +93 -0
- metadata +79 -0
data/ChangeLog
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
= www-favicon
|
3
|
+
|
4
|
+
== Description
|
5
|
+
|
6
|
+
library for finding favicon from specific URL
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
=== Archive Installation
|
11
|
+
|
12
|
+
rake install
|
13
|
+
|
14
|
+
=== Gem Installation
|
15
|
+
|
16
|
+
gem update --system
|
17
|
+
gem install gemcutter
|
18
|
+
gem tumble
|
19
|
+
gem install www-favicon
|
20
|
+
|
21
|
+
== Features/Problems
|
22
|
+
|
23
|
+
== Synopsis
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'www-favicon'
|
27
|
+
|
28
|
+
favicon = WWW::Favicon.new
|
29
|
+
favicon_url = favicon.find('http://www.google.com/')
|
30
|
+
|
31
|
+
== Copyright
|
32
|
+
|
33
|
+
Author:: youpy <youpy@buycheapviagraonlinenow.com>
|
34
|
+
Copyright:: Copyright (c) 2008 youpy
|
35
|
+
License:: The MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/sshpublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
$LOAD_PATH << File.dirname(__FILE__) + '/lib/'
|
12
|
+
require 'www/favicon'
|
13
|
+
|
14
|
+
include FileUtils
|
15
|
+
|
16
|
+
NAME = "www-favicon"
|
17
|
+
AUTHOR = "youpy"
|
18
|
+
EMAIL = "youpy@buycheapviagraonlinenow.com"
|
19
|
+
DESCRIPTION = "find favicon url"
|
20
|
+
BIN_FILES = %w( )
|
21
|
+
VERS = WWW::Favicon::VERSION
|
22
|
+
|
23
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
|
+
RDOC_OPTS = [
|
26
|
+
'--title', "#{NAME} documentation",
|
27
|
+
"--charset", "utf-8",
|
28
|
+
"--opname", "index.html",
|
29
|
+
"--line-numbers",
|
30
|
+
"--main", "README.rdoc",
|
31
|
+
"--inline-source",
|
32
|
+
]
|
33
|
+
|
34
|
+
task :default => [:spec]
|
35
|
+
task :package => [:clean]
|
36
|
+
|
37
|
+
Spec::Rake::SpecTask.new do |t|
|
38
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
39
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
40
|
+
t.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
spec = Gem::Specification.new do |s|
|
44
|
+
s.name = NAME
|
45
|
+
s.version = VERS
|
46
|
+
s.platform = Gem::Platform::RUBY
|
47
|
+
s.has_rdoc = true
|
48
|
+
s.extra_rdoc_files = ["README.rdoc", "ChangeLog"]
|
49
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
50
|
+
s.summary = DESCRIPTION
|
51
|
+
s.description = DESCRIPTION
|
52
|
+
s.author = AUTHOR
|
53
|
+
s.email = EMAIL
|
54
|
+
s.executables = BIN_FILES
|
55
|
+
s.bindir = "bin"
|
56
|
+
s.require_path = "lib"
|
57
|
+
s.autorequire = ""
|
58
|
+
s.test_files = Dir["test/test_*.rb"]
|
59
|
+
|
60
|
+
s.add_dependency('hpricot', '>= 0')
|
61
|
+
#s.required_ruby_version = '>= 1.8.2'
|
62
|
+
|
63
|
+
s.files = %w(README.rdoc ChangeLog Rakefile) +
|
64
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
65
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
66
|
+
Dir.glob("examples/**/*.rb") +
|
67
|
+
Dir.glob("tools/*.rb")
|
68
|
+
|
69
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
70
|
+
end
|
71
|
+
|
72
|
+
Rake::GemPackageTask.new(spec) do |p|
|
73
|
+
p.need_tar = true
|
74
|
+
p.gem_spec = spec
|
75
|
+
end
|
76
|
+
|
77
|
+
task :install do
|
78
|
+
name = "#{NAME}-#{VERS}.gem"
|
79
|
+
sh %{rake package}
|
80
|
+
sh %{sudo gem install pkg/#{name}}
|
81
|
+
end
|
82
|
+
|
83
|
+
task :uninstall => [:clean] do
|
84
|
+
sh %{sudo gem uninstall #{NAME}}
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
Rake::RDocTask.new do |rdoc|
|
89
|
+
rdoc.rdoc_dir = 'html'
|
90
|
+
rdoc.options += RDOC_OPTS
|
91
|
+
rdoc.template = "resh"
|
92
|
+
#rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
93
|
+
if ENV['DOC_FILES']
|
94
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
95
|
+
else
|
96
|
+
rdoc.rdoc_files.include('README.rdoc', 'ChangeLog')
|
97
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
98
|
+
rdoc.rdoc_files.include('ext/**/*.c')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc 'Show information about the gem.'
|
103
|
+
task :debug_gem do
|
104
|
+
puts spec.to_ruby
|
105
|
+
end
|
data/lib/www/favicon.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/https'
|
4
|
+
require 'hpricot'
|
5
|
+
|
6
|
+
module WWW
|
7
|
+
class Favicon
|
8
|
+
VERSION = '0.0.4'
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(url)
|
15
|
+
html = request(URI(url)).body
|
16
|
+
find_from_html(html, url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_from_html(html, url)
|
20
|
+
uri = URI(url)
|
21
|
+
favicon_url = find_from_link(html, uri) || try_default_path(uri)
|
22
|
+
if @options[:verify]
|
23
|
+
favicon_url = nil unless valid_favicon_url?(favicon_url)
|
24
|
+
end
|
25
|
+
favicon_url
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_favicon_url?(url)
|
29
|
+
response = request(URI.parse(url))
|
30
|
+
|
31
|
+
(
|
32
|
+
response.code =~ /\A2/ &&
|
33
|
+
response.body.to_s != '' &&
|
34
|
+
response.content_type =~ /image/i
|
35
|
+
) ? true : false
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def find_from_link(html, uri)
|
41
|
+
doc = Hpricot(html)
|
42
|
+
|
43
|
+
doc.search('//link').each do |link|
|
44
|
+
if link[:rel] =~ /^(shortcut )?icon$/i
|
45
|
+
favicon_url_or_path = link[:href]
|
46
|
+
|
47
|
+
if favicon_url_or_path =~ /^http/
|
48
|
+
return favicon_url_or_path
|
49
|
+
else
|
50
|
+
return URI.join(uri.to_s, favicon_url_or_path).to_s
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def try_default_path(uri)
|
59
|
+
uri.path = '/favicon.ico'
|
60
|
+
%w[query fragment].each do |element|
|
61
|
+
uri.send element + '=', nil
|
62
|
+
end
|
63
|
+
|
64
|
+
response = request(uri, 'head')
|
65
|
+
|
66
|
+
case response.code.split('').first
|
67
|
+
when '2'
|
68
|
+
return uri.to_s
|
69
|
+
when '3'
|
70
|
+
return response['Location']
|
71
|
+
end
|
72
|
+
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def request(uri, method = 'get')
|
77
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
78
|
+
|
79
|
+
if uri.scheme == 'https'
|
80
|
+
http.use_ssl = true
|
81
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
82
|
+
end
|
83
|
+
|
84
|
+
http.start do |http|
|
85
|
+
path =
|
86
|
+
(uri.path.empty? ? '/' : uri.path) +
|
87
|
+
(uri.query ? '?' + uri.query : '') +
|
88
|
+
(uri.fragment ? '#' + uri.fragment : '')
|
89
|
+
response = http.send(method, path)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: www-favicon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- youpy
|
8
|
+
autorequire: ""
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-06 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: find favicon url
|
26
|
+
email: youpy@buycheapviagraonlinenow.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- ChangeLog
|
34
|
+
files:
|
35
|
+
- README.rdoc
|
36
|
+
- ChangeLog
|
37
|
+
- Rakefile
|
38
|
+
- lib/www/favicon.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage:
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --title
|
46
|
+
- www-favicon documentation
|
47
|
+
- --charset
|
48
|
+
- utf-8
|
49
|
+
- --opname
|
50
|
+
- index.html
|
51
|
+
- --line-numbers
|
52
|
+
- --main
|
53
|
+
- README.rdoc
|
54
|
+
- --inline-source
|
55
|
+
- --exclude
|
56
|
+
- ^(examples|extras)/
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: find favicon url
|
78
|
+
test_files: []
|
79
|
+
|