diff --git a/lib/whois/parsers/whois.registration.ge.rb b/lib/whois/parsers/whois.registration.ge.rb new file mode 100644 index 00000000..43c3a652 --- /dev/null +++ b/lib/whois/parsers/whois.registration.ge.rb @@ -0,0 +1,201 @@ +#-- +# Ruby Whois +# +# An intelligent pure Ruby WHOIS client and parser. +# +# Copyright (c) 2009-2018 Simone Carletti +#++ + + +require_relative 'base' +require 'whois/scanners/whois.registration.ge.rb' + +module Whois + class Parsers + + # Parser for the whois.example.com server. + # + # In case you are not implementing all the methods, + # please add the following statement to the class docblock. + # + # @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. + class WhoisRegistrationGe < Base + + include Scanners::Scannable + + self.scanner = Scanners::WhoisRegistrationGe + + # Gets the registry disclaimer that comes with the record. + # + # Returns a String with the disclaimer if available, + # nil otherwise. + property_supported :disclaimer do + nil + end + + # Gets the domain name as stored by the registry. + # + # Returns a String with the domain name if available, + # nil otherwise. + property_supported :domain do + if content_for_scanner =~ /No match for\s\"(.+)\"\.\n/ + $1.downcase + else + node("Domain Name", &:downcase) + end + end + + # Gets the unique domain ID as stored by the registry. + # + # Returns a String with the domain ID if available, + # nil otherwise. + property_supported :domain_id do + raise Whois::AttributeNotSupported + end + + # Gets the record status or statuses. + # + # Returns a String/Array with the record status if available, + # nil otherwise. + property_supported :status do + if available? + :available + else + :registered + end + end + + # Checks whether this record is available. + # + # Returns true/false depending whether this record is available. + property_supported :available? do + !!(content_for_scanner =~ /^No match for/) + end + + # Checks whether this record is registered. + # + # Returns true/false depending this record is available. + property_supported :registered? do + !available? + end + + # Gets the date the record was created, + # according to the registry record. + # + # Returns a Time object representing the date the record was created or + # nil otherwise. + property_supported :created_on do + node("Creation Date") { |value| parse_time(value) } + end + + # Gets the date the record was last updated, + # according to the registry record. + # + # Returns a Time object representing the date the record was last updated or + # nil if not available. + property_supported :updated_on do + nil + end + + # Gets the date the record is set to expire, + # according to the registry record. + # + # Returns a Time object representing the date the record is set to expire or + # nil if not available. + property_supported :expires_on do + node("Registry Expiry Date") { |value| parse_time(value) } + end + + # Gets the registrar object containing the registrar details + # extracted from the registry record. + # + # Returns an instance of Parser::Registrar representing the registrar or + # nil if not available. + property_supported :registrar do + if node("Registrar") + Parser::Registrar.new( + name: node("Registrar"), + ) + end + end + + + # Gets the registrant contact object containing the details of the record owner + # extracted from the registry record. + # + # Returns an instance of Parser::Contact representing the registrant contact or + # nil if not available. + property_supported :registrant_contacts do + build_contact("Registrant", Parser::Contact::TYPE_REGISTRANT) + end + + # Gets the administrative contact object containing the details of the record administrator + # extracted from the registry record. + # + # Returns an instance of Parser::Contact representing the administrative contact or + # nil if not available. + property_supported :admin_contacts do + build_contact("Admin", Parser::Contact::TYPE_ADMINISTRATIVE) + end + + # Gets the technical contact object containing the details of the technical representative + # extracted from the registry record. + # + # Returns an instance of Parser::Contact representing the technical contact or + # nil if not available. + property_supported :technical_contacts do + build_contact("Tech", Parser::Contact::TYPE_TECHNICAL) + end + + + # Gets the list of name server entries for this record, + # extracted from the registry record. + # + # @example + # nameserver + # # => [] + # + # @example + # nameserver + # # => [ + # # #, + # # # + # # ] + # + # @return [Array] + property_supported :nameservers do + Array.wrap(node("Name Server")).reject(&:empty?).reverse.map do |name| + Parser::Nameserver.new(name: name.downcase) + end + end + + private + + def build_contact(element, type) + if type == Parser::Contact::TYPE_REGISTRANT + node(element) do + Parser::Contact.new( + type: type, + name: node("#{element}"), + ) + end + elsif Parser::Contact::TYPE_ADMINISTRATIVE + Parser::Contact.new( + type: type, + name: node("Admin Name"), + email: node("Admin Email") + ) + elsif Parser::Contact::TYPE_TECHNICAL + Parser::Contact.new( + type: type, + name: node("Tech Name"), + email: node("Tech Email") + ) + end + end + end + + end +end diff --git a/lib/whois/scanners/whois.registration.ge.rb b/lib/whois/scanners/whois.registration.ge.rb new file mode 100644 index 00000000..562a35f8 --- /dev/null +++ b/lib/whois/scanners/whois.registration.ge.rb @@ -0,0 +1,43 @@ +require_relative 'base' + +module Whois + module Scanners + + class WhoisRegistrationGe < Base + + self.tokenizers += [ + :skip_head, + :scan_available, + :scan_throttled, + :skip_empty_line, + :skip_blank_line, + :scan_keyvalue, + :skip_end, + ] + + tokenizer :scan_available do + if settings[:pattern_available] && @input.skip_until(settings[:pattern_available]) + @ast['status:available'] = true + end + end + + tokenizer :scan_throttled do + if settings[:pattern_throttled] && @input.skip_until(settings[:pattern_throttled]) + @ast['response:throttled'] = true + end + end + + tokenizer :skip_head do + if @input.skip_until(/Domain Name:/) + @input.scan(/\s?(.+)\n/) + @ast["Domain Name"] = @input[1].strip + end + end + + tokenizer :skip_end do + @input.terminate + end + + end + end +end diff --git a/spec/fixtures/responses/whois.registration.ge/ge/status_available.expected b/spec/fixtures/responses/whois.registration.ge/ge/status_available.expected new file mode 100644 index 00000000..0cc17beb --- /dev/null +++ b/spec/fixtures/responses/whois.registration.ge/ge/status_available.expected @@ -0,0 +1,29 @@ +#domain + %s == "u34jedzcq.ge" + +#status + %s == :available + +#available? + %s == true + +#registered? + %s == false + +#created_on + %s == nil + +#updated_on + %s == nil + +#expires_on + %s == nil + + +#registrar + %s == nil + + +#nameservers + %s %CLASS{array} + %s == [] \ No newline at end of file diff --git a/spec/fixtures/responses/whois.registration.ge/ge/status_available.txt b/spec/fixtures/responses/whois.registration.ge/ge/status_available.txt new file mode 100644 index 00000000..8f3f0a06 --- /dev/null +++ b/spec/fixtures/responses/whois.registration.ge/ge/status_available.txt @@ -0,0 +1,27 @@ +No match for "U34JEDZCQ.GE". + + +TERMS OF USE: +The WHOIS service is provided solely for informational purposes. +You are not authorized to access or query our Whois +database through the use of electronic processes that are high-volume and +automated except as reasonably necessary to register domain names or +modify existing registrations; the Data is provided by NIC for +information purposes only, and to assist persons in obtaining information +about or related to a domain name registration record. NIC does not +guarantee its accuracy. By submitting a Whois query, you agree to abide +by the following terms of use: You agree that you may 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 e-mail, telephone, +or facsimile; or (2) enable high volume, automated, electronic processes +that apply to NIC (or its computer systems). The compilation, +repackaging, dissemination or other use of this Data is expressly +prohibited without the prior written consent of NIC. You agree not to +use electronic processes that are automated and high-volume to access or +query the Whois database except as reasonably necessary to register +domain names or modify existing registrations. NIC reserves the right +to restrict your access to the Whois database in its sole discretion to ensure +operational stability. NIC may restrict or terminate your access to the +Whois database for failure to abide by these terms of use. NIC +reserves the right to modify these terms at any time. \ No newline at end of file diff --git a/spec/fixtures/responses/whois.registration.ge/ge/status_registered.expected b/spec/fixtures/responses/whois.registration.ge/ge/status_registered.expected new file mode 100644 index 00000000..42c7d05e --- /dev/null +++ b/spec/fixtures/responses/whois.registration.ge/ge/status_registered.expected @@ -0,0 +1,102 @@ +#domain + %s == "google.ge" + +#domain_id + %s %ERROR{AttributeNotSupported} + +#status + %s == :registered + +#available? + %s == false + +#registered? + %s == true + +#created_on + %s %CLASS{time} + %s %TIME{2006-07-28} + +#expires_on + %s %CLASS{time} + %s %TIME{2022-07-29} + +#registrar + %s %CLASS{registrar} + %s.id == nil + %s.name == "proservice ltd" + %s.organization == nil + %s.url == nil + +#registrant_contacts + %s %CLASS{array} + %s %SIZE{1} + %s[0] %CLASS{contact} + %s[0].type == Whois::Parser::Contact::TYPE_REGISTRANT + %s[0].id == nil + %s[0].name == "Google LLC" + %s[0].organization == nil + %s[0].address == nil + %s[0].city == nil + %s[0].zip == nil + %s[0].state == nil + %s[0].country == nil + %s[0].country_code == nil + %s[0].phone == nil + %s[0].fax == nil + %s[0].email == nil + %s[0].created_on == nil + %s[0].updated_on == nil + +#admin_contacts + %s %CLASS{array} + %s %SIZE{1} + %s[0] %CLASS{contact} + %s[0].type == Whois::Parser::Contact::TYPE_ADMINISTRATIVE + %s[0].id == nil + %s[0].name == "Google LLC" + %s[0].organization == nil + %s[0].address == nil + %s[0].city == nil + %s[0].zip == nil + %s[0].state == nil + %s[0].country == nil + %s[0].country_code == nil + %s[0].phone == nil + %s[0].fax == nil + %s[0].email == "dns-admin@google.com" + %s[0].created_on == nil + %s[0].updated_on == nil + +#technical_contacts + %s %CLASS{array} + %s %SIZE{1} + %s[0] %CLASS{contact} + %s[0].type == Whois::Parser::Contact::TYPE_TECHNICAL + %s[0].id == nil + %s[0].name == "Google LLC" + %s[0].organization == nil + %s[0].address == nil + %s[0].city == nil + %s[0].zip == nil + %s[0].state == nil + %s[0].country == nil + %s[0].country_code == nil + %s[0].phone == nil + %s[0].fax == nil + %s[0].email == "dns-admin@google.com" + %s[0].created_on == nil + %s[0].updated_on == nil + + +#nameservers + %s %CLASS{array} + %s %SIZE{4} + %s[0] %CLASS{nameserver} + %s[0].name == "ns1.google.com" + %s[1] %CLASS{nameserver} + %s[1].name == "ns2.google.com" + %s[2] %CLASS{nameserver} + %s[2].name == "ns3.google.com" + %s[3] %CLASS{nameserver} + %s[3].name == "ns4.google.com" \ No newline at end of file diff --git a/spec/fixtures/responses/whois.registration.ge/ge/status_registered.txt b/spec/fixtures/responses/whois.registration.ge/ge/status_registered.txt new file mode 100644 index 00000000..ce368e7f --- /dev/null +++ b/spec/fixtures/responses/whois.registration.ge/ge/status_registered.txt @@ -0,0 +1,40 @@ + Domain Name: GOOGLE.GE + Creation Date: 2006-07-28 + Registry Expiry Date: 2022-07-29 + Registrar: proservice ltd + Domain Status: Ok + Registrant: Google LLC + Admin Name: Google LLC + Admin Email: dns-admin@google.com + Tech Name: Google LLC + Tech Email: dns-admin@google.com + Name Server: ns4.google.com + Name Server: ns3.google.com + Name Server: ns2.google.com + Name Server: ns1.google.com + + +TERMS OF USE: +The WHOIS service is provided solely for informational purposes. +You are not authorized to access or query our Whois +database through the use of electronic processes that are high-volume and +automated except as reasonably necessary to register domain names or +modify existing registrations; the Data is provided by NIC for +information purposes only, and to assist persons in obtaining information +about or related to a domain name registration record. NIC does not +guarantee its accuracy. By submitting a Whois query, you agree to abide +by the following terms of use: You agree that you may 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 e-mail, telephone, +or facsimile; or (2) enable high volume, automated, electronic processes +that apply to NIC (or its computer systems). The compilation, +repackaging, dissemination or other use of this Data is expressly +prohibited without the prior written consent of NIC. You agree not to +use electronic processes that are automated and high-volume to access or +query the Whois database except as reasonably necessary to register +domain names or modify existing registrations. NIC reserves the right +to restrict your access to the Whois database in its sole discretion to ensure +operational stability. NIC may restrict or terminate your access to the +Whois database for failure to abide by these terms of use. NIC +reserves the right to modify these terms at any time. \ No newline at end of file diff --git a/spec/whois/parsers/responses/whois.registration.ge/ge/status_available_spec.rb b/spec/whois/parsers/responses/whois.registration.ge/ge/status_available_spec.rb new file mode 100644 index 00000000..02f609bd --- /dev/null +++ b/spec/whois/parsers/responses/whois.registration.ge/ge/status_available_spec.rb @@ -0,0 +1,70 @@ +# 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.registration.ge/ge/status_available.expected +# +# and regenerate the tests with the following rake task +# +# $ rake spec:generate +# + +require 'spec_helper' +require 'whois/parsers/whois.registration.ge.rb' + +describe Whois::Parsers::WhoisRegistrationGe, "status_available.expected" do + + subject do + file = fixture("responses", "whois.registration.ge/ge/status_available.txt") + part = Whois::Record::Part.new(body: File.read(file)) + described_class.new(part) + end + + describe "#domain" do + it do + expect(subject.domain).to eq("u34jedzcq.ge") + end + end + describe "#status" do + it do + expect(subject.status).to eq(:available) + end + end + describe "#available?" do + it do + expect(subject.available?).to eq(true) + end + end + describe "#registered?" do + it do + expect(subject.registered?).to eq(false) + end + end + describe "#created_on" do + it do + expect(subject.created_on).to eq(nil) + end + end + describe "#updated_on" do + it do + expect(subject.updated_on).to eq(nil) + end + end + describe "#expires_on" do + it do + expect(subject.expires_on).to eq(nil) + end + end + describe "#registrar" do + it do + expect(subject.registrar).to eq(nil) + end + end + describe "#nameservers" do + it do + expect(subject.nameservers).to be_a(Array) + expect(subject.nameservers).to eq([]) + end + end +end diff --git a/spec/whois/parsers/responses/whois.registration.ge/ge/status_registered_spec.rb b/spec/whois/parsers/responses/whois.registration.ge/ge/status_registered_spec.rb new file mode 100644 index 00000000..83f8f0a8 --- /dev/null +++ b/spec/whois/parsers/responses/whois.registration.ge/ge/status_registered_spec.rb @@ -0,0 +1,150 @@ +# 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.registration.ge/ge/status_registered.expected +# +# and regenerate the tests with the following rake task +# +# $ rake spec:generate +# + +require 'spec_helper' +require 'whois/parsers/whois.registration.ge.rb' + +describe Whois::Parsers::WhoisRegistrationGe, "status_registered.expected" do + + subject do + file = fixture("responses", "whois.registration.ge/ge/status_registered.txt") + part = Whois::Record::Part.new(body: File.read(file)) + described_class.new(part) + end + + describe "#domain" do + it do + expect(subject.domain).to eq("google.ge") + end + end + describe "#domain_id" do + it do + expect { subject.domain_id }.to raise_error(Whois::AttributeNotSupported) + end + end + describe "#status" do + it do + expect(subject.status).to eq(:registered) + end + end + describe "#available?" do + it do + expect(subject.available?).to eq(false) + end + end + describe "#registered?" do + it do + expect(subject.registered?).to eq(true) + end + end + describe "#created_on" do + it do + expect(subject.created_on).to be_a(Time) + expect(subject.created_on).to eq(Time.parse("2006-07-28")) + end + end + describe "#expires_on" do + it do + expect(subject.expires_on).to be_a(Time) + expect(subject.expires_on).to eq(Time.parse("2022-07-29")) + end + end + describe "#registrar" do + it do + expect(subject.registrar).to be_a(Whois::Parser::Registrar) + expect(subject.registrar.id).to eq(nil) + expect(subject.registrar.name).to eq("proservice ltd") + expect(subject.registrar.organization).to eq(nil) + expect(subject.registrar.url).to eq(nil) + end + end + describe "#registrant_contacts" do + it do + expect(subject.registrant_contacts).to be_a(Array) + expect(subject.registrant_contacts.size).to eq(1) + expect(subject.registrant_contacts[0]).to be_a(Whois::Parser::Contact) + expect(subject.registrant_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_REGISTRANT) + expect(subject.registrant_contacts[0].id).to eq(nil) + expect(subject.registrant_contacts[0].name).to eq("Google LLC") + expect(subject.registrant_contacts[0].organization).to eq(nil) + expect(subject.registrant_contacts[0].address).to eq(nil) + expect(subject.registrant_contacts[0].city).to eq(nil) + expect(subject.registrant_contacts[0].zip).to eq(nil) + expect(subject.registrant_contacts[0].state).to eq(nil) + expect(subject.registrant_contacts[0].country).to eq(nil) + expect(subject.registrant_contacts[0].country_code).to eq(nil) + expect(subject.registrant_contacts[0].phone).to eq(nil) + expect(subject.registrant_contacts[0].fax).to eq(nil) + expect(subject.registrant_contacts[0].email).to eq(nil) + expect(subject.registrant_contacts[0].created_on).to eq(nil) + expect(subject.registrant_contacts[0].updated_on).to eq(nil) + end + end + describe "#admin_contacts" do + it do + expect(subject.admin_contacts).to be_a(Array) + expect(subject.admin_contacts.size).to eq(1) + expect(subject.admin_contacts[0]).to be_a(Whois::Parser::Contact) + expect(subject.admin_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_ADMINISTRATIVE) + expect(subject.admin_contacts[0].id).to eq(nil) + expect(subject.admin_contacts[0].name).to eq("Google LLC") + expect(subject.admin_contacts[0].organization).to eq(nil) + expect(subject.admin_contacts[0].address).to eq(nil) + expect(subject.admin_contacts[0].city).to eq(nil) + expect(subject.admin_contacts[0].zip).to eq(nil) + expect(subject.admin_contacts[0].state).to eq(nil) + expect(subject.admin_contacts[0].country).to eq(nil) + expect(subject.admin_contacts[0].country_code).to eq(nil) + expect(subject.admin_contacts[0].phone).to eq(nil) + expect(subject.admin_contacts[0].fax).to eq(nil) + expect(subject.admin_contacts[0].email).to eq("dns-admin@google.com") + expect(subject.admin_contacts[0].created_on).to eq(nil) + expect(subject.admin_contacts[0].updated_on).to eq(nil) + end + end + describe "#technical_contacts" do + it do + expect(subject.technical_contacts).to be_a(Array) + expect(subject.technical_contacts.size).to eq(1) + expect(subject.technical_contacts[0]).to be_a(Whois::Parser::Contact) + expect(subject.technical_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_TECHNICAL) + expect(subject.technical_contacts[0].id).to eq(nil) + expect(subject.technical_contacts[0].name).to eq("Google LLC") + expect(subject.technical_contacts[0].organization).to eq(nil) + expect(subject.technical_contacts[0].address).to eq(nil) + expect(subject.technical_contacts[0].city).to eq(nil) + expect(subject.technical_contacts[0].zip).to eq(nil) + expect(subject.technical_contacts[0].state).to eq(nil) + expect(subject.technical_contacts[0].country).to eq(nil) + expect(subject.technical_contacts[0].country_code).to eq(nil) + expect(subject.technical_contacts[0].phone).to eq(nil) + expect(subject.technical_contacts[0].fax).to eq(nil) + expect(subject.technical_contacts[0].email).to eq("dns-admin@google.com") + expect(subject.technical_contacts[0].created_on).to eq(nil) + expect(subject.technical_contacts[0].updated_on).to eq(nil) + end + end + describe "#nameservers" do + it do + expect(subject.nameservers).to be_a(Array) + expect(subject.nameservers.size).to eq(4) + expect(subject.nameservers[0]).to be_a(Whois::Parser::Nameserver) + expect(subject.nameservers[0].name).to eq("ns1.google.com") + expect(subject.nameservers[1]).to be_a(Whois::Parser::Nameserver) + expect(subject.nameservers[1].name).to eq("ns2.google.com") + expect(subject.nameservers[2]).to be_a(Whois::Parser::Nameserver) + expect(subject.nameservers[2].name).to eq("ns3.google.com") + expect(subject.nameservers[3]).to be_a(Whois::Parser::Nameserver) + expect(subject.nameservers[3].name).to eq("ns4.google.com") + end + end +end