ColdFusion and the OpenSRS name_suggest API (Part I)

OpenSRS API Add comments

Recently OpenSRS made some changes to their name_suggest API, and I decided to write a cold fusion component to make using it a whole lot easier.  In case someone else out there is interested in using ColdFusion to interact with the OpenSRS API, I thought I would post some of the basics here. 

I kind of threw this together, so it isn’t very feature-rich, but it’s a great starting point if you’re interested.

Anyway.  The process is this: 1) You format the XML request that you’re going to send , 2) you send it over https, and 3) you parse the results into something meaningful.  You will, of course, have to be a OpenSRS reseller with a username and a password.

Here’s the documentation on the API:
http://opensrs.com/resources/domains/documentation/

We’re using the name_suggest function.

First you will need some keywords.  It can be a domain name like cfjazz.com, or it can be something wordy, like "cold fusion jazz".  Here’s the function that formats the XML request that you’re going to send.

<cffunction name="formatRequest_nameSuggest" returnType="string" output="false">

<cfargument name="searchstring" required	= "yes">
<cfargument name="lookup" required	= "no">
<cfargument name="suggestion" required	= "no">
<cfargument name="premium" required	= "no">

<cfparam name="lookup" default = "yes">			
<cfparam name="suggestion" default = "yes">			
<cfparam name="premium" default = "yes">		

<cfset services_list = "">

<cfif #lookup# is "yes">			
 <cfset services_list = listAppend(services_list, "lookup")>				
</cfif>

<cfif #suggestion# is "yes">	
 <cfset services_list = listAppend(services_list, "suggestion")>		
</cfif>

<cfif #premium# is "yes">			
 <cfset services_list = listAppend(services_list, "premium")>			
</cfif>

<cfset services_count = ListLen(services_list)>

<cfsavecontent variable="thePost"><?xml version='1.0' encoding='UTF-8' standalone='no' ?>

<!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>

<OPS_envelope>

<header>

<version>0.9</version>

</header>

<body>

<data_block>

<dt_assoc>

<item key="protocol">XCP</item>

<item key="action">name_suggest</item>

<item key="object">domain</item>

<item key="attributes">

<dt_assoc>

<item key="searchstring">#searchstring#</item>

<item key='languages'>

<dt_array>

<item key='0'>en</item>

</dt_array>

</item>

<item key="tlds">

<dt_array>

<item key="0">.com</item>

<item key="1">.net</item>

<item key="2">.org</item>

<item key="3">.biz</item>

<item key="4">.us</item>

<item key="4">.mobi</item>

</dt_array>

</item>

<item key="services">

<dt_array>

<cfloop from="1" to ="#services_count#" index="tehCount">

<item key="#NumberFormat((tehCount - 1), "9")#">#ListGetAt(services_list, tehCount)#</item>

</cfloop>

</dt_array>

</item>

<item key="maximum">25</item>

</dt_assoc>

</item>

</dt_assoc>

</data_block>

</body>

</OPS_envelope></cfsavecontent>

<cfset trimmedPost = #trim(thePost)#>

<cfreturn #trimmedPost#>

</cffunction>

Yeah, that looks like a lot, but it isn’t really.  It takes the search string you passed it, lets you tell it YES or NO for the lookup, suggestion and premium services and then formats the XML with a CFSAVECONTENT.  If I wanted to improve this, I’d add more CFARGUMENTS to let me pass more of the name_suggest parameters, which can be found here:

http://opensrs.com/resources/documentation/opensrsapixml/name_suggest_domain_request.htm

This will do for now though.  So, to use this function, you just drop a CFINVOKE on the page you post your keywords to.  Like this:

<cfinvoke 					
	component="openSRS.openSRS"
	method="formatRequest_nameSuggest"
	searchstring="#keyword#"
	returnVariable="theRequest"
	>


Pretty straightforward, eh?  You give the CFINVOKE your keywords, and it hands you back some XML in a variable.

(...to be continued)

0 responses to “ColdFusion and the OpenSRS name_suggest API (Part I)”

Leave a Reply

Leave this field empty:

Powered by Mango Blog. Initial Template Design and Icons by N.Design Studio, modified by Michael Cummins.