lib/domain_finder.rb in domain_finder-0.0.1 vs lib/domain_finder.rb in domain_finder-0.0.2
- old
+ new
@@ -10,19 +10,25 @@
def search(domains)
results = []
domains.each do |domain|
- uri = URI(URL)
+ uri = URI.parse(URL)
params = { q: domain }
uri.query = URI.encode_www_form(params)
- res = Net::HTTP.get_response(uri)
+ 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)
+ 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
@@ -37,14 +43,14 @@
def parse_results(results)
json = JSON.parse(results)
json['results'].map do |result|
case result['availability']
when 'available'
- "○ #{result['domain']}"
+ "o #{result['domain']}"
when 'maybe'
"? #{result['domain']}"
else
- "✘ #{result['domain']}"
+ "x #{result['domain']}"
end
end
end
end
end