- C#
- Java
- PHP
- Ruby on Rails
- Python
- ColdFusion
- VB
- TSQL
- NodeJS
Address Validation Canada 2 C# Rest Code Snippet
string primaryurl = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=" + address + "&Address2=" + address2 + "&Municipality=" + municiaplity + "&Province=" + province + "&PostalCode=" + postalcode + "&Language=" + language + "&LicenseKey=" + licensekey; string backupurl = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=" + address + "&Address2=" + address2 + "&Municipality=" + municiaplity + "&Province=" + province + "&PostalCode=" + postalcode + "&Language=" + language + "&LicenseKey=" + licensekey; CanadianAddressResponseV2 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.TypeCode == "3")) ; { wsresponse = httpGet(backupurl); } if (wsresponse.Error != null) { ProcessErrorResponse(wsresponse.Error); } else { ProcessSuccessfulResponse(wsresponse.CanadianAddressInfoV2); }
Address Validation Canada 2 Java Rest Code Snippet
String mainurl = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address="+ address + "&Address2=" + address2 + "&Municipality=" + municipality + "&Province=" + province + "&PostalCode=" + postalcode + "&Language=" + language + "&LicenseKey=" + licensekey; String backupurl = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address="+ address + "&Address2=" + address2 + "&Municipality=" + municipality + "&Province=" + province + "&PostalCode=" + postalcode + "&Language=" + language + "&LicenseKey=" + licensekey; //System.out.println(mainurl); AVCA2RestClient avca2rest = new AVCA2RestClient(); JSONObject results = new JSONObject(); results = avca2rest.AddressResponse(mainurl, backupurl);
Address Validation Canada 2 PHP Rest Code Snippets
$URL = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=".urlencode($Address)."&Address2=".urlencode($Address2)."&Municipality=".urlencode($Municipality)."&Province=".urldecode($Province)."&PostalCode=".urldecode($PostalCode)."&Language=".urldecode($Language)."&LicenseKey=".urlencode($LicenseKey); //use backup url once given purchased license key $backupURL = "https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=".urlencode($Address)."&Address2=".urlencode($Address2)."&Municipality=".urlencode($Municipality)."&Province=".urldecode($Province)."&PostalCode=".urldecode($PostalCode)."&Language=".urldecode($Language)."&LicenseKey=".urlencode($LicenseKey); try{ // Get cURL resource $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Address Validation Canada')); 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 Address Validation Canada')); 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; } }
Address Validation Canada 2 RoR Code Snippets
class RequestsController < ApplicationController def show @request = Request.find(params[:id]) #This sets the default timeout for HTTParty get operation. This must be set in order to use the gem default_timeout = 10 address = @request.address1 address2 = @request.address2 municipality = @request.municipality province = @request.province postalcode = @request.postalcode language = @request.language licensekey = @request.licensekey #Set Primary and Backup URLs as needed. This method encodes and standardizes the URI to pass to the REST service. primaryURL = URI.encode("https://trial.serviceobjects.com/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=" + postalcode + "&Province=" + province + "&Municipality=" + municipality + "&Address2=" + address2 + "&Address=" + address + "&Language="+ language + "&LicenseKey=" + licensekey) backupURL = URI.encode("https://trial.serviceobjects.com/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=" + postalcode + "&Province=" + province + "&Municipality=" + municipality + "&Address2=" + address2 + "&Address=" + address + "&Language="+ language + "&LicenseKey=" + licensekey) #These are set to access the hash that is returned @avca2result ="CanadianAddressResponseV2" @avca2info = "CanadianAddressInfoV2" @avca2error = "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) end end private #processes HTTParty response and uses hash names to display #relevant info returned from the ServiceObjects web serivce def processresults(response) #Processes Error Response from the web service #Processes a valid response from the web service end end
Address Validation Canada 2 Python Code Snippet
mAddress = Address.get() if mAddress is None or mAddress == "": mAddress = " " mAddress2 = Address2.get() if mAddress2 is None or mAddress2 == "": mAddress2 = " " mMunicipality = Municipality.get() if mMunicipality is None or mMunicipality == "": mMunicipality = " " mProvince = Province.get() if mProvince is None or mProvince == "": mProvince = " " mPostalCode = PostalCode.get() if mPostalCode is None or mPostalCode == "": mPostalCode = " " mLanguage = Language.get() if mLanguage is None or mLanguage == "": mLanguage = " " mLicenseKey = LicenseKey.get() if mLicenseKey is None or mLicenseKey == "": mLicenseKey = " " #Set the Primary and backup URLs as necessary primaryURL = 'https://trial.serviceobjects.com/gcc/GeoCoderCanada.asmx/GetGeoLocation?' backupURL = 'https://trial.serviceobjects.com/gcc/GeoCoderCanada.asmx/GetGeoLocation?' #The Requests package allows the user to format the path parameters like so instead of having to manually insert them into the URL inputs = {"PostalCode": mPostalCode, 'Province': mProvince, 'Municipality': mMunicipality, 'Address2':mAddress2, 'Address': mAddress, 'Language': mLanguage, '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) #Handel response and check for errors #Attempts to make a call to the service if the primary url failed 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) #Handel response and check for errors #Prints an error if the primary and backup URLs failed except: Label(swin.window, text='Error').pack() print (result)
Address Validation Canada 2 ColdFusion Snippet
<!--Makes Request to web service ---> <cfIf isDefined("form.Action") AND Action neq "" > <cftry> <cfset primaryURL = "https://trial.serviceobjects.com/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=#PostalCode#&Province=#Province#&Municipality=#Municipality#&Address2=#Address2#&Address=#Address#&Language=#Language#&LicenseKey=#LicenseKey#"> <cfhttp url="#primaryURL#" method="get" result="response"> <cfset outputs = XmlParse(response.FileContent)> <cfcatch> <cftry> <cfset backupURL = "https://trial.serviceobjects.com/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=#PostalCode#&Province=#Province#&Municipality=#Municipality#&Address2=#Address2#&Address=#Address#&Language=#Language#&LicenseKey=#LicenseKey#"> <cfhttp url="#backupURL#" method="get" result="response"> <cfset outputs = XmlParse(response.FileContent)> <cfcatch > <cfoutput > The Following Error Occured: #response.StatusCode# </cfoutput> </cfcatch> </cftry> </cfcatch> </cftry> </cfif>
Address Validation 2 Canada 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/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=" + postalcode + "&Province=" + province + "&Municipality=" + municipality + "&Address2=" + address2 + "&Address=" + address + "&Language=" + language + "&LicenseKey=" + licensekey Dim backupurl As String = "https://trial.serviceobjects.com/AVCA2/api.svc/ValidateCanadianAddressV2?PostalCode=" + postalcode + "&Province=" + province + "&Municipality=" + municipality + "&Address2=" + address2 + "&Address=" + address + "&Language=" + language + "&LicenseKey=" + licensekey Dim wsresponse As AVCA2Response.CanadianAddressResponseV2 = 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) End If
Address Validation Canada 2 TSQL Rest Code Snippet
BEGIN SET @sUrl = 'https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=' + @address + '&Address2=' + @address2 + '&Municipality=' + @municipality + '&Province=' + @province + '&PostalCode=' + @postalcode + '&Language=' + @language + '&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://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=' + @address + '&Address2=' + @address2 + '&Municipality=' + @municipality + '&Province=' + @province + '&PostalCode=' + @postalcode + '&Language=' + @language + '&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
Address Validation Canada 2 REST Code Snippet
var primaryUrl = 'https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=' + Address +'&Address2='+ Address2 + '&Municipality=' + Municipality +'&Province=' + Province +'&PostalCode=' + PostalCode + '&Language=' + Language +'&LicenseKey=' + LicenseKey; var backupUrl = 'https://trial.serviceobjects.com/avca2/api.svc/ValidateCanadianAddressV2?Address=' + Address +'&Address2='+ Address2 + '&Municipality=' + Municipality +'&Province=' + Province +'&PostalCode=' + PostalCode + '&Language=' + Language +'&LicenseKey=' + LicenseKey; var req = http.get(primaryUrl, function(res) { res.setEncoding('utf8'); res.on('data', function (results) { //Sets up the XML to JSON parser. JSON makes the response easier to handle. var parser = require('xml2js').Parser({explicitArray: false,ignoreAttrs: true}); parser.parseString(results, function (err, outputs) { if (outputs.CanadianAddressResponseV2.Error != null) { //Indicates a Fatal error has occured. If this happens, the logic will then failover to the backup url if (outputs.CanadianAddressResponseV2.Error.TypeCode == "3") { var backupReq = http.get(backupUrl, function(backupRes) { backupRes.setEncoding('utf8'); backupRes.on('data', function (results) { var parser = require('xml2js').Parser({explicitArray: false,ignoreAttrs: true}); parser.parseString(results, function (err, outputs) { console.log("Backup Call Was Used."); response.end(JSON.stringify(outputs , null, 3)); }); }); }); } else { //Will Display the JSON Formatted Error Response here response.end(JSON.stringify(outputs, null, 3)); return; } } else { //Will Display the JSON Formatted Valid Response here response.end(JSON.stringify(outputs, null, 3)); return; } }); }); });