root_domain 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/FUNDING.yml +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/sync-data +105 -0
- data/data/cctld.json +237 -0
- data/data/slds.json +6044 -0
- data/data/tlds.json +1510 -0
- data/lib/root_domain.rb +34 -0
- data/lib/root_domain/version.rb +5 -0
- data/root_domain.gemspec +40 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9604392f3bd2b810161f518225a1826f148dd9a139dd6e71577a414c0b89c3ef
|
4
|
+
data.tar.gz: fe373334382a4ff5bc6a3439af994cede81288fac75593ea9c183ffd135819d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bcb1c388c491eea1338434687444cfd18f865af3b9b986aa9add49061115466d8dcc353fef699e54dffde767538d3b4fc982c25157f7942f0ef83cb5c1f6bf8
|
7
|
+
data.tar.gz: 99d5b89c1c8daee5bd218db7896af16fe1c8107a5af398ce098093099198f53044efc0b4778d9235a7123b16f95a780bd473231a8c8d251bb3d022e563d4c0dc
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at me@fnando.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [fnando]
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Nando Vieira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# root_domain
|
2
|
+
|
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. [SLDs](https://en.wikipedia.org/wiki/Second-level_domain) too.
|
5
|
+
|
6
|
+
With root_domain, you can easily extract the root domain, expanding any input from punycode into ASCII entries.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "root_domain"
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install root_domain
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "root_domain"
|
28
|
+
|
29
|
+
RootDomain.call("www.example.com")
|
30
|
+
#=> example.com
|
31
|
+
|
32
|
+
RootDomain.call("www.example.com.br")
|
33
|
+
#=> example.com.br
|
34
|
+
|
35
|
+
RootDomain.call("myapp.apps.🤯.com")
|
36
|
+
#=> xn--oq9h.com
|
37
|
+
```
|
38
|
+
|
39
|
+
## Changelog
|
40
|
+
|
41
|
+
The changelog file is available at [CHANGELOG.md](https://github.com/fnando/root_domain/tree/main/CHANGELOG.md)
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/root_domain. 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/fnando/root_domain/blob/master/CODE_OF_CONDUCT.md).
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
56
|
+
|
57
|
+
## Code of Conduct
|
58
|
+
|
59
|
+
Everyone interacting in the RootDomain project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fnando/root_domain/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "root_domain"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/sync-data
ADDED
@@ -0,0 +1,105 @@
|
|
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
ADDED
@@ -0,0 +1,237 @@
|
|
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
|
+
]
|