Domains-domainName-namespinner:SAMPLE
From Hostway API Documentation
SAMPLE /domains/{domainName}/namespinner
This page contains JavaScript and HTML sources used to perform domain name availbility searches for suggested domain names.
Contents |
JavaScript
/**** DISCLAIMER The code examples, API, information, data, and other materials (collectively "Materials") made available on this website are provided on an "as is", "as available" basis, without any warranty as to the completeness, accuracy, reliability, suitability, availability, merchantability or fitness for a particular purpose. Hostway expressly makes no warranty, representation, or guaranty as to the content, sequence, timeliness, or completeness of the Materials. Hostway further makes no warranty, representation, or guaranty that the Materials will be uninterrupted or error free or bug free. Hostway will not provide any support for the Materials, and Hostway is not obligated correct any issues may exist in the Materials whether or not Hostway has knowledge of such issues. However, Hostway reserves the right to amend, modify, or delete all or any portion of the Materials at any time at Hostway's sole discretion, and such amendment, modification, or deletion may affect, alter, or terminate the functionality of any previous versions of the Materials (such as the code examples) without notice. Hostway will have absolutely no liability in connection with or arising from the Materials, your use of the Materials, or the availability or unavailability of any of the Materials. Furthermore, Hostway expressly disclaims all liability for, without limitation: i. Any and all damage to your computer, hardware, data, information, materials, and business arising from the Materials or your use, modification, or distribution of the Materials; ii. Any and all indirect or consequential loss or damage, loss of data or loss of profits arising out of, or in connection with, your use, modification, or distribution of the Materials; iii. Any and all functions of any modifications that you make to the Materials, including any loss, damage, or other liability resulting from your modification of the Materials; iv. Any and all losses or damages caused, in whole or in part, by Hostway's actions, omissions, or negligence in procuring, compiling, or delivering the Materials; v. Any and all errors, omissions, or inaccuracies in the Materials regardless of how caused, or delays or interruptions in delivery of the Materials; or vi. Any decision you or any third party may make, or action taken or not taken, in reliance upon the Materials. For the purposes of this disclaimer, "Hostway" includes, without limitation, Hostway's divisions, affiliates, subsidiaries, successors, parent companies, and their (including Hostway's) executives, directors, officers, managers, employees, consultants, contractors, agents, affiliates, third-party providers, merchants, licensors or the like. ****/ var publicApiUrl = 'http://coreapi01.ote.chicago.hostway:8092'; /** * suggestNames : * * Make an ajax request to get the availability of suggested domain names. * Assembles querystring via queryStringMap * Assemble url with * 1. publicApiUrl * 2. nameSuggest * 3. querystring * * @constructor * @this {suggestNames} * @param {string} nameSuggest, the second level domain name text to spin. * @param {Object.<string, string>} queryStringMap, a map of all the additional attributes to send as querystring. * @param {function( { status: number, name: string, suggestions[{name:string, tld:string, available:boolean}] } )} * resultHandler, function object holding the results of a spin call. * */ function suggestNames(nameSuggest, queryStringMap, resultHandler) { var qs = ""; // // build query string with additional parameters to be sent with name spinner request // for(var key in queryStringMap){ if (queryStringMap.hasOwnProperty(key)) { if(key=='maxResults' && queryStringMap[key] >= 0 && new Number(queryStringMap[key]) > 0 ){ qs = qs + "maxResults="+queryStringMap[key]+'&'; } if(key=='addRelated' && queryStringMap[key]){ qs = qs + "AddRelated="+queryStringMap[key]+'&'; } if(key=='useHyphens'){ qs = qs + "useHyphens="+queryStringMap[key]+'&'; } if(key=='tldList' && (queryStringMap[key] != null && queryStringMap[key].length > 0)){ qs = qs + "TLDList="+queryStringMap[key]+'&'; } } } // Remove invalid chars. Input should be a set of keywords like 'Smart Investor' // or a second level domain name like 'smartinvestor.com' // nameSuggest = nameSuggest.replace("\\",""); nameSuggest = nameSuggest.replace("http://",""); nameSuggest = nameSuggest.replace("/",""); nameSuggest = nameSuggest.replace("www\.",""); var uri = '/domains/' + nameSuggest + '/namespinner'; // // exec spinner request // $.ajax({ type: "GET", url: publicApiUrl + uri +'?'+qs, dataType: "json", success: function(data, textStatus, jqXHR) { console.log('SUCCESS ' + textStatus); result = { status: jqXHR.status, name: nameSuggest, suggestions:data.suggestions }; resultHandler(result); }, error: function(jqXHR, textStatus, errorThrown) { console.log('Error status=' + jqXHR.status); result = { status: jqXHR.status, name: nameSuggest}; resultHandler(result); } }); }
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!-- DISCLAIMER The code examples, API, information, data, and other materials (collectively "Materials") made available on this website are provided on an "as is", "as available" basis, without any warranty as to the completeness, accuracy, reliability, suitability, availability, merchantability or fitness for a particular purpose. Hostway expressly makes no warranty, representation, or guaranty as to the content, sequence, timeliness, or completeness of the Materials. Hostway further makes no warranty, representation, or guaranty that the Materials will be uninterrupted or error free or bug free. Hostway will not provide any support for the Materials, and Hostway is not obligated correct any issues may exist in the Materials whether or not Hostway has knowledge of such issues. However, Hostway reserves the right to amend, modify, or delete all or any portion of the Materials at any time at Hostway's sole discretion, and such amendment, modification, or deletion may affect, alter, or terminate the functionality of any previous versions of the Materials (such as the code examples) without notice. Hostway will have absolutely no liability in connection with or arising from the Materials, your use of the Materials, or the availability or unavailability of any of the Materials. Furthermore, Hostway expressly disclaims all liability for, without limitation: i. Any and all damage to your computer, hardware, data, information, materials, and business arising from the Materials or your use, modification, or distribution of the Materials; ii. Any and all indirect or consequential loss or damage, loss of data or loss of profits arising out of, or in connection with, your use, modification, or distribution of the Materials; iii. Any and all functions of any modifications that you make to the Materials, including any loss, damage, or other liability resulting from your modification of the Materials; iv. Any and all losses or damages caused, in whole or in part, by Hostway's actions, omissions, or negligence in procuring, compiling, or delivering the Materials; v. Any and all errors, omissions, or inaccuracies in the Materials regardless of how caused, or delays or interruptions in delivery of the Materials; or vi. Any decision you or any third party may make, or action taken or not taken, in reliance upon the Materials. For the purposes of this disclaimer, "Hostway" includes, without limitation, Hostway's divisions, affiliates, subsidiaries, successors, parent companies, and their (including Hostway's) executives, directors, officers, managers, employees, consultants, contractors, agents, affiliates, third-party providers, merchants, licensors or the like. --> <title>Domain Name Suggestions Availability Check</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript" src="namespinner.js"></script> <script type="text/javascript"> // show or hide advance attributes, default to false var advacedAttr=false; // show or hide help content, default to false var help=false; // Used only to show how long each name suggestion search takes. var curTime = (new Date()).getTime(); /* * UI help content hover action. */ (function($){ $(document).ready(function() { // // onclick show/remove advanced settings // $('#advancedSettings').click(function() { if(!advacedAttr) { $('[name=advancedSettings]').css("visibility","visible"); $('#content').css("height","290"); advacedAttr=true; }else{ $('[name=advancedSettings]').css("visibility","hidden"); $('#content').css("height","50"); advacedAttr=false; $('[name=help]').empty(); help=false; } }); // // onclick show/remove help content // $('#help').click(function() { if(!help){ $('[name=help]').append( '<ul>'+ '<li>Add Related : Return domain names that are related to the SLD</li>'+ '<li>Use Hyphens : Return domain names that include hyphens</li>'+ '<li>Max Results : Maximum number of suggested names to return in <br/>'+ 'addition to your input (between 0 and 99)'+ '</ul>' ); help=true; $('#content').css("height","490"); $('#content').css("width","400"); }else{ $('[name=help]').empty(); help=false; $('#content').css("height","290"); $('#content').css("width","400"); } }); // // formatting of suggestion text area field // $('[name=nameSuggest]').click(function(){ if ($(this).val() == 'Enter search term') { $(this).val(''); } $(this).css('color','#333'); }); }); })(window.jQuery || window.$); /**** * * Callback function to display results returned in the suggestNames * call. This function reads the name suggestion results returned by * the Hostway Public API Server as a JSON structure. It keeps track * of all the TLDs returned in the result and builds a list of the * suggested names for each TLD and whether that name is available or * not. It then builds an HTML table with the TLDs in the top row. * */ function displayResult(result) { /***** ------ An example of the results returned for the search term 'DerivativesMarket' and Max Results was set to 3. The three results are 'DerivativesSell', 'DerivativesStore' and 'DerivativesShop'. Note that useHyphens and addRelated do not have an impact on the results in this case as the first 3 results do not make use of hyphens or related words. { "suggestions": [ {"available": "true", "name": "DerivativesSell", "tld": "Com"}, {"available": "true", "name": "DerivativesSell", "tld": "Net"}, {"available": "true", "name": "DerivativesSell", "tld": "Org"}, {"available": "true", "name": "DerivativesSell", "tld": "Info"}, {"available": "true", "name": "DerivativesSell", "tld": "Biz"}, {"available": "true", "name": "DerivativesSell", "tld": "Pro"}, {"available": "true", "name": "DerivativesSell", "tld": "Mobi"}, {"available": "true", "name": "DerivativesSell", "tld": "Asia"}, {"available": "true", "name": "DerivativesSell", "tld": "Ca"}, {"available": "true", "name": "DerivativesSell", "tld": "Co"}, {"available": "true", "name": "DerivativesSell", "tld": "Us"}, {"available": "true", "name": "DerivativesStore", "tld": "Com"}, {"available": "true", "name": "DerivativesStore", "tld": "Net"}, {"available": "true", "name": "DerivativesStore", "tld": "Org"}, {"available": "true", "name": "DerivativesStore", "tld": "Info"}, {"available": "true", "name": "DerivativesStore", "tld": "Biz"}, {"available": "true", "name": "DerivativesStore", "tld": "Pro"}, {"available": "true", "name": "DerivativesStore", "tld": "Mobi"}, {"available": "true", "name": "DerivativesStore", "tld": "Asia"}, {"available": "true", "name": "DerivativesStore", "tld": "Ca"}, {"available": "true", "name": "DerivativesStore", "tld": "Co"}, {"available": "true", "name": "DerivativesStore", "tld": "Us"}, {"available": "false", "name": "DerivativesShop", "tld": "Com"}, {"available": "false", "name": "DerivativesShop", "tld": "Net"}, {"available": "true", "name": "DerivativesShop", "tld": "Org"}, {"available": "true", "name": "DerivativesShop", "tld": "Info"}, {"available": "true", "name": "DerivativesShop", "tld": "Biz"}, {"available": "false", "name": "DerivativesShop", "tld": "Pro"}, {"available": "true", "name": "DerivativesShop", "tld": "Mobi"}, {"available": "true", "name": "DerivativesShop", "tld": "Asia"}, {"available": "true", "name": "DerivativesShop", "tld": "Ca"}, {"available": "true", "name": "DerivativesShop", "tld": "Co"}, {"available": "true", "name": "DerivativesShop", "tld": "Us"} ] } ------ *****/ $("#resultMsg").css('text-decoration', 'none'); if (result.status == 200) { var headerArr = []; var suggestions = {}; var content = ""; $.each(result.suggestions, function(key, suggestion) { // Add each TLD to a header array for display. if ( $.inArray( suggestion.tld, headerArr ) == -1 ) { headerArr.push(suggestion.tld); } // And build a dictionary of results that looks like this: // { // "suggested1": {"com": {"available" :"true"}, "net": {"available" :"false"}}, // "suggested2": {"com": {"available" :"false"}, "net": {"available" :"false"}} // } if (!(suggestion.name in suggestions)) { suggestions[suggestion.name] = {}; } suggestions[suggestion.name][suggestion.tld] = {}; suggestions[suggestion.name][suggestion.tld].available = suggestion.available; }); // Show the results, including TLDs header in a table content += "<table><tr><td><strong>Name</strong></td>"; for(name in headerArr) { content+= "<td cellspacing=\"25px\"><strong>."+headerArr[name].toLowerCase()+"</strong></td>"; } content += "</tr>"; for(var name in suggestions) { var str = "<tr><td>"+name+"</td>"; for (var tld in suggestions[name]) { if (suggestions[name][tld].available == 'true') { // include a checkbox for a domain because the domain is available and could // be selected for registration str += "<td align=\"center\"><input type=\"checkbox\" name=\"domain\" value=\""+name+"."+tld+"\"/></td>"; } else { // suggested domain name is not available for this TLD. str += "<td align=\"center\">X</td>"; } } str += "</tr>"; content += str; } content += "</table>"; alert var deltaTime = (new Date()).getTime() - curTime ; $(".namespinnerResult").html(content); $("#resultMsg").css('text-decoration', 'none'); $("#resultMsg").text(" (results in "+deltaTime +" ms)"); } else { $("#resultMsg").text("Error (" + result.status + ")"); } } /* * Submit the query. */ function nameSearch() { // // nameSuggest - the second level domain string used to search for additional suggestions // var nameSuggest = $('[name=nameSuggest]').val(); // used to show the time taken to perform the lookup. curTime = (new Date()).getTime(); // gather form submittion fields var tldList=""; var i = 0; $(':checkbox').each(function() { if(this.name == 'tld' && this.checked){ // append the TLD to the query string tldList = tldList + $(this).attr('value') +','; } }); if(tldList.charAt( tldList.length-1 ) == ",") { tldList = tldList.slice(0, -1); } var addRelated = $('[name=AddRelated]').attr('checked')?true:false; var useHyphens = $('[name=UseHyphens]').attr('checked')?true:false; var maxResults = $('[name=MaxResults]').val(); $("#resultMsg").css('text-decoration', 'blink'); $(".namespinnerResult").empty(); $("#resultMsg").text("Checking ..."); // Form field validation var errorMessage; if (isNaN(maxResults / 1) != false) { errorMessage = "maxResults needs to be between 0 and 99"; } else if (nameSuggest.indexOf("\\") !=-1) { errorMessage = "Please remove \\ from the name suggestion string"; } else if (nameSuggest.indexOf("http://") == 0) { errorMessage = "Please remove http:// from the name suggestion string"; } else if (nameSuggest.indexOf("/") !=-1) { errorMessage = "Please remove / from the name suggestion string"; } else if (nameSuggest.indexOf("www.") == 0) { errorMessage = "Please remove www. from the name suggestion string"; } // Upon error, display message and stop execution if(errorMessage != null){ $("#resultMsg").text(errorMessage); $("#resultMsg").css('color','red'); return; } // querystring map information in order to submit additional attribute (not required). // empty querystring will results in default behaviour var queryString = { 'tldList': tldList, 'addRelated': addRelated, 'useHyphens': useHyphens, 'maxResults': maxResults }; // call namespinner // suggestNames(nameSuggest, queryString, displayResult); } </script> </head> <style type="text/css"> .div1{ display:inline; color:green;} .div2{ display:inline;visibility:hidden;} </style> <body> <div id="info" style="width: 400px;"> <b>Domain name suggestion tool </b> - This page provides a basic example of the domain name suggestion tool which generates search results for domains that are similar to the one provided as input. Search results can be adjusted by allowing the use of hyphens separating words and by allowing the use of related words. The number of results can set from 1 to 99 with the default being 20. The set of To Level Domains (TLDs) can also be controlled. </div> <br/> <div id="content" style="background-color: #fafafa; border: solid 1px #333333; padding: 20px; padding-top: 0px; width: 400px; height: 50px;"> <form method="post" id="domainSearchForm" onsubmit="nameSearch(); return false;"> <div id="formContent"> <br> <input type="text" name="nameSuggest" size="30" maxlength="60" value="Enter search term"/><input type="submit" name="SearchButton" value="Get suggestions" /> <br/> <a id="advancedSettings" href="#">Advanced setting</a> <br> <div name="advancedSettings" class="div2"> <table border="0" width="400"> <tr> <td><input type="checkbox" name="UseHyphens" value="1"/></td><td>Use Hyphens</td> </tr> <tr> <td><input type="checkbox" name="AddRelated" value="1"/></td><td>Add Related</td> </tr> <tr> <td><input type="text" name="MaxResults" size="2" maxlength="2"/></td><td>Max Results</td> </tr> <tr> <td valign="top">Tld list<div class="div1" name="tldListHelp"></div></td> <td> <table> <tr> <td><input type="checkbox" name="tld" value="com" id="com"/><label for="com">com</label></td> <td><input type="checkbox" name="tld" value="net" id="net"/> <label for="net">net</label> </td> <td><input type="checkbox" name="tld" value="org" id="org"/> <label for="org">org</label> </td> <td><input type="checkbox" name="tld" value="info" id="info"/> <label for="info">info</label> </td> </tr> <tr> </tr> <tr> <td><input type="checkbox" name="tld" value="co" id="co"/> <label for="co">co</label> </td> <td><input type="checkbox" name="tld" value="biz" id="biz"/> <label for="biz">biz</label> </td> <td><input type="checkbox" name="tld" value="pro" id="pro"/> <label for="pro">pro</label> </td> <td><input type="checkbox" name="tld" value="mobi" id="mobi"/> <label for="mobi">mobi</label> </td> </tr> <tr> <td><input type="checkbox" name="tld" value="us" id="us"/> <label for="us">us</label> </td> <td><input type="checkbox" name="tld" value="ca" id="ca"/> <label for="ca">ca</label> </td> <td><input type="checkbox" name="tld" value="asia" id="asia"/> <label for="asia">asia</label> </td> </tr> <tr> </tr> </table> </td> </tr> <tr> <td colspan="2" align="left"> <a id="help" href="#">Help</a> <br/> <div name="help"></div> </td> </tr> </table> </div> </div> </form> </div> <div style="text-align:left" id="resultMsg"></div> <div class="namespinnerResult"></div> </body> </html>
See also