youpy-www-favicon 0.0.1

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