root_domain 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +1 -1
- data/lib/root_domain.rb +2 -9
- data/lib/root_domain/version.rb +1 -1
- data/root_domain.gemspec +2 -1
- metadata +18 -8
- data/bin/sync-data +0 -105
- data/data/cctld.json +0 -237
- data/data/slds.json +0 -6044
- data/data/tlds.json +0 -1510
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289644bed4f6c5a3a393c27c3220acc86c823d6cc7592aa4b588b7aeec69bc83
|
4
|
+
data.tar.gz: b2a5e7c4cf351f611107289fa48bfc5b87a2c98e93e731a74454791bf2d93ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86825db89adb00560847ccf025483e1b759ee26bafed4261a90b0ba06b55ef7f8772365507b72f7b0950abda55bd1a2572a21c77d3d4a4703efe260d6ca34f58
|
7
|
+
data.tar.gz: 21002dbe083f78df85489277b643c385bc1fc8e8e3f7afb7fc9868e4bacd6bc8746ede22910306a9721652018586e2f98dd1caead89f13c2d569fe795e3d09e6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# root_domain
|
2
2
|
|
3
3
|
If you ever worked with domain validation, you probably needed to extract the
|
4
|
-
root domain. This means that, given some hostname, remove subdomains from the original input, taking into account not only official Internet [TLDs](https://en.wikipedia.org/wiki/Top-level_domain), but
|
4
|
+
root domain. This means that, given some hostname, you must remove subdomains from the original input, taking into account not only official Internet [TLDs](https://en.wikipedia.org/wiki/Top-level_domain), but [SLDs](https://en.wikipedia.org/wiki/Second-level_domain) too.
|
5
5
|
|
6
6
|
With root_domain, you can easily extract the root domain, expanding any input from punycode into ASCII entries.
|
7
7
|
|
data/lib/root_domain.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "email_data"
|
3
4
|
require "simpleidn"
|
4
5
|
require "json"
|
5
6
|
|
@@ -9,7 +10,7 @@ module RootDomain
|
|
9
10
|
def self.call(input)
|
10
11
|
input = SimpleIDN.to_ascii(input)
|
11
12
|
|
12
|
-
find(slds, input) || find(tlds, input)
|
13
|
+
find(EmailData.slds, input) || find(EmailData.tlds, input)
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.find(source, input)
|
@@ -23,12 +24,4 @@ module RootDomain
|
|
23
24
|
|
24
25
|
nil
|
25
26
|
end
|
26
|
-
|
27
|
-
def self.slds
|
28
|
-
@slds ||= JSON.parse(File.read("#{__dir__}/../data/slds.json"))
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.tlds
|
32
|
-
@tlds ||= JSON.parse(File.read("#{__dir__}/../data/tlds.json"))
|
33
|
-
end
|
34
27
|
end
|
data/lib/root_domain/version.rb
CHANGED
data/root_domain.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = spec.summary
|
14
14
|
spec.homepage = "https://github.com/fnando/root_domain"
|
15
15
|
spec.license = "MIT"
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
+
spec.add_dependency "email_data"
|
31
32
|
spec.add_dependency "simpleidn"
|
32
33
|
|
33
34
|
spec.add_development_dependency "aitch"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: root_domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: email_data
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: simpleidn
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,10 +156,6 @@ files:
|
|
142
156
|
- Rakefile
|
143
157
|
- bin/console
|
144
158
|
- bin/setup
|
145
|
-
- bin/sync-data
|
146
|
-
- data/cctld.json
|
147
|
-
- data/slds.json
|
148
|
-
- data/tlds.json
|
149
159
|
- lib/root_domain.rb
|
150
160
|
- lib/root_domain/version.rb
|
151
161
|
- root_domain.gemspec
|
@@ -164,14 +174,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
174
|
requirements:
|
165
175
|
- - ">="
|
166
176
|
- !ruby/object:Gem::Version
|
167
|
-
version: 2.
|
177
|
+
version: 2.7.0
|
168
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
179
|
requirements:
|
170
180
|
- - ">="
|
171
181
|
- !ruby/object:Gem::Version
|
172
182
|
version: '0'
|
173
183
|
requirements: []
|
174
|
-
rubygems_version: 3.1.
|
184
|
+
rubygems_version: 3.1.4
|
175
185
|
signing_key:
|
176
186
|
specification_version: 4
|
177
187
|
summary: Extract root domain from hosts (e.g. www.example will be extracted as example.com
|
data/bin/sync-data
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "bundler/inline"
|
5
|
-
|
6
|
-
gemfile do
|
7
|
-
gem "aitch"
|
8
|
-
gem "simpleidn"
|
9
|
-
end
|
10
|
-
|
11
|
-
class ImportDomainSuffixes
|
12
|
-
def call
|
13
|
-
list = []
|
14
|
-
list += build(country_tlds, cctld: true, tld: true)
|
15
|
-
list += build(tlds, tld: true)
|
16
|
-
list += build(slds)
|
17
|
-
|
18
|
-
save_file(:cctld, country_tlds.sort)
|
19
|
-
save_file(:tlds, tlds.sort)
|
20
|
-
save_file(:slds, slds.sort)
|
21
|
-
end
|
22
|
-
|
23
|
-
def save_file(file, data)
|
24
|
-
File.open("#{__dir__}/../data/#{file}.json", "w") do |io|
|
25
|
-
io << JSON.pretty_generate(data)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def build(suffixes, attrs = {})
|
30
|
-
suffixes = suffixes
|
31
|
-
.compact
|
32
|
-
.map(&:strip)
|
33
|
-
.reject(&:empty?)
|
34
|
-
.map(&:downcase)
|
35
|
-
.uniq
|
36
|
-
|
37
|
-
suffixes.map do |suffix|
|
38
|
-
name = SimpleIDN.to_ascii(suffix)
|
39
|
-
attrs.merge(name: name, levels: name.split(".").size)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def country_tlds
|
44
|
-
@country_tlds ||= fetch_country_tlds
|
45
|
-
end
|
46
|
-
|
47
|
-
def tlds
|
48
|
-
@tlds ||= fetch_tlds
|
49
|
-
end
|
50
|
-
|
51
|
-
def slds
|
52
|
-
@slds ||= (fetch_slds + fetch_public_suffix)
|
53
|
-
.compact
|
54
|
-
.map {|sld| SimpleIDN.to_ascii(sld).gsub("!", "") }
|
55
|
-
.uniq
|
56
|
-
end
|
57
|
-
|
58
|
-
def fetch_tlds
|
59
|
-
url = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
|
60
|
-
response = Aitch.get(url)
|
61
|
-
tlds = response.body.lines
|
62
|
-
tlds.shift # remove update notice
|
63
|
-
tlds
|
64
|
-
.map(&:chomp)
|
65
|
-
.map(&:downcase)
|
66
|
-
.uniq
|
67
|
-
end
|
68
|
-
|
69
|
-
def fetch_country_tlds
|
70
|
-
url = "https://github.com/samayo/country-json/raw/master/src/country-by-domain-tld.json"
|
71
|
-
response = Aitch.get(url)
|
72
|
-
country_tlds = JSON.parse(response.body, symbolize_names: true)
|
73
|
-
|
74
|
-
country_tlds
|
75
|
-
.map {|info| info[:tld][1..-1] if info[:tld] }
|
76
|
-
.compact
|
77
|
-
end
|
78
|
-
|
79
|
-
def fetch_slds
|
80
|
-
url = "https://www.quackit.com/domain-names/country_domain_extensions.cfm"
|
81
|
-
response = Aitch.get(url)
|
82
|
-
response.data.css("b")
|
83
|
-
.map {|node| node.text.squeeze.downcase }
|
84
|
-
.select {|sld| sld.start_with?(".") }
|
85
|
-
.map {|sld| sld[/^\.([-a-z0-9.]+)/, 1] }
|
86
|
-
.reject(&:nil?)
|
87
|
-
.reject {|sld| sld.split(".").size < 2 }
|
88
|
-
end
|
89
|
-
|
90
|
-
def fetch_public_suffix
|
91
|
-
url = "https://publicsuffix.org/list/public_suffix_list.dat"
|
92
|
-
response = Aitch.get(url)
|
93
|
-
content, _ = response.body.split("END ICANN DOMAINS")
|
94
|
-
|
95
|
-
content
|
96
|
-
.lines
|
97
|
-
.map {|line| line.gsub(/^\*\./, "") }
|
98
|
-
.map(&:strip)
|
99
|
-
.reject(&:empty?)
|
100
|
-
.reject {|line| line.start_with?("/") }
|
101
|
-
.select {|line| line.include?(".") }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
ImportDomainSuffixes.new.call
|
data/data/cctld.json
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
[
|
2
|
-
"ad",
|
3
|
-
"ae",
|
4
|
-
"af",
|
5
|
-
"ag",
|
6
|
-
"ai",
|
7
|
-
"al",
|
8
|
-
"am",
|
9
|
-
"an",
|
10
|
-
"ao",
|
11
|
-
"aq",
|
12
|
-
"ar",
|
13
|
-
"as",
|
14
|
-
"at",
|
15
|
-
"au",
|
16
|
-
"aw",
|
17
|
-
"az",
|
18
|
-
"ba",
|
19
|
-
"bb",
|
20
|
-
"bd",
|
21
|
-
"be",
|
22
|
-
"bf",
|
23
|
-
"bg",
|
24
|
-
"bh",
|
25
|
-
"bi",
|
26
|
-
"bj",
|
27
|
-
"bm",
|
28
|
-
"bn",
|
29
|
-
"bo",
|
30
|
-
"br",
|
31
|
-
"bs",
|
32
|
-
"bt",
|
33
|
-
"bv",
|
34
|
-
"bw",
|
35
|
-
"by",
|
36
|
-
"bz",
|
37
|
-
"ca",
|
38
|
-
"cc",
|
39
|
-
"cd",
|
40
|
-
"cf",
|
41
|
-
"cg",
|
42
|
-
"ch",
|
43
|
-
"ci",
|
44
|
-
"ck",
|
45
|
-
"cl",
|
46
|
-
"cm",
|
47
|
-
"cn",
|
48
|
-
"co",
|
49
|
-
"cr",
|
50
|
-
"cu",
|
51
|
-
"cv",
|
52
|
-
"cx",
|
53
|
-
"cy",
|
54
|
-
"cz",
|
55
|
-
"de",
|
56
|
-
"dj",
|
57
|
-
"dk",
|
58
|
-
"dm",
|
59
|
-
"do",
|
60
|
-
"dz",
|
61
|
-
"ec",
|
62
|
-
"ee",
|
63
|
-
"eg",
|
64
|
-
"eh",
|
65
|
-
"er",
|
66
|
-
"es",
|
67
|
-
"et",
|
68
|
-
"fi",
|
69
|
-
"fj",
|
70
|
-
"fk",
|
71
|
-
"fr",
|
72
|
-
"ga",
|
73
|
-
"gb",
|
74
|
-
"gd",
|
75
|
-
"ge",
|
76
|
-
"gf",
|
77
|
-
"gh",
|
78
|
-
"gi",
|
79
|
-
"gl",
|
80
|
-
"gm",
|
81
|
-
"gn",
|
82
|
-
"gp",
|
83
|
-
"gq",
|
84
|
-
"gr",
|
85
|
-
"gs",
|
86
|
-
"gt",
|
87
|
-
"gu",
|
88
|
-
"gw",
|
89
|
-
"gy",
|
90
|
-
"hk",
|
91
|
-
"hm",
|
92
|
-
"hn",
|
93
|
-
"hr",
|
94
|
-
"ht",
|
95
|
-
"hu",
|
96
|
-
"id",
|
97
|
-
"ie",
|
98
|
-
"il",
|
99
|
-
"in",
|
100
|
-
"io",
|
101
|
-
"iq",
|
102
|
-
"ir",
|
103
|
-
"is",
|
104
|
-
"it",
|
105
|
-
"jm",
|
106
|
-
"jo",
|
107
|
-
"jp",
|
108
|
-
"ke",
|
109
|
-
"kg",
|
110
|
-
"kh",
|
111
|
-
"ki",
|
112
|
-
"km",
|
113
|
-
"kn",
|
114
|
-
"kp",
|
115
|
-
"kr",
|
116
|
-
"kw",
|
117
|
-
"ky",
|
118
|
-
"kz",
|
119
|
-
"la",
|
120
|
-
"lb",
|
121
|
-
"lc",
|
122
|
-
"li",
|
123
|
-
"lk",
|
124
|
-
"lr",
|
125
|
-
"ls",
|
126
|
-
"lt",
|
127
|
-
"lu",
|
128
|
-
"lv",
|
129
|
-
"ly",
|
130
|
-
"ma",
|
131
|
-
"mc",
|
132
|
-
"md",
|
133
|
-
"mg",
|
134
|
-
"mh",
|
135
|
-
"mk",
|
136
|
-
"ml",
|
137
|
-
"mm",
|
138
|
-
"mn",
|
139
|
-
"mo",
|
140
|
-
"mp",
|
141
|
-
"mq",
|
142
|
-
"mr",
|
143
|
-
"ms",
|
144
|
-
"mt",
|
145
|
-
"mu",
|
146
|
-
"mv",
|
147
|
-
"mw",
|
148
|
-
"mx",
|
149
|
-
"my",
|
150
|
-
"mz",
|
151
|
-
"na",
|
152
|
-
"nc",
|
153
|
-
"ne",
|
154
|
-
"nf",
|
155
|
-
"ng",
|
156
|
-
"ni",
|
157
|
-
"nl",
|
158
|
-
"no",
|
159
|
-
"np",
|
160
|
-
"nr",
|
161
|
-
"nu",
|
162
|
-
"nz",
|
163
|
-
"om",
|
164
|
-
"pa",
|
165
|
-
"pe",
|
166
|
-
"pf",
|
167
|
-
"pg",
|
168
|
-
"ph",
|
169
|
-
"pk",
|
170
|
-
"pl",
|
171
|
-
"pm",
|
172
|
-
"pn",
|
173
|
-
"pr",
|
174
|
-
"ps",
|
175
|
-
"pt",
|
176
|
-
"pw",
|
177
|
-
"py",
|
178
|
-
"qa",
|
179
|
-
"re",
|
180
|
-
"ro",
|
181
|
-
"ru",
|
182
|
-
"rw",
|
183
|
-
"sa",
|
184
|
-
"sb",
|
185
|
-
"sc",
|
186
|
-
"sd",
|
187
|
-
"se",
|
188
|
-
"sg",
|
189
|
-
"sh",
|
190
|
-
"si",
|
191
|
-
"sj",
|
192
|
-
"sk",
|
193
|
-
"sl",
|
194
|
-
"sm",
|
195
|
-
"sn",
|
196
|
-
"so",
|
197
|
-
"sr",
|
198
|
-
"ss",
|
199
|
-
"st",
|
200
|
-
"sv",
|
201
|
-
"sy",
|
202
|
-
"sz",
|
203
|
-
"tc",
|
204
|
-
"td",
|
205
|
-
"tf",
|
206
|
-
"tg",
|
207
|
-
"th",
|
208
|
-
"tj",
|
209
|
-
"tk",
|
210
|
-
"tl",
|
211
|
-
"tm",
|
212
|
-
"tn",
|
213
|
-
"to",
|
214
|
-
"tr",
|
215
|
-
"tt",
|
216
|
-
"tv",
|
217
|
-
"tz",
|
218
|
-
"ua",
|
219
|
-
"ug",
|
220
|
-
"us",
|
221
|
-
"uy",
|
222
|
-
"uz",
|
223
|
-
"va",
|
224
|
-
"vc",
|
225
|
-
"ve",
|
226
|
-
"vg",
|
227
|
-
"vi",
|
228
|
-
"vn",
|
229
|
-
"vu",
|
230
|
-
"wf",
|
231
|
-
"ws",
|
232
|
-
"ye",
|
233
|
-
"yt",
|
234
|
-
"za",
|
235
|
-
"zm",
|
236
|
-
"zw"
|
237
|
-
]
|