/lib/DDG/Spice/Whois.pm
Perl | 43 lines | 28 code | 13 blank | 2 comment | 5 complexity | 25a9a0c801c8c46a122c0793af131c77 MD5 | raw file
Possible License(s): Apache-2.0
- package DDG::Spice::Whois;
- # ABSTRACT: Returns an internet domain's availability and whois information.
- use strict;
- use DDG::Spice;
- use Domain::PublicSuffix;
- use Text::Trim;
- triggers any => "whois", "lookup", "domain", "is domain", "available", "is available", "register", "owner", "owner of", "who owns", "buy", "how to buy";
- # API call details for Whois API (http://www.whoisxmlapi.com/)
- spice to => 'https://www.whoisxmlapi.com/whoisserver/WhoisService?domainName=$1&outputFormat=JSON&callback={{callback}}&apiKey={{ENV{DDG_SPICE_WHOIS_APIKEY}}}';
- spice content_type_javascript => 1;
- handle remainder_lc => sub {
- my $domain;
- my $publicSuffix = Domain::PublicSuffix->new();
- s/https?:\/\/|\?//g; # strip keywords and http(s) and question mark
- s/\:\d{1,5}//g; # strip ports, such as :3000 - highest port number 65535
- if ( /\s/ ) {
- s/\bis\b|\bfor\b//g # if space, strip additional words
- }
- if(m/\//) {
- s|[^/]+$||; # if we have /about.html or other remove it
- s/\/$//g; # remove the left over slash
- }
- trim($_); # trim any leading and trailing spaces
- if ( /\s/ ) { return; } # do not trigger if the query still contains spaces
- return if !$_; # do not trigger this spice if the query is blank
- $domain = $publicSuffix->get_root_domain($_); # get the root domain assuming we have that left in our query
- return if !$domain;
- return $domain;
- };
- 1;