Method: Mongo::Srv::Resolver#get_txt_options_string

Defined in:
lib/mongo/srv/resolver.rb

#get_txt_options_string(hostname) ⇒ nil | String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Obtains the TXT records of a host.

Parameters:

  • hostname (String)

    The host whose TXT records should be obtained.

Returns:

  • (nil | String)

    URI options string from TXT record associated with the hostname, or nil if there is no such record.

Raises:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/mongo/srv/resolver.rb', line 132

def get_txt_options_string(hostname)
  records = @resolver.getresources(hostname, Resolv::DNS::Resource::IN::TXT)
  if records.empty?
    return nil
  end

  if records.length > 1
    msg = "Only one TXT record is allowed: querying hostname #{hostname} returned #{records.length} records"

    raise Error::InvalidTXTRecord, msg
  end

  records[0].strings.join
end