lib/domain_finder.rb in domain_finder-0.0.3 vs lib/domain_finder.rb in domain_finder-0.0.4

- old
+ new

@@ -1,14 +1,20 @@ -require "domain_finder/version" require 'json' require 'net/http' +# Namespace for domain_finder gem module DomainFinder + # The URL of the domain registrar URL = 'https://domai.nr/api/json/search' class << self + + # Searches for the availability of one or more domains by using a domain registrar API. + # + # @param domains [Array<String>] One or more domain names + # @return [Array<String>] Domain availability results def search(domains) results = [] domains.each do |domain| @@ -38,11 +44,16 @@ results end private - def parse_results(results) - json = JSON.parse(results) + # Parses JSON response from API call and converts it to an array of human-readable strings. + # + # @private + # @param json_string [String] A json-parsable string + # @return [Array<String>] An array of human-readable strings + def parse_results(json_string) + json = JSON.parse(json_string) json['results'].map do |result| case result['availability'] when 'available' "o #{result['domain']}" when 'maybe'