From 68d0c47a0b9aaf28255e1f098229d231479b639c Mon Sep 17 00:00:00 2001 From: Eric Case Date: Sun, 8 Jun 2014 14:06:59 -0700 Subject: [PATCH] Add 'not available' status to .fi --- lib/whois/record/parser/whois.fi.rb | 13 ++- lib/whois/record/scanners/whois.fi.rb | 7 ++ .../whois.fi/status_reserved.expected | 48 ++++++++++ .../responses/whois.fi/status_reserved.txt | 6 ++ .../whois.fi/status_reserved_spec.rb | 96 +++++++++++++++++++ 5 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 spec/fixtures/responses/whois.fi/status_reserved.expected create mode 100644 spec/fixtures/responses/whois.fi/status_reserved.txt create mode 100644 spec/whois/record/parser/responses/whois.fi/status_reserved_spec.rb diff --git a/lib/whois/record/parser/whois.fi.rb b/lib/whois/record/parser/whois.fi.rb index 5e6952c0b..7377655b7 100644 --- a/lib/whois/record/parser/whois.fi.rb +++ b/lib/whois/record/parser/whois.fi.rb @@ -39,7 +39,9 @@ class WhoisFi < Base property_supported :status do - if registered? + if reserved? + :reserved + elsif registered? case node("status", &:downcase) when "granted" :registered @@ -76,11 +78,11 @@ class WhoisFi < Base property_not_supported :registrar - + property_supported :registrant_contacts do node("descr") do |array| address = node("address") - + Record::Contact.new( type: Record::Contact::TYPE_REGISTRANT, id: array[1], @@ -105,6 +107,11 @@ class WhoisFi < Base end end + # NEWPROPERTY + def reserved? + !!content_for_scanner.match(/Domain not available/) + end + end end diff --git a/lib/whois/record/scanners/whois.fi.rb b/lib/whois/record/scanners/whois.fi.rb index fdd706a89..4b2e7bc88 100644 --- a/lib/whois/record/scanners/whois.fi.rb +++ b/lib/whois/record/scanners/whois.fi.rb @@ -22,6 +22,7 @@ class WhoisFi < Base :scan_available, :scan_disclaimer, :scan_keyvalue, + :scan_reserved ] @@ -31,6 +32,12 @@ class WhoisFi < Base end end + tokenizer :scan_reserved do + if @input.skip(/^Domain not available/) + @ast["status:reserved"] = true + end + end + tokenizer :scan_disclaimer do if @input.match?(/^More information/) @ast["field:disclaimer"] = @input.scan_until(/(.*)\n\n/).strip diff --git a/spec/fixtures/responses/whois.fi/status_reserved.expected b/spec/fixtures/responses/whois.fi/status_reserved.expected new file mode 100644 index 000000000..facca0df4 --- /dev/null +++ b/spec/fixtures/responses/whois.fi/status_reserved.expected @@ -0,0 +1,48 @@ +#disclaimer + %s == "More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority" + + +#domain + %s == nil + +#domain_id + %s %ERROR{AttributeNotSupported} + + +#status + %s == :reserved + +#available? + %s == false + +#reserved? + %s == true + + +#created_on + %s == nil + +#updated_on + %s == nil + +#expires_on + %s == nil + + +#registrar + %s %ERROR{AttributeNotSupported} + +#registrant_contacts + %s %CLASS{array} + %s == [] + +#admin_contacts + %s %ERROR{AttributeNotSupported} + +#technical_contacts + %s %ERROR{AttributeNotSupported} + + +#nameservers + %s %CLASS{array} + %s == [] diff --git a/spec/fixtures/responses/whois.fi/status_reserved.txt b/spec/fixtures/responses/whois.fi/status_reserved.txt new file mode 100644 index 000000000..d49a0e246 --- /dev/null +++ b/spec/fixtures/responses/whois.fi/status_reserved.txt @@ -0,0 +1,6 @@ + +Domain not available + +More information is available at https://domain.fi/ +Copyright (c) Finnish Communications Regulatory Authority + diff --git a/spec/whois/record/parser/responses/whois.fi/status_reserved_spec.rb b/spec/whois/record/parser/responses/whois.fi/status_reserved_spec.rb new file mode 100644 index 000000000..af306b051 --- /dev/null +++ b/spec/whois/record/parser/responses/whois.fi/status_reserved_spec.rb @@ -0,0 +1,96 @@ +# 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.fi/status_reserved.expected +# +# and regenerate the tests with the following rake task +# +# $ rake spec:generate +# + +require 'spec_helper' +require 'whois/record/parser/whois.fi.rb' + +describe Whois::Record::Parser::WhoisFi, "status_reserved.expected" do + + subject do + file = fixture("responses", "whois.fi/status_reserved.txt") + part = Whois::Record::Part.new(body: File.read(file)) + described_class.new(part) + end + + describe "#disclaimer" do + it do + expect(subject.disclaimer).to eq("More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority") + end + end + describe "#domain" do + it do + expect(subject.domain).to eq(nil) + 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(:reserved) + end + end + describe "#available?" do + it do + expect(subject.available?).to eq(false) + end + end + describe "#reserved?" do + it do + expect(subject.reserved?).to eq(true) + 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 raise_error(Whois::AttributeNotSupported) + end + end + describe "#registrant_contacts" do + it do + expect(subject.registrant_contacts).to be_a(Array) + expect(subject.registrant_contacts).to eq([]) + end + end + describe "#admin_contacts" do + it do + expect { subject.admin_contacts }.to raise_error(Whois::AttributeNotSupported) + end + end + describe "#technical_contacts" do + it do + expect { subject.technical_contacts }.to raise_error(Whois::AttributeNotSupported) + end + end + describe "#nameservers" do + it do + expect(subject.nameservers).to be_a(Array) + expect(subject.nameservers).to eq([]) + end + end +end