flavicon 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +14 -0
- data/README.md +5 -0
- data/VERSION +1 -1
- data/flavicon.gemspec +85 -0
- data/lib/flavicon/finder.rb +5 -4
- data/spec/flavicon/finder_spec.rb +73 -14
- data/spec/spec_helper.rb +7 -0
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb77bbe0910de976833f57dcac196e53ea950339
|
|
4
|
+
data.tar.gz: d6a108eb16a4657f6cde6eca58046a2f01e6d69c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d6d4fe83925c84bc05e9a6ba5c982b91c7680769dc16a696505ccb314a590de97a6218ba9bb122da194ace43ba0e6d2ed93bc3962f64583ab7fc3d8ddc8365b
|
|
7
|
+
data.tar.gz: edef26f6b50cf155d161a415ebd80efccc46c0add83dd2387b3f4d00107d91a72f1981274a5dec48c86e1c00c0958a9cbdee7c973ca073c837d14c1cc48775a5
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -4,6 +4,12 @@ GEM
|
|
|
4
4
|
addressable (2.3.6)
|
|
5
5
|
builder (3.2.2)
|
|
6
6
|
coderay (1.1.0)
|
|
7
|
+
coveralls (0.7.0)
|
|
8
|
+
multi_json (~> 1.3)
|
|
9
|
+
rest-client
|
|
10
|
+
simplecov (>= 0.7)
|
|
11
|
+
term-ansicolor
|
|
12
|
+
thor
|
|
7
13
|
crack (0.4.2)
|
|
8
14
|
safe_yaml (~> 1.0.0)
|
|
9
15
|
descendants_tracker (0.0.4)
|
|
@@ -36,6 +42,7 @@ GEM
|
|
|
36
42
|
jwt (0.1.11)
|
|
37
43
|
multi_json (>= 1.5)
|
|
38
44
|
method_source (0.8.2)
|
|
45
|
+
mime-types (2.2)
|
|
39
46
|
mini_portile (0.5.3)
|
|
40
47
|
multi_json (1.9.2)
|
|
41
48
|
multi_xml (0.5.5)
|
|
@@ -56,6 +63,8 @@ GEM
|
|
|
56
63
|
rake (10.3.1)
|
|
57
64
|
rdoc (3.12.2)
|
|
58
65
|
json (~> 1.4)
|
|
66
|
+
rest-client (1.6.7)
|
|
67
|
+
mime-types (>= 1.16)
|
|
59
68
|
rspec (2.14.1)
|
|
60
69
|
rspec-core (~> 2.14.0)
|
|
61
70
|
rspec-expectations (~> 2.14.0)
|
|
@@ -71,7 +80,11 @@ GEM
|
|
|
71
80
|
simplecov-html (~> 0.8.0)
|
|
72
81
|
simplecov-html (0.8.0)
|
|
73
82
|
slop (3.5.0)
|
|
83
|
+
term-ansicolor (1.3.0)
|
|
84
|
+
tins (~> 1.0)
|
|
85
|
+
thor (0.19.1)
|
|
74
86
|
thread_safe (0.3.3)
|
|
87
|
+
tins (1.1.0)
|
|
75
88
|
webmock (1.17.4)
|
|
76
89
|
addressable (>= 2.2.7)
|
|
77
90
|
crack (>= 0.3.2)
|
|
@@ -81,6 +94,7 @@ PLATFORMS
|
|
|
81
94
|
|
|
82
95
|
DEPENDENCIES
|
|
83
96
|
bundler (~> 1.0)
|
|
97
|
+
coveralls
|
|
84
98
|
jeweler (~> 2.0)
|
|
85
99
|
nokogiri (~> 1.6)
|
|
86
100
|
pry (~> 0)
|
data/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
[](https://travis-ci.org/hasghari/flavicon)
|
|
2
|
+
[](https://codeclimate.com/github/hasghari/flavicon)
|
|
3
|
+
[](https://coveralls.io/r/hasghari/flavicon)
|
|
4
|
+
[](http://badge.fury.io/rb/flavicon)
|
|
5
|
+
|
|
1
6
|
# flavicon
|
|
2
7
|
|
|
3
8
|
Disclaimer: This is a rewrite of the [www-favicon](https://github.com/youpy/www-favicon) gem for a couple reasons:
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
data/flavicon.gemspec
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: flavicon 0.1.1 ruby lib
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = "flavicon"
|
|
9
|
+
s.version = "0.1.1"
|
|
10
|
+
|
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib"]
|
|
13
|
+
s.authors = ["Hamed Asghari"]
|
|
14
|
+
s.date = "2016-09-22"
|
|
15
|
+
s.description = "fetch favicon url by parsing html and falling back on /favicon.ico as default"
|
|
16
|
+
s.email = "hasghari@gmail.com"
|
|
17
|
+
s.extra_rdoc_files = [
|
|
18
|
+
"LICENSE.txt",
|
|
19
|
+
"README.md"
|
|
20
|
+
]
|
|
21
|
+
s.files = [
|
|
22
|
+
".document",
|
|
23
|
+
".rspec",
|
|
24
|
+
".ruby-gemset",
|
|
25
|
+
".ruby-version",
|
|
26
|
+
".travis.yml",
|
|
27
|
+
"Gemfile",
|
|
28
|
+
"Gemfile.lock",
|
|
29
|
+
"LICENSE.txt",
|
|
30
|
+
"README.md",
|
|
31
|
+
"Rakefile",
|
|
32
|
+
"VERSION",
|
|
33
|
+
"flavicon.gemspec",
|
|
34
|
+
"lib/flavicon.rb",
|
|
35
|
+
"lib/flavicon/finder.rb",
|
|
36
|
+
"spec/fixtures/absolute.html",
|
|
37
|
+
"spec/fixtures/missing.html",
|
|
38
|
+
"spec/fixtures/multiple.html",
|
|
39
|
+
"spec/fixtures/relative.html",
|
|
40
|
+
"spec/flavicon/finder_spec.rb",
|
|
41
|
+
"spec/flavicon_spec.rb",
|
|
42
|
+
"spec/spec_helper.rb"
|
|
43
|
+
]
|
|
44
|
+
s.homepage = "http://github.com/hasghari/flavicon"
|
|
45
|
+
s.licenses = ["MIT"]
|
|
46
|
+
s.rubygems_version = "2.2.2"
|
|
47
|
+
s.summary = "fetch favicon url for provided url"
|
|
48
|
+
|
|
49
|
+
if s.respond_to? :specification_version then
|
|
50
|
+
s.specification_version = 4
|
|
51
|
+
|
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
53
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.6"])
|
|
54
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.14"])
|
|
55
|
+
s.add_development_dependency(%q<webmock>, ["~> 1.17"])
|
|
56
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
57
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
|
58
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
|
59
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0"])
|
|
60
|
+
s.add_development_dependency(%q<pry>, ["~> 0"])
|
|
61
|
+
s.add_development_dependency(%q<coveralls>, [">= 0"])
|
|
62
|
+
else
|
|
63
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.6"])
|
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.14"])
|
|
65
|
+
s.add_dependency(%q<webmock>, ["~> 1.17"])
|
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
|
69
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
|
70
|
+
s.add_dependency(%q<pry>, ["~> 0"])
|
|
71
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.6"])
|
|
75
|
+
s.add_dependency(%q<rspec>, ["~> 2.14"])
|
|
76
|
+
s.add_dependency(%q<webmock>, ["~> 1.17"])
|
|
77
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
|
80
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
|
81
|
+
s.add_dependency(%q<pry>, ["~> 0"])
|
|
82
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
data/lib/flavicon/finder.rb
CHANGED
|
@@ -9,12 +9,13 @@ module Flavicon
|
|
|
9
9
|
def find
|
|
10
10
|
response, resolved = request(url)
|
|
11
11
|
favicon_url = extract_from_html(response.body, resolved) || default_path(resolved)
|
|
12
|
-
|
|
12
|
+
verify_favicon_url(favicon_url)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def
|
|
16
|
-
response,
|
|
17
|
-
response.is_a?(Net::HTTPSuccess) && response.body.to_s != '' && response.content_type =~ /image/i
|
|
15
|
+
def verify_favicon_url(url)
|
|
16
|
+
response, resolved = request(url)
|
|
17
|
+
return unless response.is_a?(Net::HTTPSuccess) && response.body.to_s != '' && response.content_type =~ /image/i
|
|
18
|
+
resolved
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def extract_from_html(html, url)
|
|
@@ -2,15 +2,45 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
|
2
2
|
require 'flavicon/finder'
|
|
3
3
|
|
|
4
4
|
describe Flavicon::Finder do
|
|
5
|
+
def html(file)
|
|
6
|
+
File.read(File.expand_path(File.dirname(__FILE__) + "/../fixtures/#{file}"))
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
subject { Flavicon::Finder.new('http://www.ex.com') }
|
|
6
10
|
|
|
7
11
|
describe '#find' do
|
|
8
|
-
it '' do
|
|
12
|
+
it 'should delegate to #request' do
|
|
13
|
+
response = double('response', body: html('absolute.html'))
|
|
14
|
+
subject.should_receive(:request).with('http://www.ex.com').and_return([response, 'http://www.other.com'])
|
|
15
|
+
subject.should_receive(:verify_favicon_url).and_return('http://sub.example.com/absolute.ico')
|
|
16
|
+
subject.find
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should extract favicon from body' do
|
|
20
|
+
response = double('response', body: html('absolute.html'))
|
|
21
|
+
subject.should_receive(:request).with('http://www.ex.com').and_return([response, 'http://www.other.com'])
|
|
22
|
+
subject.should_receive(:verify_favicon_url).with('http://sub.example.com/absolute.ico')
|
|
23
|
+
.and_return('http://sub.example.com/absolute.ico')
|
|
24
|
+
subject.find.should == 'http://sub.example.com/absolute.ico'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should fallback to default when response is empty' do
|
|
28
|
+
response = double('response', body: '')
|
|
29
|
+
subject.should_receive(:request).with('http://www.ex.com').and_return([response, 'http://www.other.com'])
|
|
30
|
+
subject.should_receive(:verify_favicon_url).with('http://www.other.com/favicon.ico')
|
|
31
|
+
.and_return('http://www.other.com/favicon.ico')
|
|
32
|
+
subject.find.should == 'http://www.other.com/favicon.ico'
|
|
33
|
+
end
|
|
9
34
|
|
|
35
|
+
it 'should return nil when not valid' do
|
|
36
|
+
response = double('response', body: html('absolute.html'))
|
|
37
|
+
subject.should_receive(:request).with('http://www.ex.com').and_return([response, 'http://www.other.com'])
|
|
38
|
+
subject.should_receive(:verify_favicon_url).and_return(nil)
|
|
39
|
+
subject.find.should be_nil
|
|
10
40
|
end
|
|
11
41
|
end
|
|
12
42
|
|
|
13
|
-
describe '#
|
|
43
|
+
describe '#verify_favicon_url' do
|
|
14
44
|
let(:favicon_url) { 'http://www.ex.com/favicon.ico' }
|
|
15
45
|
let(:response) do
|
|
16
46
|
{ status: 200, body: 'blah', headers: { 'Content-Type' => 'image/x-icon'} }
|
|
@@ -20,8 +50,8 @@ describe Flavicon::Finder do
|
|
|
20
50
|
stub_request(:get, favicon_url).to_return(response)
|
|
21
51
|
end
|
|
22
52
|
|
|
23
|
-
it 'should
|
|
24
|
-
subject.
|
|
53
|
+
it 'should return favicon url' do
|
|
54
|
+
subject.verify_favicon_url(favicon_url).should == favicon_url
|
|
25
55
|
end
|
|
26
56
|
|
|
27
57
|
context 'http failure' do
|
|
@@ -29,8 +59,8 @@ describe Flavicon::Finder do
|
|
|
29
59
|
{ status: 400, body: 'blah', headers: { 'Content-Type' => 'image/x-icon'} }
|
|
30
60
|
end
|
|
31
61
|
|
|
32
|
-
it 'should
|
|
33
|
-
subject.
|
|
62
|
+
it 'should return nil' do
|
|
63
|
+
subject.verify_favicon_url(favicon_url).should be_nil
|
|
34
64
|
end
|
|
35
65
|
end
|
|
36
66
|
|
|
@@ -39,8 +69,8 @@ describe Flavicon::Finder do
|
|
|
39
69
|
{ status: 200, body: '', headers: { 'Content-Type' => 'image/x-icon'} }
|
|
40
70
|
end
|
|
41
71
|
|
|
42
|
-
it 'should
|
|
43
|
-
subject.
|
|
72
|
+
it 'should return nil' do
|
|
73
|
+
subject.verify_favicon_url(favicon_url).should be_nil
|
|
44
74
|
end
|
|
45
75
|
end
|
|
46
76
|
|
|
@@ -49,17 +79,13 @@ describe Flavicon::Finder do
|
|
|
49
79
|
{ status: 200, body: 'blah', headers: { 'Content-Type' => 'text/javascript'} }
|
|
50
80
|
end
|
|
51
81
|
|
|
52
|
-
it 'should
|
|
53
|
-
subject.
|
|
82
|
+
it 'should return nil' do
|
|
83
|
+
subject.verify_favicon_url(favicon_url).should be_nil
|
|
54
84
|
end
|
|
55
85
|
end
|
|
56
86
|
end
|
|
57
87
|
|
|
58
88
|
describe '#extract_from_html' do
|
|
59
|
-
def html(file)
|
|
60
|
-
File.read(File.expand_path(File.dirname(__FILE__) + "/../fixtures/#{file}"))
|
|
61
|
-
end
|
|
62
|
-
|
|
63
89
|
it 'should return nil for empty body' do
|
|
64
90
|
subject.extract_from_html('', 'http://www.ex.com').should be_nil
|
|
65
91
|
end
|
|
@@ -84,6 +110,24 @@ describe Flavicon::Finder do
|
|
|
84
110
|
end
|
|
85
111
|
end
|
|
86
112
|
|
|
113
|
+
describe '#default_path' do
|
|
114
|
+
it 'should return default favicon url' do
|
|
115
|
+
subject.default_path('http://www.basic.com').should == 'http://www.basic.com/favicon.ico'
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'ignores query and fragment' do
|
|
119
|
+
subject.default_path('http://www.basic.com?query=a#fragment').should == 'http://www.basic.com/favicon.ico'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'ignores path with no trailing slash' do
|
|
123
|
+
subject.default_path('http://www.basic.com/basic').should == 'http://www.basic.com/favicon.ico'
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'ignores path with trailing slash' do
|
|
127
|
+
subject.default_path('http://www.basic.com/basic/').should == 'http://www.basic.com/favicon.ico'
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
87
131
|
describe '#request' do
|
|
88
132
|
before do
|
|
89
133
|
stub_request(:get, 'http://www.ex.com/abc/')
|
|
@@ -102,6 +146,21 @@ describe Flavicon::Finder do
|
|
|
102
146
|
url.should == 'http://www.ex.com/abc/'
|
|
103
147
|
end
|
|
104
148
|
|
|
149
|
+
context 'ssl' do
|
|
150
|
+
before do
|
|
151
|
+
stub_request(:get, 'http://secure.ex.com:443/abc/')
|
|
152
|
+
.to_return(status: 200, body: '', headers: {})
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'should set http secure state' do
|
|
156
|
+
Net::HTTP.any_instance.should_receive(:use_ssl=).with(true)
|
|
157
|
+
Net::HTTP.any_instance.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
|
158
|
+
response, url = subject.request('https://secure.ex.com/abc/')
|
|
159
|
+
response.should be_a Net::HTTPSuccess
|
|
160
|
+
url.should == 'https://secure.ex.com/abc/'
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
105
164
|
context 'redirect' do
|
|
106
165
|
before do
|
|
107
166
|
stub_request(:get, 'http://www.ex.com/abc')
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'simplecov'
|
|
2
|
+
require 'coveralls'
|
|
2
3
|
|
|
3
4
|
module SimpleCov::Configuration
|
|
4
5
|
def clean_filters
|
|
@@ -11,9 +12,15 @@ SimpleCov.configure do
|
|
|
11
12
|
load_profile 'test_frameworks'
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
16
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
17
|
+
Coveralls::SimpleCov::Formatter
|
|
18
|
+
]
|
|
19
|
+
|
|
14
20
|
ENV['COVERAGE'] && SimpleCov.start do
|
|
15
21
|
add_filter '/.rvm/'
|
|
16
22
|
end
|
|
23
|
+
|
|
17
24
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
18
25
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
19
26
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flavicon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hamed Asghari
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|
|
@@ -122,6 +122,20 @@ dependencies:
|
|
|
122
122
|
- - "~>"
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
124
|
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: coveralls
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
125
139
|
description: fetch favicon url by parsing html and falling back on /favicon.ico as
|
|
126
140
|
default
|
|
127
141
|
email: hasghari@gmail.com
|
|
@@ -135,12 +149,14 @@ files:
|
|
|
135
149
|
- ".rspec"
|
|
136
150
|
- ".ruby-gemset"
|
|
137
151
|
- ".ruby-version"
|
|
152
|
+
- ".travis.yml"
|
|
138
153
|
- Gemfile
|
|
139
154
|
- Gemfile.lock
|
|
140
155
|
- LICENSE.txt
|
|
141
156
|
- README.md
|
|
142
157
|
- Rakefile
|
|
143
158
|
- VERSION
|
|
159
|
+
- flavicon.gemspec
|
|
144
160
|
- lib/flavicon.rb
|
|
145
161
|
- lib/flavicon/finder.rb
|
|
146
162
|
- spec/fixtures/absolute.html
|