Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Parser for .ug domains #35

Closed
wants to merge 5 commits into from

2 participants

@DerGuteMoritz

Hi Simone,

feel free to pull this (very basic) parser for .ug domains from me.

Thanks a lot for your work!

Moritz

@weppos
Owner

Hi Moritz,

I reviewed your parser and it looks very good!
There are a few changes I would ask you to apply before merging the patch into the master branch:

  1. created_on should return a Time instance. Please use
    DateTime.strptime($1, '%d/%m/%Y %H:%M:%S %Z').to_time
    to cast the value and update the test accordingly.

  2. Since this is not a full parser, please change the header from

    #
    # = whois.co.ug parser
    #
    # Parser for the whois.co.ug server.
    #
    

    to

    #
    # = whois.co.ug parser
    #
    # Parser for the whois.co.ug server.
    #
    # NOTE: This parser is just a stub and provides only a few basic methods
    # to check for domain availability and get domain status.
    # Please consider to contribute implementing missing methods.
    # See WhoisNicIt parser for an explanation of all available methods
    # and examples.
    #
    

Thanks for your contribution!

@DerGuteMoritz

Hey Simone,

thanks for the quick response! I used DateTime in this particular case because the time is in the EAT zone. The to_time method only considers UTC time objects. I didn't find a quick way to do the conversoin without pulling in tzinfo or the like. Any suggestions?

I'll incorporate the note in a minute!

Moritz

@weppos
Owner

Unfortunately this is a known issue.

Currently, parsers are not timezone-aware. In fact, most registries don't include timezone information and Ruby 1.8 is not very good at converting DateTime to Time and viceversa.

I'm still trying to understand whether:

  • add tzinfo (optional or required) dependency
  • drop support for Ruby < 1.9

This is something we certainly need to address, but in the meantime I prefer to consistently return a Time instance as long as we don't find a working solution for all the parsers with the price of loosing TimeZone information.

Of course, I'm open to suggestions.

@DerGuteMoritz

I don't really know how to handle this elegantly as well. Another option would be to pull in ActiveSupport and rely on its abstraction over the various solutions. Then again, I'm not really fond of how timezones are handled by it. This is really a can of worms! :-)

@weppos
Owner

I will look into that ASAP. In the meantime, I'm going to merge your changes.
Thank you very much, Moritz.

@weppos
Owner

Parser for .ug domains (closed by eef4e6c138700eb966f80b22d2d251c71355e5ac)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 8, 2010
  1. add very basic parser for .ug domains

    Moritz Heidkamp authored
  2. use whois.co.ug for .ug domains

    Moritz Heidkamp authored
  3. include note that the .ug parser is not complete (suggested by Simone…

    Moritz Heidkamp authored
    … Carletti)
  4. always return Time objects even if it means losing time zone informat…

    Moritz Heidkamp authored
    …ion (for now)
This page is out of date. Refresh to see the latest.
View
2  data/c/tld_serv_list
@@ -291,7 +291,7 @@
.tw whois.twnic.net.tw
.tz whois.tznic.or.tz
.ua whois.net.ua
-.ug www.registry.co.ug # this is a whois server too
+.ug whois.co.ug
.ac.uk whois.ja.net
.bl.uk NONE
.british-library.uk NONE
View
76 lib/whois/answer/parser/whois.co.ug.rb
@@ -0,0 +1,76 @@
+#
+# = Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+#
+# Category:: Net
+# Package:: Whois
+# Author:: Moritz Heidkamp <moritz.heidkamp@bevuta.com>
+# License:: MIT License
+#
+#--
+#
+#++
+
+
+require 'whois/answer/parser/base'
+
+
+module Whois
+ class Answer
+ class Parser
+
+ #
+ # = whois.co.ug parser
+ #
+ # Parser for the whois.co.ug server.
+ #
+ # NOTE: This parser is just a stub and provides only a few basic methods
+ # to check for domain availability and get domain status.
+ # Please consider to contribute implementing missing methods.
+ # See WhoisNicIt parser for an explanation of all available methods
+ # and examples.
+ #
+ class WhoisCoUg < Base
+
+ property_supported :status do
+ @status ||= content_for_scanner[/^Status:\s+(.+)$/, 1]
+ end
+
+ property_supported :available? do
+ @available ||= !!(content_for_scanner =~ /No entries found for the selected source/)
+ end
+
+ property_supported :registered? do
+ !available?
+ end
+
+ property_supported :created_on do
+ @created_on ||= if content_for_scanner =~ /Registered:\s+(.+)$/
+ Time.parse($1)
+ end
+ end
+
+ property_supported :updated_on do
+ @updated_on ||= if content_for_scanner =~ /Updated:\s+(.+)$/
+ DateTime.strptime($1, '%d/%m/%Y %H:%M:%S').to_time
+ end
+ end
+
+ property_supported :expires_on do
+ @expires_on ||= if content_for_scanner =~ /Expiry:\s(.+)$/
+ Time.parse($1)
+ end
+ end
+
+
+ property_supported :nameservers do
+ @nameservers ||= content_for_scanner.scan(/Nameserver:\s+(.+)$/).flatten.map(&:downcase)
+ end
+
+ end
+
+ end
+ end
+end
View
2  lib/whois/definitions/tlds.rb
@@ -279,7 +279,7 @@
Whois::Server.define :tld, ".tz", "whois.tznic.or.tz"
Whois::Server.define :tld, ".in.ua", "whois.in.ua"
Whois::Server.define :tld, ".ua", "whois.net.ua"
-Whois::Server.define :tld, ".ug", "www.registry.co.ug"
+Whois::Server.define :tld, ".ug", "whois.co.ug"
Whois::Server.define :tld, ".ac.uk", "whois.ja.net"
Whois::Server.define :tld, ".bl.uk", nil, {:adapter=>Whois::Server::Adapters::None}
Whois::Server.define :tld, ".british-library.uk", nil, {:adapter=>Whois::Server::Adapters::None}
View
7 test/testcases/responses/whois.co.ug/available.txt
@@ -0,0 +1,7 @@
+
+**********************************************************
+* The UG ccTLD Registry Database *
+**********************************************************
+
+% No entries found for the selected source(s).
+
View
35 test/testcases/responses/whois.co.ug/registered.txt
@@ -0,0 +1,35 @@
+
+**********************************************************
+* The UG ccTLD Registry Database *
+**********************************************************
+
+Domain: whois.co.ug
+Description: UG CCTLD Database (IT solutions, Domain Names, helpdesk and call center)
+Registered: 2nd April, 2001
+Expiry: 7th April, 2018
+Status: ACTIVE
+Admin Contact: Charles Musisi
+Tech Contact: Mpeirwe Johnson
+Nameserver: ns1.cfi.co.ug
+Nameserver: ns2.cfi.co.ug
+Nameserver: ns3.cfi.co.ug
+MNT-BY: MAINT-UG
+Source: UG
+Updated: 10/11/2009 14:06:58 EAT
+
+Admin Contact: Charles Musisi
+NIC: CM260
+Address: Computer Frontiers International, Plot 6B Windsor Loop, P.O. Box 12
+City: Kampala
+Country: Uganda
+Phone: +256 31 230 1800
+Updated: 13/02/2008 09:35:15 EAT hostmaster@cfi.co.ug
+
+Tech Contact: Mpeirwe Johnson
+NIC: MJ5-UG
+Address: Plot 6B, Windor Loop Kitante
+City: Kampala
+Country: Uganda
+Phone: +256782694615
+Updated: 11/12/2008 11:55:01 EAT hostmaster@cfi.co.ug
+
View
83 test/whois/answer/parser/whois.co.ug_test.rb
@@ -0,0 +1,83 @@
+require 'test_helper'
+require 'whois/answer/parser/whois.co.ug'
+
+class AnswerParserWhoisCoUgTest < Whois::Answer::Parser::TestCase
+
+ def setup
+ @klass = Whois::Answer::Parser::WhoisCoUg
+ @host = "whois.co.ug"
+ end
+
+
+ def test_status
+ parser = @klass.new(load_part('/registered.txt'))
+ expected = "ACTIVE"
+ assert_equal expected, parser.status
+ assert_equal expected, parser.instance_eval { @status }
+
+ parser = @klass.new(load_part('/available.txt'))
+ expected = nil
+ assert_equal expected, parser.status
+ assert_equal expected, parser.instance_eval { @status }
+ end
+
+ def test_available?
+ assert !@klass.new(load_part('/registered.txt')).available?
+ assert @klass.new(load_part('/available.txt')).available?
+ end
+
+ def test_registered?
+ assert @klass.new(load_part('/registered.txt')).registered?
+ assert !@klass.new(load_part('/available.txt')).registered?
+ end
+
+ def test_created_on
+ parser = @klass.new(load_part('/registered.txt'))
+
+ expected = Time.mktime(2001, 4, 2, 0, 0, 0)
+ assert_equal expected, parser.created_on
+ assert_equal expected, parser.instance_eval { @created_on }
+
+ parser = @klass.new(load_part('/available.txt'))
+ expected = nil
+ assert_equal expected, parser.created_on
+ assert_equal expected, parser.instance_eval { @created_on }
+ end
+
+ def test_updated_on
+ parser = @klass.new(load_part('/registered.txt'))
+ expected = Time.gm(2009, 11, 10, 14, 6, 58)
+ assert_equal expected, parser.updated_on
+ assert_equal expected, parser.instance_eval { @updated_on }
+
+ parser = @klass.new(load_part('/available.txt'))
+ expected = nil
+ assert_equal expected, parser.updated_on
+ assert_equal expected, parser.instance_eval { @updated_on }
+ end
+
+ def test_expires_on
+ parser = @klass.new(load_part('/registered.txt'))
+ expected = Time.mktime(2018, 4, 7)
+ assert_equal expected, parser.expires_on
+ assert_equal expected, parser.instance_eval { @expires_on }
+
+ parser = @klass.new(load_part('/available.txt'))
+ expected = nil
+ assert_equal expected, parser.expires_on
+ assert_equal expected, parser.instance_eval { @expires_on }
+ end
+
+ def test_nameservers
+ parser = @klass.new(load_part('/registered.txt'))
+ expected = %w[ns1.cfi.co.ug ns2.cfi.co.ug ns3.cfi.co.ug]
+ assert_equal expected, parser.nameservers
+ assert_equal expected, parser.instance_eval { @nameservers }
+
+ parser = @klass.new(load_part('/available.txt'))
+ expected = []
+ assert_equal expected, parser.nameservers
+ assert_equal expected, parser.instance_eval { @nameservers }
+ end
+
+end
Something went wrong with that request. Please try again.