public-suffix-list 0.0.6 → 0.1.0
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.
- data/README.rdoc +25 -7
- data/lib/public_suffix_list.rb +9 -5
- data/lib/public_suffix_list/cache_file.rb +1 -1
- data/spec/public_suffix_list.spec +25 -15
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -11,7 +11,17 @@ method of finding the highest level at which a domain may be
|
|
11
11
|
registered for a particular top-level domain (the policies differ with
|
12
12
|
each registry)...". Public Suffix List is also a small Ruby library
|
13
13
|
designed to make the Public Suffix List (http://publicsuffix.org/)
|
14
|
-
easier to use.
|
14
|
+
easier to use. Public Suffix List will transparently download the
|
15
|
+
latest list of top-level domains, parse the list, and optionally cache
|
16
|
+
the parsed data.
|
17
|
+
|
18
|
+
The public API is as simple as I could make it. Instantiating the
|
19
|
+
PublicSuffixList class downloads, parses, and caches the data. There
|
20
|
+
are three instance methods:
|
21
|
+
|
22
|
+
[*tld*(domain)] return the top-level domain name
|
23
|
+
[*cdn*(domain)] return the canonical domain name
|
24
|
+
[*split*(domain)] split the domain name into parts
|
15
25
|
|
16
26
|
== Features
|
17
27
|
|
@@ -23,24 +33,32 @@ easier to use.
|
|
23
33
|
|
24
34
|
require "public_suffix_list"
|
25
35
|
|
26
|
-
#
|
36
|
+
# Downloads and parses the latest data file and returns "com".
|
27
37
|
PublicSuffixList.new.tld("foobar.com")
|
28
38
|
|
29
|
-
#
|
39
|
+
# Downloads and parses the latest data file and returns "foobar.com".
|
30
40
|
PublicSuffixList.new.cdn("foobar.com")
|
31
41
|
|
32
|
-
#
|
42
|
+
# Downloads and parses the latest data file, caches it in /tmp,
|
43
|
+
# and returns ["abc", "xyz", "co.uk"].
|
33
44
|
PublicSuffixList.new(:cache_dir => "/tmp").split("abc.xyz.co.uk")
|
34
45
|
|
35
|
-
#
|
36
|
-
|
46
|
+
# Loads the cached data in /tmp if it is less than 100 seconds old,
|
47
|
+
# downloads, parses, and caches it if it is older, and returns
|
48
|
+
# ["test", "nhs", "uk"].
|
49
|
+
PublicSuffixList.new(:cache_dir => "/tmp", :cache_expiry_period => 100).split("test.nhs.uk")
|
37
50
|
|
38
|
-
#
|
51
|
+
# You don't have to instantiate PublicSuffixList every time you
|
52
|
+
# use it, of course...
|
39
53
|
p = PublicSuffixList.new
|
40
54
|
p.split("fee.fi.fo.com") # => ["fee.fi", "fo", "com"]
|
41
55
|
p.cdn("fee.fi.fo.com") # => "fo.com", "cdn" is "canonical domain name"
|
42
56
|
p.tld("fee.fi.fo.com") # => "com", "tld" is "top-level domain"
|
43
57
|
|
58
|
+
# You can even use other data files, both local and remote
|
59
|
+
# (as long as they conform to the Public Suffix List file format).
|
60
|
+
PublicSuffixList.new(:url => "spec/test.dat")
|
61
|
+
|
44
62
|
== Requirements
|
45
63
|
|
46
64
|
None that I am aware of.
|
data/lib/public_suffix_list.rb
CHANGED
@@ -6,7 +6,7 @@ require "public_suffix_list/parser.rb"
|
|
6
6
|
|
7
7
|
class PublicSuffixList
|
8
8
|
|
9
|
-
VERSION = "0.0
|
9
|
+
VERSION = "0.1.0"
|
10
10
|
|
11
11
|
def self.config
|
12
12
|
@@config ||= Config.new
|
@@ -20,12 +20,16 @@ class PublicSuffixList
|
|
20
20
|
|
21
21
|
attr_accessor :cache_dir
|
22
22
|
attr_accessor :cache_expiry_period
|
23
|
-
attr_accessor :
|
23
|
+
attr_accessor :url
|
24
|
+
|
25
|
+
# effective_tld_names_url is deprecated
|
26
|
+
alias_method :effective_tld_names_url, :url
|
27
|
+
alias_method :effective_tld_names_url=, :url=
|
24
28
|
|
25
29
|
def initialize
|
26
30
|
@cache_dir = nil
|
27
31
|
@cache_expiry_period = 30 * 24 * 60 * 60
|
28
|
-
@
|
32
|
+
@url = "http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/src/effective_tld_names.dat?raw=1"
|
29
33
|
end
|
30
34
|
|
31
35
|
end
|
@@ -72,7 +76,7 @@ class PublicSuffixList
|
|
72
76
|
private
|
73
77
|
|
74
78
|
def fetch
|
75
|
-
@rules = Parser.parse(open(@config.
|
79
|
+
@rules = Parser.parse(open(@config.url))
|
76
80
|
end
|
77
81
|
|
78
82
|
def cache
|
@@ -80,7 +84,7 @@ class PublicSuffixList
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def uncache
|
83
|
-
rules = @cache_file[:rules] unless @cache_file.expired?
|
87
|
+
@rules = @cache_file[:rules] unless @cache_file.expired?
|
84
88
|
end
|
85
89
|
|
86
90
|
def match(domain, rules)
|
@@ -11,7 +11,7 @@ class PublicSuffixList
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def file
|
14
|
-
File.join(@config.cache_dir, URI.parse(@config.
|
14
|
+
File.join(@config.cache_dir, URI.parse(@config.url).path.split("/").last + ".cache") if cache?
|
15
15
|
end
|
16
16
|
|
17
17
|
def exist?
|
@@ -2,30 +2,40 @@ require 'lib/public_suffix_list'
|
|
2
2
|
|
3
3
|
describe PublicSuffixList do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
it "should accept both effective_tld_names_url and url" do
|
6
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
|
7
|
+
public_suffix_list.config.effective_tld_names_url.should == "spec/test.dat"
|
8
|
+
public_suffix_list.config.url.should == "spec/test.dat"
|
9
|
+
public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
|
10
|
+
public_suffix_list.config.effective_tld_names_url.should == "spec/test.dat"
|
11
|
+
public_suffix_list.config.url.should == "spec/test.dat"
|
8
12
|
end
|
9
13
|
|
10
14
|
it "should calculate tld and cdn correctly" do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
|
16
|
+
public_suffix_list.cache_file.should be nil
|
17
|
+
public_suffix_list.cdn("foo.bar.com").should == "bar.com"
|
18
|
+
public_suffix_list.tld("foo.bar.com").should == "com"
|
19
|
+
public_suffix_list.cdn("foobar.com").should == "foobar.com"
|
20
|
+
public_suffix_list.tld("foobar.com").should == "com"
|
15
21
|
end
|
16
22
|
|
17
23
|
it "should not assume the root name is a top level domain" do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
|
25
|
+
public_suffix_list.cache_file.should be nil
|
26
|
+
public_suffix_list.tld("com").should == "com"
|
27
|
+
public_suffix_list.tld("bar.foo").should == "bar.foo"
|
28
|
+
public_suffix_list.tld("baz.foo").should == "baz.foo"
|
29
|
+
public_suffix_list.tld("qux.foo").should == ""
|
30
|
+
public_suffix_list.tld("foo").should == ""
|
23
31
|
end
|
24
32
|
|
25
33
|
it "should handle edge cases correctly" do
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
|
35
|
+
public_suffix_list.cache_file.should be nil
|
36
|
+
public_suffix_list.split("").should == ["", "", ""]
|
37
|
+
public_suffix_list.cdn("").should == ""
|
38
|
+
public_suffix_list.tld("").should == ""
|
29
39
|
end
|
30
40
|
|
31
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public-suffix-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Sundsted
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-15 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|