favicon_extractor 0.1.0 → 0.1.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
  SHA256:
3
- metadata.gz: b44ee0289ac7c0c1df82a2b3d88feeae973629d580fc68dfc051a9451ba85ff5
4
- data.tar.gz: bd3723310fa22090b0e49a7d6aede1e2d0ccc9ebf6842bbafdfe59515af87b3f
3
+ metadata.gz: 187e199988b118245705c57d38190d320b5762f9a524d6c6b3c0a4981e91b142
4
+ data.tar.gz: be53d57f3048b09384f561ee11f811283623d65db04bf164bd87f2e393ac227a
5
5
  SHA512:
6
- metadata.gz: dd75749abe808208f3d2b2be8bf61fdc76569e126fe51c4b19d481f93a2a1d678c9835edb591d5fbe6f568c9238c0c2bf8249717b94b1d84ad5b0622338dc644
7
- data.tar.gz: 22e4faefc50ce89187f7d0a19ec05cdbe5eb8a4d2f206bb9a119d2b76189ff64e648a3179d6a7fcec2c89dd6d4c62614a26b1c46da28b15aafecb93a91de0182
6
+ metadata.gz: 2948579cd27161d98505c7caea5c66797ae3fa0f62e67bf16f83f26f0f6976ecb022e325b74f43f6f60f14421137327e03c9233f814afa072e66499d9c34498e
7
+ data.tar.gz: cf3d613a3deb6ddbfd295db1d863751fe83b92fdd835559e0742224e54f27f74bffcad845421b367668bb7f5ab764841b6bbbb4a7bd1bf3d2ae0279ce2431748
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- favicon_extractor (0.1.0)
4
+ favicon_extractor (0.1.2)
5
5
  fastimage (~> 2.2)
6
6
 
7
7
  GEM
@@ -54,6 +54,7 @@ GEM
54
54
 
55
55
  PLATFORMS
56
56
  x86_64-darwin-21
57
+ x86_64-linux
57
58
 
58
59
  DEPENDENCIES
59
60
  fastimage (~> 2.2)
data/README.md CHANGED
@@ -14,7 +14,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
 
15
15
  ## Usage
16
16
 
17
- ```
17
+ ```ruby
18
18
  require 'favicon_extractor'
19
19
 
20
20
  FaviconExtractor.extract("http://google.com")
@@ -29,7 +29,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
29
29
 
30
30
  ## Contributing
31
31
 
32
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/favicon_extractor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/favicon_extractor/blob/master/CODE_OF_CONDUCT.md).
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/leeourand/favicon_extractor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/leeourand/favicon_extractor/blob/master/CODE_OF_CONDUCT.md).
33
33
 
34
34
  ## License
35
35
 
@@ -37,4 +37,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
37
37
 
38
38
  ## Code of Conduct
39
39
 
40
- Everyone interacting in the FaviconExtractor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/favicon_extractor/blob/master/CODE_OF_CONDUCT.md).
40
+ Everyone interacting in the FaviconExtractor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/leeourand/favicon_extractor/blob/master/CODE_OF_CONDUCT.md).
@@ -1,12 +1,14 @@
1
+ require 'pry'
1
2
  module FaviconExtractor
2
3
  class ExtractsFaviconsFromHtml
3
4
  class << self
4
5
  def extract(html, url)
5
- html.scan(/<link.*icon.*>/).flatten.map do |str|
6
+ @url = url
7
+ html.scan(/<link.*?icon.*?>/).flatten.map do |str|
6
8
  str.match(/href="(.*?)"/).captures.first
7
9
  end
8
10
  .map { |str| handle_relative_paths(str) }
9
- .append(default_favicon_for(url))
11
+ .append(default_favicon)
10
12
  end
11
13
 
12
14
  private
@@ -15,7 +17,7 @@ module FaviconExtractor
15
17
 
16
18
  def handle_relative_paths(str)
17
19
  if str.start_with?("/")
18
- uri = URI(url)
20
+ uri = URI(@url)
19
21
  uri.path = str
20
22
  uri.to_s
21
23
  else
@@ -23,8 +25,8 @@ module FaviconExtractor
23
25
  end
24
26
  end
25
27
 
26
- def default_favicon_for(url)
27
- uri = URI(url)
28
+ def default_favicon
29
+ uri = URI(@url)
28
30
  uri.path = DEFAULT_FAVICON_PATH
29
31
  uri.to_s
30
32
  end
@@ -1,27 +1,36 @@
1
1
  module FaviconExtractor
2
2
  class MakesHttpRequests
3
3
  def self.request(location)
4
- new.request(location)
4
+ new(location).request
5
5
  end
6
6
 
7
- def initialize
7
+ def initialize(url)
8
8
  @redirect_limit = 10
9
9
  @redirects = 0
10
+ @url = url
10
11
  end
11
12
 
12
- def request(location)
13
+ def request
13
14
  raise ArgumentError, "too many redirects" if @redirects > redirect_limit
14
15
 
15
16
  begin
16
- response = Net::HTTP.get_response(URI(location))
17
+ uri = URI(url)
18
+ response = Net::HTTP.start(uri.host,
19
+ uri.port,
20
+ read_timeout: 10,
21
+ open_timeout: 10,
22
+ ssl_timeout: 10,
23
+ use_ssl: uri.scheme == "https") do |http|
24
+ http.request(Net::HTTP::Get.new(uri))
25
+ end
17
26
 
18
27
  case response
19
28
  when Net::HTTPSuccess
20
29
  response.body
21
30
  when Net::HTTPRedirection
22
31
  @redirects += 1
23
- location = response["location"]
24
- request(location)
32
+ @url = response["location"]
33
+ request
25
34
  else
26
35
  response.value
27
36
  end
@@ -30,6 +39,6 @@ module FaviconExtractor
30
39
 
31
40
  private
32
41
 
33
- attr_reader :redirect_limit
42
+ attr_reader :redirect_limit, :url
34
43
  end
35
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FaviconExtractor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favicon_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Ourand