- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- TSQL
Name Validation 2 C# Code Snippet
string primaryurl = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/" + Uri.EscapeDataString(name) + " / " + Uri.EscapeDataString(option) + "/" + Uri.EscapeDataString(licensekey) + "?format=xml"; string backupurl = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/" + Uri.EscapeDataString(name) + " / " + Uri.EscapeDataString(option) + "/" + Uri.EscapeDataString(licensekey) + "?format=xml"; NameInfoV2Response wsresponse = new NameInfoV2Response(); wsresponse = httpGet(primaryurl); //checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured. if (wsresponse == null || (wsresponse.Error != null && wsresponse.Error.Type != null && wsresponse.Error.TypeCode == "3")) ; { wsresponse = httpGet(backupurl); } if (wsresponse.Error != null) { ProcessErrorResponse(wsresponse.Error); } else { ProcessSuccessfulResponse(wsresponse); }
Name Validation 2 Java Code Snippet
NameInfoV2Response.Error error = null; NameInfoV2Response.NameInfoV2 nameInfoV2 = null; try { String name = request.getParameter("iName"); String option = request.getParameter("iOption"); String licenseKey = request.getParameter("iKey"); NV2RestClient NV2Client = new NV2RestClient(); NameInfoV2Response result = NV2Client.NameInfoV2(name, option, licenseKey); if (result != null) { error = result.error; nameInfoV2 = result.NameInfoV2; }
Name Validation 2 PHP Code Snippet
// variable cleanup before generating url $Name = trim($Name); $LicenseKey = trim($LicenseKey); $URL = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/".rawurlencode($Name)."/".rawurlencode($Option)."/".rawurlencode($LicenseKey)."?format=xml"; //use backup url once given purchased license key $backupURL = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/".rawurlencode($Name)."/".rawurlencode($Option)."/".rawurlencode($LicenseKey)."?format=xml"; // Get cURL resource $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Name Validation 2')); curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds // Send the request & save response to $resp $resp = curl_exec($curl); // Close request to clear up some resources if($resp == false) { echo "IN back up block"; curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Name Validation 2')); curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds // Send the request & save response to $resp $resp = curl_exec($curl); if($resp == false) { echo "<b> Both rest calls failed </b>"; curl_close($curl); return; }
Name Validation 2 RoR Code Snippet
primaryURL = URI.encode("https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=" + name + "&Option=" + option+ "&LicenseKey=" + licensekey) backupURL = URI.encode("https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=" + name + "&Option=" + option+ "&LicenseKey=" + licensekey) #These are set to access the hash that is returned @nv2response ="NameInfoV2Response" @nv2info = "NameInfoV2" @nv2BestGuessName = "BestGuessName" @nv2error = "Error" #Begins the call the RESTful web service begin response = HTTParty.get(primaryURL, timeout: default_timeout) #processes the response to display to the screen #Passes the response returned from HTTParty and processes them depending on the results processresults(response) rescue StandardError => e begin #uses the backupURl in the event that the service encountered an error response = HTTParty.get(backupURL, timeout: default_timeout) #processes the response returned from using the backupURL processresults(response) #If the backup url railed this will raise an error and display the #error message returned from the HTTParty gem. rescue StandardError => error @status = error.message @displaydata = {"Error" => "A Big Error Occured"} end end
Name Validation 2 Python Code Snippet
primaryURL = 'https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?' backupURL = 'https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?' #The Requests package allows the user to format the path parameters like so instead of having to manually insert them into the URL inputs = {'Name': mName, 'Option':mOption, 'LicenseKey': mLicenseKey} try: result = requests.get(primaryURL, params=inputs) #Parses the XML response from the service into a python dictionary type outputs = xmltodict.parse(result.content) #checks the output for Errors and displays the info accordingly if 'Error' in outputs['NameInfoV2Response']: #loops through the response from the service and prints the values to the screen. for key, value in outputs['NameInfoV2Response']['Error'].iteritems(): Label(swin.window, text=str(key) + " : " + str(value)).pack() else: for key, value in outputs['NameInfoV2Response']['NameInfoV2'].iteritems(): if key != 'BestGuessName': Label(swin.window, text=str(key) + " : " + str(value)).pack() except: try: result = requests.get(backupURL, params=inputs) #Parses the XML response from the service into a python dictionary type outputs = xmltodict.parse(result.content) #checks the output for Errors and displays the info accordingly if 'Error' in outputs['NameInfoV2Response']: #loops through the response from the service and prints the values to the screen. for key, value in outputs['NameInfoV2Response']['Error'].iteritems(): Label(swin.window, text=str(key) + " : " + str(value)).pack() else: for key, value in outputs['NameInfoV2Response']['NameInfoV2'].iteritems(): if key != 'BestGuessName': Label(swin.window, text=str(key) + " : " + str(value)).pack()
Name Validation 2 ColdFusion Code Snippet
<cfIf isDefined("form.Action") AND Action neq "" > <cftry> <cfset primaryURL = "https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=#Name#&Option=#Option#&LicenseKey=#LicenseKey#"> <cfhttp url="#primaryURL#" method="get" result="response"> <cfset outputs = XmlParse(response.FileContent)> <cfcatch > <cftry> <cfset backupURL = "https://trial.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=#Name#&Option=#Option#&LicenseKey=#LicenseKey#"> <cfhttp url="#backupURL#" method="get" result="response"> <cfset outputs = XmlParse(response.FileContent)> <cfcatch type="any" name="error"> <cfoutput> The Following Error Occured: "#error.Message#" </cfoutput> </cfcatch> </cftry> </cfcatch> </cftry> </cfif>
Name Validation 2 VB Code Snippet
'encodes the URLs for the get Call. Set the primary and back urls as necessary Dim primaryurl As String = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/" + Uri.EscapeUriString(name) + "/" + Uri.EscapeUriString(opt) + "/" + Uri.EscapeUriString(licensekey) + "?format=xml" Dim backupurl As String = "https://trial.serviceobjects.com/NV2/api.svc/NameInfoV2/" + Uri.EscapeUriString(name) + "/" + Uri.EscapeUriString(opt) + "/" + Uri.EscapeUriString(licensekey) + "?format=xml" Dim wsresponse As New NameInfoV2Response() wsresponse = httpGet(primaryurl) 'checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured. If wsresponse Is Nothing OrElse (wsresponse.[Error] IsNot Nothing AndAlso wsresponse.[Error].TypeCode = "3") Then wsresponse = httpGet(backupurl) End If If wsresponse.[Error] IsNot Nothing Then ProcessErrorResponse(wsresponse.[Error]) Else ProcessSuccessfulResponse(wsresponse)
Name Validation 2 TSQL Code Snippet
BEGIN SET @sUrl = 'https://sws.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=' + @name + '&Option=' + @option + '&LicenseKey=' + @key EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sUrl, false EXEC sp_OAMethod @obj, 'send' EXEC sp_OAGetProperty @obj, 'responseText', @response OUT --Checks the Response for a fatal error or if null. IF @response IS NULL BEGIN SET @sBackupUrl = 'https://swsbackup.serviceobjects.com/nv2/api.svc/NameInfoV2?Name=' + @name + '&Option=' + @option + '&LicenseKey=' + @key EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sBackupUrl, false EXEC sp_OAMethod @obj, 'send' EXEC sp_OAGetProperty @obj, 'responseText', @response OUT END END