PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Whois.pm

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