• Stars
    star
    2
  • Language
    Crystal
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small Crystal library designed to make the Public Suffix List (https://publicsuffix.org/) easier to use.

public_suffix

GitHub Release Build Status Documentation

The Public Suffix List is "a cross-vendor initiative to provide an accurate list of domain name suffixes". Such a list is necessary because "there was and remains no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain...".

public_suffix is a small Crystal library designed to make the Public Suffix List easier to use. The library will transparently download the latest list of rules, parse the rules, and optionally cache them. Source URL, cache directory, and cache expiry are all configurable.

The public API is as simple as I could make it. Instantiating the PublicSuffix class creates a new instance with reasonable defaults (downloads and caches the official list of rules for 30 days).

There are three instance methods:

  • PublicSuffix#tld returns the top-level domain name
  • PublicSuffix#cdn returns the canonical domain name
  • PublicSuffix#splitsplits the domain name into parts

Features

  • Transparent download of the official domain rules file
  • Optional caching of domain rules data, with refetch upon expiry
  • Tiny API

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      public_suffix:
        github: toddsundsted/public_suffix
    
  2. Run shards install

Synopsis

require "public_suffix"

# Downloads and parses the latest data file and returns
# the top-level domain name
PublicSuffix.new.tld("foobar.com") # => "com"

# Downloads and parses the latest data file and returns
# the canonical domain name
PublicSuffix.new.cdn("foobar.com") # => "foobar.com"

# Downloads and parses the latest data file, caches it in /tmp,
# and splits the domain name into parts
PublicSuffix.new(cache_dir: "/tmp").split("abc.xyz.co.uk") # => ["abc", "xyz", "co.uk"].

# Downloads and caches data in /tmp if it is less than
# 100 seconds old, parses it, and splits the domain name
# into parts
PublicSuffix.new(cache_dir: "/tmp", cache_expiry_period: 100).split("test.parliament.uk") # => ["test", "parliament", "uk"]

# You don't have to instantiate PublicSuffix every time you use it
p = PublicSuffix.new
p.split("fee.fi.fo.com") # => ["fee.fi", "fo", "com"]
p.cdn("fee.fi.fo.com")   # => "fo.com", "cdn" means "canonical domain name"
p.tld("fee.fi.fo.com")   # => "com", "tld" means "top-level domain"

# You can even use other data files, both local and remote
# (as long as they conform to the Public Suffix List file format)
PublicSuffix.new(url: "file://./spec/test.dat")

Contributing

  1. Fork it (https://github.com/toddsundsted/public_suffix/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

More Repositories

1

ktistec

Single user ActivityPub (https://www.w3.org/TR/activitypub/) server.
Crystal
330
star
2

stunt

LambdaMOO with multiple inheritance, anonymous objects, HTTP, JSON <-> MOO translation, better crypto, a map datatype and a RESTful interface.
C++
72
star
3

ishi

Graph plotting package with a small API and sensible defaults powered by gnuplot.
Crystal
47
star
4

mxnet.cr

MXNet (AI/ML) bindings for the Crystal language.
Crystal
22
star
5

improvise

Starter kit for Stunt.
JavaScript
18
star
6

rmoo

A major mode for interacting with MOOs.
Emacs Lisp
12
star
7

Public-Suffix-List

Ruby code for working with the Public Suffix List
Ruby
11
star
8

deep-learning

Exercises in deep learning -- Crystal language edition
Crystal
10
star
9

web_finger

A WebFinger (https://tools.ietf.org/html/rfc7033) client for Crystal.
Crystal
9
star
10

jquery.tweetcapture

Capture Twitter search tweets in real time and stick them in a web-page.
JavaScript
7
star
11

iterm2

Display images within the terminal using the ITerm2 Inline Images Protocol.
Crystal
6
star
12

slang

Slim-inspired templating language for Crystal
Crystal
5
star
13

host_meta

A Web Host Metadata (https://tools.ietf.org/html/rfc6415) client for Crystal.
Crystal
3
star
14

shiken

Basic Rails and Git skills test for candidates.
Ruby
3
star
15

javascript-as3-socket

Git clone of http://code.google.com/p/javascript-as3-socket/ with improvements.
JavaScript
3
star
16

heroku-buildpack-stunt

Heroku buildpack for Stunt.
Shell
2
star
17

openssl_ext

Crystal bindings for OpenSSL RSA
Crystal
2
star
18

ki

A simple mobile agent framework, described in a series of articles for JavaWorld c. 1998.
Java
2
star
19

pwnserver

It's my data and I wants it back!
2
star
20

compare-cores

Compares two LambdaMOO databases (with extensions).
Perl
2
star
21

moocode-mode

A fork of Rob Myers' Emacs major mode providing syntax highlighting and indentation for MOO code.
Emacs Lisp
2
star
22

rubyweb

Rubyweb - a literate programming system for Ruby
Ruby
1
star
23

zzz

Hypermedia controls.
1
star
24

Scala-for-Scripting

Scala
1
star
25

libxml_ext

Extensions to XML in Crystal.
Crystal
1
star
26

iui

Custom version of the IUI iPhone webapp library.
JavaScript
1
star