favico 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b1a6d70a1e060feda07d9d2e4b36fc884379c0a
4
+ data.tar.gz: 941d2b5a40a0f18101ae90b0fce4bfe6489df1e6
5
+ SHA512:
6
+ metadata.gz: 933d66a4e57d97c4603f203e37e1e65599e8a75c0fdf98a80f7701f876b7e233542945a562eab396523ac33a16a245eeea1b1cd392b16ff92dc51c60f64b7aea
7
+ data.tar.gz: 506ac046622b11476d27a48cafd318f44d8042521e0661e185087dce3d71a4e53705058eee584b375efeee7f745866fbda2533cfb905d25dd2c1192d8390d752
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+ gem 'nokogiri'
3
+ gem 'httparty'
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ httparty (0.11.0)
5
+ multi_json (~> 1.0)
6
+ multi_xml (>= 0.5.2)
7
+ multi_json (1.7.3)
8
+ multi_xml (0.5.3)
9
+ nokogiri (1.5.9)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ httparty
16
+ nokogiri
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ A simple favicon parser which lets you grab favicons from almost any website
2
+ with a fairly simple interface. Mostly created because I was slightly bored.
3
+
4
+ ```
5
+ fparser = Favicon::Parser.new
6
+ fparser.fetch_favicon("http://www.google.com")
7
+ => "http://www.google.com/favicon.ico"
8
+ ```
9
+
10
+ That's about it. It'll be useful for creating your own favicon fetcher or something
11
+ else that you need them for.
data/favico.gemspec ADDED
@@ -0,0 +1,16 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'lib/favico/version')
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "favico"
6
+ s.version = "0.0.1"
7
+ s.date = "2013-05-26"
8
+ s.summary = "Grabs the favicon of any website you want with a simple interface"
9
+ s.description = %q{Grabs the favicon of any website you want}
10
+ s.authors = ["John Bunting"]
11
+ s.email = "codingjester@gmail.com"
12
+ s.files = `git ls-files`.split("\n")
13
+ s.homepage = "http://github.com/codingjester/favico"
14
+ s.require_paths = ["lib"]
15
+ s.version = Favico::VERSION
16
+ end
data/lib/favico.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'favico/parser'
2
+
3
+ module Favico
4
+ class Parser
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ require 'nokogiri'
2
+ require 'httparty'
3
+
4
+ module Favico
5
+ class Parser
6
+ include HTTParty
7
+
8
+ def root_favicon?(url)
9
+ url = url + "/favicon.ico"
10
+ response = self.class.head(url)
11
+ return response.code == 200
12
+ end
13
+
14
+ def fetch_favicon(url)
15
+ if root_favicon?(url)
16
+ return url + "/favicon.ico"
17
+ end
18
+ parse_favicon(url)
19
+ end
20
+
21
+ def parse_favicon(url)
22
+ response = self.class.get(url)
23
+ favicon = xpath_parse(response.body)
24
+ if (!favicon.start_with?("http"))
25
+ favicon = url + "/" + favicon
26
+ end
27
+ favicon
28
+ end
29
+
30
+ def xpath_parse(body)
31
+ doc = Nokogiri::HTML(body)
32
+ doc.xpath("//link[contains(@rel, 'icon')]/@href")[0].value
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Favico
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: favico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Bunting
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Grabs the favicon of any website you want
14
+ email: codingjester@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Gemfile
20
+ - Gemfile.lock
21
+ - README.md
22
+ - favico.gemspec
23
+ - lib/favico.rb
24
+ - lib/favico/parser.rb
25
+ - lib/favico/version.rb
26
+ homepage: http://github.com/codingjester/favico
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Grabs the favicon of any website you want with a simple interface
49
+ test_files: []