Module: DomainFinder
- Defined in:
- lib/domain_finder.rb
Overview
Namespace for domain_finder gem
Constant Summary collapse
- URL =
The URL of the domain registrar
'https://domai.nr/api/json/search'
Class Method Summary collapse
-
.search(domains) ⇒ Array<String>
Searches for the availability of one or more domains by using a domain registrar API.
Class Method Details
.search(domains) ⇒ Array<String>
Searches for the availability of one or more domains by using a domain registrar API.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/domain_finder.rb', line 16 def search(domains) results = [] domains.each do |domain| uri = URI.parse(URL) params = { q: domain } uri.query = URI.encode_www_form(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) res = http.request(request) results << "** #{domain} **" if domains.size > 1 if res.is_a?(Net::HTTPSuccess) results += parse_results(res.body) elsif res.is_a?(Net::HTTPBadRequest) results << "Registrar doesn't like your request. Try a different one." else raise "Error #{res.code} while accessing domain registrar" end end results end |