favicon_party 0.7.2 → 0.7.3
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/README.md +41 -27
- data/favicon_party.gemspec +2 -2
- data/lib/favicon_party/http_client.rb +25 -11
- data/lib/favicon_party/version.rb +1 -1
- data/test/http_client_test.rb +35 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef9b824cda0cae36de3a07037a15c0d81544b4f8
|
|
4
|
+
data.tar.gz: 6d3240def0f41df85d8eb49c96719af79d982104
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 452738e3e43e306b5dce0975f1bcab0530a6d0a78fe7f112f2d7e1633e2ef492e71056ea5a87d778627ff686a2640991952fbda3ef243da0f6b85eca5f77c660
|
|
7
|
+
data.tar.gz: 962ffa342e40859c5cde56c50bd3387663c2343a925c8d6064141d3541f7a9393b63d08b971400387bf292fabf7f9b7a72e57d4e578bc5571b8c9dd0ad846b71
|
data/README.md
CHANGED
|
@@ -1,52 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
Fetch favicons from
|
|
3
|
+
Fetch favicons from webpages and convert them into various image formats!
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
You can install FaviconParty through [RubyGems](https://rubygems.org/)
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
$ gem install favicon_party
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or add it to your application's Gemfile and install via bundler
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
gem 'favicon_party'
|
|
18
|
+
```
|
|
4
19
|
|
|
5
20
|
|
|
6
21
|
## Fetching favicon images
|
|
7
22
|
|
|
8
|
-
|
|
9
|
-
links
|
|
23
|
+
FaviconParty parses the html response of the query url to find favicon
|
|
24
|
+
links and falls back to checking /favicon.ico
|
|
10
25
|
|
|
11
26
|
```ruby
|
|
12
|
-
image = FaviconParty.fetch! "
|
|
27
|
+
image = FaviconParty.fetch! "github.com"
|
|
28
|
+
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If a valid favicon isn't found:
|
|
13
32
|
|
|
14
|
-
|
|
33
|
+
```ruby
|
|
34
|
+
FaviconParty.fetch! "http://example.com" # raises FaviconNotFound
|
|
35
|
+
FaviconParty.fetch "http://example.com" # nil
|
|
36
|
+
```
|
|
15
37
|
|
|
16
|
-
|
|
38
|
+
|
|
39
|
+
## Converting favicon images
|
|
40
|
+
|
|
41
|
+
To access the source favicon data and convert it into various image formats:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
17
44
|
image.source_data # binary favicon image data
|
|
18
45
|
image.to_png # binary 16x16 png data
|
|
19
46
|
image.base64_png # base64-encoded 16x16 png data
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
FaviconParty.fetch! "http://example.com" # raises FaviconNotFound
|
|
23
|
-
FaviconParty.fetch "http://example.com" # nil
|
|
24
47
|
```
|
|
25
48
|
|
|
26
49
|
|
|
27
50
|
## Loading favicon images
|
|
28
51
|
|
|
29
|
-
You can load favicon
|
|
52
|
+
You can load favicon data from image files:
|
|
30
53
|
|
|
31
54
|
```ruby
|
|
32
55
|
image = FaviconParty.load "/path/to/favicon.ico"
|
|
56
|
+
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
|
|
33
57
|
|
|
34
|
-
#
|
|
58
|
+
image.valid? # true
|
|
35
59
|
```
|
|
36
60
|
|
|
37
|
-
|
|
61
|
+
And also load them directly from their source URLs:
|
|
38
62
|
|
|
39
63
|
```ruby
|
|
40
64
|
image = FaviconParty.load "https://github.com/favicon.ico"
|
|
41
|
-
|
|
42
|
-
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
|
|
65
|
+
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
|
|
43
66
|
```
|
|
44
67
|
|
|
45
68
|
|
|
46
69
|
## Command-line client
|
|
47
70
|
|
|
48
|
-
|
|
49
|
-
default, it attempts to fetch a favicon from the given URL and prints it
|
|
71
|
+
FaviconParty also provides a command-line script for fetching favicons. By
|
|
72
|
+
default, it attempts to fetch a favicon from the given URL and prints it to stdout.
|
|
50
73
|
Run `fetch_favicon --help` to see the list of options.
|
|
51
74
|
|
|
52
75
|
```bash
|
|
@@ -56,15 +79,6 @@ fetch_favicon example.com # prints an error to STDERR
|
|
|
56
79
|
```
|
|
57
80
|
|
|
58
81
|
|
|
59
|
-
## Installation
|
|
60
|
-
|
|
61
|
-
The best way to install Favicon Party is through [RubyGems](https://rubygems.org/)
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
$ gem install favicon_party
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
|
|
68
82
|
## Requirements
|
|
69
83
|
|
|
70
84
|
* Ruby 2.0.0+
|
data/favicon_party.gemspec
CHANGED
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.authors = ["Linmiao Xu"]
|
|
13
13
|
s.email = ["linmiao.xu@gmail.com"]
|
|
14
14
|
|
|
15
|
-
s.summary = "Fetch favicons from
|
|
16
|
-
s.description = "Fetch favicons from
|
|
15
|
+
s.summary = "Fetch favicons from webpages and have a blast!"
|
|
16
|
+
s.description = "Fetch favicons from webpages and have a blast!"
|
|
17
17
|
s.homepage = "https://github.com/linrock/favicon_party"
|
|
18
18
|
s.license = "MIT"
|
|
19
19
|
|
|
@@ -3,22 +3,18 @@ require 'open3'
|
|
|
3
3
|
|
|
4
4
|
module FaviconParty
|
|
5
5
|
|
|
6
|
+
# For now, wrap command-line curl rather than using net/http or open-uri
|
|
7
|
+
# because of easier/more reliable SSL handling
|
|
8
|
+
#
|
|
6
9
|
module HTTPClient
|
|
7
10
|
include FaviconParty::Utils
|
|
8
11
|
|
|
9
12
|
TIMEOUT = 5
|
|
10
13
|
|
|
11
|
-
# For now, wrap command-line curl rather than using net/http or open-uri
|
|
12
|
-
# because of easier/more reliable SSL handling
|
|
13
|
-
#
|
|
14
|
-
def curl_cmd(url)
|
|
15
|
-
"curl -sL -k --compressed -m #{TIMEOUT} --ciphers 'RC4,3DES,ALL' --fail --show-error '#{url}'"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
14
|
# Encodes output as utf8 - Not for binary http responses
|
|
19
15
|
#
|
|
20
16
|
def get(url)
|
|
21
|
-
stdin, stdout, stderr, t = Open3.popen3(
|
|
17
|
+
stdin, stdout, stderr, t = Open3.popen3(curl_get_cmd(url))
|
|
22
18
|
output = encode_utf8(stdout.read).strip
|
|
23
19
|
error = encode_utf8(stderr.read).strip
|
|
24
20
|
if !error.nil? && !error.empty?
|
|
@@ -36,12 +32,30 @@ module FaviconParty
|
|
|
36
32
|
# Get binary data from url and ignore errors
|
|
37
33
|
#
|
|
38
34
|
def bin_get(url)
|
|
39
|
-
`#{
|
|
35
|
+
`#{curl_get_cmd(url)} 2>/dev/null`
|
|
40
36
|
end
|
|
41
37
|
|
|
42
38
|
def head(url)
|
|
43
|
-
|
|
44
|
-
encode_utf8
|
|
39
|
+
response_headers = `#{curl_head_cmd(url)}`
|
|
40
|
+
encode_utf8 response_headers
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_curl_cmd(url, flags = "")
|
|
44
|
+
"curl #{curl_shared_flags} #{flags} '#{prefix_url(url)}'"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def curl_get_cmd(url)
|
|
48
|
+
build_curl_cmd url, "--compressed --fail --show-error"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def curl_head_cmd(url)
|
|
52
|
+
build_curl_cmd url, "-I -1"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def curl_shared_flags
|
|
58
|
+
"-sL -k -m #{TIMEOUT} --ciphers 'RC4,3DES,ALL'"
|
|
45
59
|
end
|
|
46
60
|
|
|
47
61
|
extend self
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HTTPClientTest < Minitest::Test
|
|
5
|
+
include FaviconParty::Utils
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@http_client = FaviconParty::HTTPClient
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_curl_get_cmd_prefixes_urls
|
|
12
|
+
url = "example.com"
|
|
13
|
+
cmd = @http_client.curl_get_cmd(url)
|
|
14
|
+
assert cmd.include?(prefix_url(url))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_curl_get_cmd_allows_prefixed_urls
|
|
18
|
+
url = "http://example.com"
|
|
19
|
+
cmd = @http_client.curl_get_cmd(url)
|
|
20
|
+
assert cmd.include?(prefix_url(url))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_curl_head_cmd_prefixes_urls
|
|
24
|
+
url = "example.com"
|
|
25
|
+
cmd = @http_client.curl_head_cmd(url)
|
|
26
|
+
assert cmd.include?(prefix_url(url))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_curl_head_cmd_allows_prefixed_urls
|
|
30
|
+
url = "http://example.com"
|
|
31
|
+
cmd = @http_client.curl_head_cmd(url)
|
|
32
|
+
assert cmd.include?(prefix_url(url))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: favicon_party
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Linmiao Xu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -66,7 +66,7 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '1.6'
|
|
69
|
-
description: Fetch favicons from
|
|
69
|
+
description: Fetch favicons from webpages and have a blast!
|
|
70
70
|
email:
|
|
71
71
|
- linmiao.xu@gmail.com
|
|
72
72
|
executables:
|
|
@@ -97,6 +97,7 @@ files:
|
|
|
97
97
|
- test/fixtures/favicons/white-16x16.ico
|
|
98
98
|
- test/fixtures/favicons/white-16x16.svg
|
|
99
99
|
- test/fixtures/html/page1.html
|
|
100
|
+
- test/http_client_test.rb
|
|
100
101
|
- test/image_test.rb
|
|
101
102
|
- test/loader_test.rb
|
|
102
103
|
- test/test_helper.rb
|
|
@@ -124,5 +125,5 @@ rubyforge_project:
|
|
|
124
125
|
rubygems_version: 2.4.8
|
|
125
126
|
signing_key:
|
|
126
127
|
specification_version: 4
|
|
127
|
-
summary: Fetch favicons from
|
|
128
|
+
summary: Fetch favicons from webpages and have a blast!
|
|
128
129
|
test_files: []
|