From da536fcde66ae36466cbed5c8caf669e80570bea Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Wed, 20 Jun 2012 13:38:21 -0400 Subject: [PATCH] Create whois.fastdomain.com parser --- .../record/parser/whois.fastdomain.com.rb | 105 ++++++++++++++ .../status_registered.expected | 91 ++++++++++++ .../status_registered.txt | 74 ++++++++++ .../status_registered_spec.rb | 135 ++++++++++++++++++ 4 files changed, 405 insertions(+) create mode 100644 lib/whois/record/parser/whois.fastdomain.com.rb create mode 100644 spec/fixtures/responses/whois.fastdomain.com/status_registered.expected create mode 100644 spec/fixtures/responses/whois.fastdomain.com/status_registered.txt create mode 100644 spec/whois/record/parser/responses/whois.fastdomain.com/status_registered_spec.rb diff --git a/lib/whois/record/parser/whois.fastdomain.com.rb b/lib/whois/record/parser/whois.fastdomain.com.rb new file mode 100644 index 000000000..652a7424a --- /dev/null +++ b/lib/whois/record/parser/whois.fastdomain.com.rb @@ -0,0 +1,105 @@ +#-- +# Ruby Whois +# +# An intelligent pure Ruby WHOIS client and parser. +# +# Copyright (c) 2009-2012 Simone Carletti +#++ + +require 'whois/record/parser/base' + +module Whois + class Record + class Parser + # Parser for the whois.fastdomain.com server. + # + # @see Whois::Record::Parser::Example + # The Example parser for the list of all available methods. + # + # @author Justin Campbell + # + class WhoisFastdomainCom < Base + property_supported(:status) { :registered } + property_supported(:available?) { false } + property_supported(:registered?) { true } + + property_supported :created_on do + if content_for_scanner =~ /Created on\.+: (.+)$/ + Time.parse($1) + end + end + + property_supported :updated_on do + if content_for_scanner =~ /Last modified on\.+: (.+)$/ + Time.parse($1) + end + end + + property_supported :expires_on do + if content_for_scanner =~ /Expires on\.+: (.+)$/ + Time.parse($1) + end + end + + property_supported :registrar do + Record::Registrar.new( + :name => "FastDomain", + :organization => "FastDomain Inc.", + :url => "http://www.fastdomain.com" + ) + end + + property_supported :registrant_contacts do + build_contact('Registrant Info', Record::Contact::TYPE_REGISTRANT) + end + + property_supported :admin_contacts do + build_contact('Administrative Info', Record::Contact::TYPE_ADMIN) + end + + property_supported :technical_contacts do + build_contact('Technical Info', Record::Contact::TYPE_TECHNICAL) + end + + property_supported :nameservers do + if content_for_scanner =~ /Domain servers in listed order:\n\n((?:.|\n)+)\n\s+=-=-=-=/ + $1.split("\n").map do |line| + Record::Nameserver.new(:name => line.strip.downcase) + end + end + end + + private + + def build_contact(element, type) + content_match = content_for_scanner.match(/#{element}\:\s\((.+)\)\n((\s+.*){7,9})/) + return unless content_match + id, contact = content_match.captures + return unless contact + + contact = contact.lines.map(&:strip).join("\n") + + match = contact.match(/ + (?.+)\n + (?
(.|\n)+)\n + (?.+),\s(?.+) (?.+)\n + (?.+)\n + Phone:\s(?.+)?\n? + Fax\.\.:\s(?.+)?\n? + Email:\s(?.+)? + /x) + + return unless match + + attributes = { :type => type, :id => id } + + match.names.each do |name| + attributes[name.to_sym] = match[name].strip if match[name] + end + + Record::Contact.new attributes + end + end + end + end +end diff --git a/spec/fixtures/responses/whois.fastdomain.com/status_registered.expected b/spec/fixtures/responses/whois.fastdomain.com/status_registered.expected new file mode 100644 index 000000000..eb9779060 --- /dev/null +++ b/spec/fixtures/responses/whois.fastdomain.com/status_registered.expected @@ -0,0 +1,91 @@ +#status + should: %s == :registered + +#available? + should: %s == false + +#registered? + should: %s == true + + +#created_on + should: %s CLASS(time) + should: %s == Time.parse("2002-11-07 05:49:33 GMT") + +#updated_on + should: %s CLASS(time) + should: %s == Time.parse("2012-04-19 17:40:46 GMT") + +#expires_on + should: %s CLASS(time) + should: %s == Time.parse("2017-11-07 05:49:33 GMT") + + +#registrar + should: %s CLASS(registrar) + should: %s.id == nil + should: %s.name == "FastDomain" + should: %s.organization == "FastDomain Inc." + should: %s.url == "http://www.fastdomain.com" + +#registrant_contacts + should: %s CLASS(array) + should: %s SIZE(1) + should: %s[0] CLASS(contact) + should: %s[0].type == Whois::Record::Contact::TYPE_REGISTRANT + should: %s[0].id == "FAST-18447012" + should: %s[0].name == "Domain Privacy Service" + should: %s[0].organization == nil + should: %s[0].address == "1958 South 950 East" + should: %s[0].city == "Provo" + should: %s[0].state == "Utah" + should: %s[0].zip == "-" + should: %s[0].country == "United States" + should: %s[0].phone == "+1.8014948462" + should: %s[0].fax == nil + should: %s[0].email == "whois@fastdomain.com" + +#admin_contacts + should: %s CLASS(array) + should: %s SIZE(1) + should: %s[0] CLASS(contact) + should: %s[0].type == Whois::Record::Contact::TYPE_ADMIN + should: %s[0].id == "FAST-18447012" + should: %s[0].name == "Domain Privacy Service" + should: %s[0].organization == nil + should: %s[0].address == "1958 South 950 East" + should: %s[0].city == "Provo" + should: %s[0].state == "Utah" + should: %s[0].zip == "-" + should: %s[0].country == "United States" + should: %s[0].phone == "+1.8014948462" + should: %s[0].fax == nil + should: %s[0].email == "whois@fastdomain.com" + +#technical_contacts + should: %s CLASS(array) + should: %s SIZE(1) + should: %s[0] CLASS(contact) + should: %s[0].type == Whois::Record::Contact::TYPE_TECHNICAL + should: %s[0].id == "FAST-18447012" + should: %s[0].name == "Domain Privacy Service" + should: %s[0].organization == nil + should: %s[0].address == "1958 South 950 East" + should: %s[0].city == "Provo" + should: %s[0].state == "Utah" + should: %s[0].zip == "-" + should: %s[0].country == "United States" + should: %s[0].phone == "+1.8014948462" + should: %s[0].fax == nil + should: %s[0].email == "whois@fastdomain.com" + + +#nameservers + should: %s CLASS(array) + should: %s SIZE(2) + should: %s[0] CLASS(nameserver) + should: %s[0].name == "ns1.fastdomain.com" + should: %s[0].ipv4 == nil + should: %s[1] CLASS(nameserver) + should: %s[1].name == "ns2.fastdomain.com" + should: %s[1].ipv4 == nil diff --git a/spec/fixtures/responses/whois.fastdomain.com/status_registered.txt b/spec/fixtures/responses/whois.fastdomain.com/status_registered.txt new file mode 100644 index 000000000..30d6fbd5f --- /dev/null +++ b/spec/fixtures/responses/whois.fastdomain.com/status_registered.txt @@ -0,0 +1,74 @@ +The data in the FastDomain Inc. WHOIS database is provided +to you by FastDomain Inc. for information purposes only, +that is, to assist you in obtaining information about or related to +a domain name registration record. FastDomain Inc. makes +this information available "as is," and does not guarantee its +accuracy. By submitting a WHOIS query, you agree that you will use +this data only for lawful purposes and that, under no circumstances +will you use this data to: (1) allow, enable, or otherwise support +the transmission of mass unsolicited, commercial advertising or +solicitations via direct mail, electronic mail, or by telephone; or +(2) enable high volume, automated, electronic processes that apply +to FastDomain Inc. (or its systems). The compilation, +repackaging, dissemination or other use of this data is expressly +prohibited without the prior written consent of +FastDomain Inc.. FastDomain Inc. reserves the +right to modify these terms at any time. By submitting this query, +you agree to abide by these terms. + +=-=-=-= + +Registrar: FastDomain Inc. +Provider Name....: FastDomain Inc. +Provider Whois...: whois.fastdomain.com +Provider Homepage: http://www.fastdomain.com/ + +Domain Name: FASTDOMAIN.COM + + Created on..............: 2002-11-07 05:49:33 GMT + Expires on..............: 2017-11-07 05:49:33 GMT + Last modified on........: 2012-04-19 17:40:46 GMT + +Registrant Info: (FAST-18447012) + + Domain Privacy Service + 1958 South 950 East + Provo, Utah - + United States + Phone: +1.8014948462 + Fax..: + Email: whois@fastdomain.com + Last modified: 2012-06-11 20:32:05 GMT + +Administrative Info: (FAST-18447012) + + Domain Privacy Service + 1958 South 950 East + Provo, Utah - + United States + Phone: +1.8014948462 + Fax..: + Email: whois@fastdomain.com + Last modified: 2012-06-11 20:32:05 GMT + +Technical Info: (FAST-18447012) + + Domain Privacy Service + 1958 South 950 East + Provo, Utah - + United States + Phone: +1.8014948462 + Fax..: + Email: whois@fastdomain.com + Last modified: 2012-06-11 20:32:05 GMT + +Status: Active + +Domain servers in listed order: + + NS1.FASTDOMAIN.COM + NS2.FASTDOMAIN.COM + =-=-=-= + +Now UNLIMITED Storage and UNLIMITED Bandwidth and Host UNLIMITED Domains on one account for ONLY $6.95 per month. +You also get a *FREE* DOMAIN REGISTRATION for one year when you host with http://www.fastdomain.com/ diff --git a/spec/whois/record/parser/responses/whois.fastdomain.com/status_registered_spec.rb b/spec/whois/record/parser/responses/whois.fastdomain.com/status_registered_spec.rb new file mode 100644 index 000000000..1ff0fe39e --- /dev/null +++ b/spec/whois/record/parser/responses/whois.fastdomain.com/status_registered_spec.rb @@ -0,0 +1,135 @@ +# encoding: utf-8 + +# This file is autogenerated. Do not edit it manually. +# If you want change the content of this file, edit +# +# /spec/fixtures/responses/whois.fastdomain.com/status_registered.expected +# +# and regenerate the tests with the following rake task +# +# $ rake spec:generate +# + +require 'spec_helper' +require 'whois/record/parser/whois.fastdomain.com.rb' + +describe Whois::Record::Parser::WhoisFastdomainCom, "status_registered.expected" do + + before(:each) do + file = fixture("responses", "whois.fastdomain.com/status_registered.txt") + part = Whois::Record::Part.new(:body => File.read(file)) + @parser = klass.new(part) + end + + describe "#status" do + it do + @parser.status.should == :registered + end + end + describe "#available?" do + it do + @parser.available?.should == false + end + end + describe "#registered?" do + it do + @parser.registered?.should == true + end + end + describe "#created_on" do + it do + @parser.created_on.should be_a(Time) + @parser.created_on.should == Time.parse("2002-11-07 05:49:33 GMT") + end + end + describe "#updated_on" do + it do + @parser.updated_on.should be_a(Time) + @parser.updated_on.should == Time.parse("2012-04-19 17:40:46 GMT") + end + end + describe "#expires_on" do + it do + @parser.expires_on.should be_a(Time) + @parser.expires_on.should == Time.parse("2017-11-07 05:49:33 GMT") + end + end + describe "#registrar" do + it do + @parser.registrar.should be_a(Whois::Record::Registrar) + @parser.registrar.id.should == nil + @parser.registrar.name.should == "FastDomain" + @parser.registrar.organization.should == "FastDomain Inc." + @parser.registrar.url.should == "http://www.fastdomain.com" + end + end + describe "#registrant_contacts" do + it do + @parser.registrant_contacts.should be_a(Array) + @parser.registrant_contacts.should have(1).items + @parser.registrant_contacts[0].should be_a(Whois::Record::Contact) + @parser.registrant_contacts[0].type.should == Whois::Record::Contact::TYPE_REGISTRANT + @parser.registrant_contacts[0].id.should == "FAST-18447012" + @parser.registrant_contacts[0].name.should == "Domain Privacy Service" + @parser.registrant_contacts[0].organization.should == nil + @parser.registrant_contacts[0].address.should == "1958 South 950 East" + @parser.registrant_contacts[0].city.should == "Provo" + @parser.registrant_contacts[0].state.should == "Utah" + @parser.registrant_contacts[0].zip.should == "-" + @parser.registrant_contacts[0].country.should == "United States" + @parser.registrant_contacts[0].phone.should == "+1.8014948462" + @parser.registrant_contacts[0].fax.should == nil + @parser.registrant_contacts[0].email.should == "whois@fastdomain.com" + end + end + describe "#admin_contacts" do + it do + @parser.admin_contacts.should be_a(Array) + @parser.admin_contacts.should have(1).items + @parser.admin_contacts[0].should be_a(Whois::Record::Contact) + @parser.admin_contacts[0].type.should == Whois::Record::Contact::TYPE_ADMIN + @parser.admin_contacts[0].id.should == "FAST-18447012" + @parser.admin_contacts[0].name.should == "Domain Privacy Service" + @parser.admin_contacts[0].organization.should == nil + @parser.admin_contacts[0].address.should == "1958 South 950 East" + @parser.admin_contacts[0].city.should == "Provo" + @parser.admin_contacts[0].state.should == "Utah" + @parser.admin_contacts[0].zip.should == "-" + @parser.admin_contacts[0].country.should == "United States" + @parser.admin_contacts[0].phone.should == "+1.8014948462" + @parser.admin_contacts[0].fax.should == nil + @parser.admin_contacts[0].email.should == "whois@fastdomain.com" + end + end + describe "#technical_contacts" do + it do + @parser.technical_contacts.should be_a(Array) + @parser.technical_contacts.should have(1).items + @parser.technical_contacts[0].should be_a(Whois::Record::Contact) + @parser.technical_contacts[0].type.should == Whois::Record::Contact::TYPE_TECHNICAL + @parser.technical_contacts[0].id.should == "FAST-18447012" + @parser.technical_contacts[0].name.should == "Domain Privacy Service" + @parser.technical_contacts[0].organization.should == nil + @parser.technical_contacts[0].address.should == "1958 South 950 East" + @parser.technical_contacts[0].city.should == "Provo" + @parser.technical_contacts[0].state.should == "Utah" + @parser.technical_contacts[0].zip.should == "-" + @parser.technical_contacts[0].country.should == "United States" + @parser.technical_contacts[0].phone.should == "+1.8014948462" + @parser.technical_contacts[0].fax.should == nil + @parser.technical_contacts[0].email.should == "whois@fastdomain.com" + end + end + describe "#nameservers" do + it do + @parser.nameservers.should be_a(Array) + @parser.nameservers.should have(2).items + @parser.nameservers[0].should be_a(Whois::Record::Nameserver) + @parser.nameservers[0].name.should == "ns1.fastdomain.com" + @parser.nameservers[0].ipv4.should == nil + @parser.nameservers[1].should be_a(Whois::Record::Nameserver) + @parser.nameservers[1].name.should == "ns2.fastdomain.com" + @parser.nameservers[1].ipv4.should == nil + end + end +end