class Whois::Parsers::BaseNicFr

Base parser for Nic.fr servers.

@abstract

Constants

MULTIVALUE_KEYS

Public Instance Methods

response_throttled?() click to toggle source

Checks whether the response has been throttled.

@return [Boolean]

# File lib/whois/parsers/base_nic_fr.rb, line 104
def response_throttled?
  !!(content_for_scanner =~ /^%% Too many requests\.{3}/)
end

Private Instance Methods

build_hash(tokens) click to toggle source
# File lib/whois/parsers/base_nic_fr.rb, line 155
def build_hash(tokens)
  {}.tap do |hash|
    tokens.each do |key, value|
      if MULTIVALUE_KEYS.include?(key)
        hash[key] ||= []
        hash[key] <<  value
      else
        hash[key] = value
      end
    end
  end
end
parse_contact(element, type) click to toggle source
# File lib/whois/parsers/base_nic_fr.rb, line 113
def parse_contact(element, type)
  return unless content_for_scanner =~ /#{element}:\s+(.+)\n/

  id = $1
  content_for_scanner.scan(/nic-hdl:\s+#{id}\n((.+\n)+)\n/).any? ||
      Whois::Parser.bug!(ParserError, "Unable to parse contact block for nic-hdl: #{id}")
  values = build_hash($1.scan(/(.+?):\s+(.+?)\n/))

  if values["type"] == "ORGANIZATION"
    name = nil
    organization = values["contact"]
    address = values["address"].join("\n")
  else
    name = values["contact"]
    if values["address"].nil?
      organization = nil
      address      = nil
    elsif values["address"].size > 2
      organization = values["address"][0]
      address      = values["address"][1..-1].join("\n")
    else
      organization = nil
      address      = values["address"].join("\n")
    end
  end

  updated_on = values["changed"] ? Time.utc(*values["changed"].split(" ").first.split("/").reverse) : nil

  Parser::Contact.new({
    :type         => type,
    :id           => id,
    :name         => name,
    :organization => organization,
    :address      => address,
    :country_code => values["country"],
    :phone        => values["phone"],
    :fax          => values["fax-no"],
    :email        => values["e-mail"],
    :updated_on   => updated_on,
  })
end