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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04c20f8f3afd2ba553493eaccc622a53e8475d52
4
- data.tar.gz: 9236896799c20478321d54209c26c6bdd88bf9b7
3
+ metadata.gz: ef9b824cda0cae36de3a07037a15c0d81544b4f8
4
+ data.tar.gz: 6d3240def0f41df85d8eb49c96719af79d982104
5
5
  SHA512:
6
- metadata.gz: 675b832b0921b0570a077627428da752f3272d35b500798d72e7539727da2c4153b6e474bdd2307776bcd1842b20252e0cfc3a4062574988dfe883b9fe6192e2
7
- data.tar.gz: 764055135af45b2d82ae4cc1f30150942e2ec89c46ea6a65051bf51921370a3dd28b2806a53d6c0bab3716ff492fd1838ba54fe07023dc8861ed317ffa6b31c9
6
+ metadata.gz: 452738e3e43e306b5dce0975f1bcab0530a6d0a78fe7f112f2d7e1633e2ef492e71056ea5a87d778627ff686a2640991952fbda3ef243da0f6b85eca5f77c660
7
+ data.tar.gz: 962ffa342e40859c5cde56c50bd3387663c2343a925c8d6064141d3541f7a9393b63d08b971400387bf292fabf7f9b7a72e57d4e578bc5571b8c9dd0ad846b71
data/README.md CHANGED
@@ -1,52 +1,75 @@
1
- # Favicon Party
1
+ ![Favicon Party](https://cloud.githubusercontent.com/assets/208617/11496590/d4b1f6dc-97c7-11e5-8e09-e61e50274e31.png)
2
2
 
3
- Fetch favicons from websites and convert them into other image formats!
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
- Favicon Party parses the html response of the query url to find favicon
9
- links, and falls back to checking /favicon.ico for valid favicon images.
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! "https://github.com"
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
- # => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
33
+ ```ruby
34
+ FaviconParty.fetch! "http://example.com" # raises FaviconNotFound
35
+ FaviconParty.fetch "http://example.com" # nil
36
+ ```
15
37
 
16
- image.valid? # true
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 files directly as well.
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
- # => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
58
+ image.valid? # true
35
59
  ```
36
60
 
37
- Same for loading favicon URLs.
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
- Favicon Party also provides a command-line script for fetching favicons. By
49
- default, it attempts to fetch a favicon from the given URL and prints it out.
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+
@@ -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 websites and have a blast!"
16
- s.description = "Fetch favicons from websites and have a blast!"
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(curl_cmd(url))
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
- `#{curl_cmd(url)} 2>/dev/null`
35
+ `#{curl_get_cmd(url)} 2>/dev/null`
40
36
  end
41
37
 
42
38
  def head(url)
43
- headers = `curl -sIL -1 --ciphers 'RC4,3DES,ALL' -m #{TIMEOUT} "#{url}"`
44
- encode_utf8 headers
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
@@ -1,3 +1,3 @@
1
1
  module FaviconParty
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -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.2
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-29 00:00:00.000000000 Z
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 websites and have a blast!
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 websites and have a blast!
128
+ summary: Fetch favicons from webpages and have a blast!
128
129
  test_files: []