Address Detective C# Code Snippet

string mainURL = TrialURL+ address1 + "/" + address2 + "/" + city + "/" + state + "/" + postalCode + "/" + businessName + "/" + phoneNumber + "/" + fullName + "/" + firstName + "/" + lastName + "/" + licenseKey;
 ADResponse result = null;
try
{
    result = HttpGet(mainURL);
    //NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
    if (result == null || (result.error != null && result.error.TypeCode == "3"))
     {
     return HttpGet(backupURL);
     }
 else
 {
    return result;
 }
}
   
private ADResponse HttpGet(string requestUrl)
{
  try
  {
   //NOTE: URL encoding occurs automatically when creating the web request
   HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
   request.Timeout = WEB_SERVICE_REQUEST_TIMEOUT;//timeout for get operation
   
  using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
       if (response.StatusCode != HttpStatusCode.OK)
         throw new Exception(String.Format(
         "Server error (HTTP {0}: {1}).",
          response.StatusCode,
          response.StatusDescription));
  
          //parse response
          DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ADResponse));
          object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
          ADResponse jsonResponse = objResponse as ADResponse;
          return jsonResponse;
     }
   }
}
  
 private void ProcessResponse(ADResponse response)
        {
            try
            {
                //processing result
                if (response.error == null)
                {
                    ProcessResult(response);
                }
                //processing error
                else
                {
                    ProcessError(response.error);
                }
            }
              
        }

Address Detective Java Code Snippet

FoundAddressResponse ADResponse = null;
ADError error = null;
FixedAddressResponse.FixedAddress[] addresses = null;
String addr1 = request.getParameter("iAddr1");
String addr2 = request.getParameter("iAddr2");
String city = request.getParameter("iCity");
String state = request.getParameter("iState");
String postalCode = request.getParameter("iPostalCode");
String businessName = request.getParameter("iBusinessName");
String phoneNumber = request.getParameter("iPhoneNumber");
String fullName = request.getParameter("iFullName");
String firstName = request.getParameter("iFirstName");
String lastName = request.getParameter("iLastName");
String licenseKey = request.getParameter("iKey");
  
ADRestClient ADClient = new ADRestClient();
FixedAddressResponse result = ADClient.FindAddress(addr1,addr2, city, state, postalCode, businessName, phoneNumber, fullName, firstName, lastName, licenseKey);
if (result != null) {
error = result.error;
addresses = result.Addresses;
}
   
//Process Results
if (error == null) {
    //DOTS Address Detective Results
          
}
   
//Process Errors
else{
}
    //DOTS Address Detective Error
      
}

Address Detective PHP Code Snippet

<?php
    $Address1 = trim($Address1);
    $Address2 = trim($Address2);
    $City = trim($City);
    $State = trim($State);
    $PostalCode = trim($PostalCode);
    $BusinessName = trim($BusinessName);
    $PhoneNumber = trim($PhoneNumber);
    $FullName = trim($FullName);
    $FirstName = trim($FirstName);
    $LastName = trim($LastName);
    $LicenseKey = trim($LicenseKey);
   
$TrialURL="https://trial.serviceobjects.com/AD/api.svc/FindAddressJson/".rawurlencode($Address1)."/".rawurlencode($Address2)."/".rawurlencode($City)."/".rawurlencode($State)."/".rawurlencode($PostalCode)."/".rawurlencode($BusinessName)."/".rawurlencode($PhoneNumber)."/".rawurlencode($FullName)."/".rawurlencode($FirstName)."/".rawurlencode($LastName)."/".rawurlencode($LicenseKey);
  
        // Get cURL resource
            $curl = curl_init();
            curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects AddressDetective'));
            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)
            {
                curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Address Detective'));
                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;
                }
            }
          
        try
        {
            $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($resp, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
        }
        catch (Exception $e)
        { 
            echo "Invalid input.";
            $gotValidInput = false;
        }
        if($gotValidInput)
        {
            //Process AD Results
        }
        else
        {
            //Process AD Error
        }
?>

Address Detective RoR Code Snippet

class RequestsController < ApplicationController
  
      address1 = @request.address1
      address2 = @request.address2
      city = @request.city
      state = @request.state
      postalcode = @request.postalcode
      businessname = @request.businessname
      phonenumber = @request.phonenumber
      fullname = @request.fullname
      firstname = @request.firstname
      lastname = @request.lastname
      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/ad/api.svc/FindAddress?"+"Address1=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "BusinessName=" + businessname + "&PhoneNumber=" + phonenumber + "&FullName=" + fullname + "&FirstName=" + firstname + "&LastName=" + lastname + "&LicenseKey=" + licensekey)
      backupURL = URI.encode("https://trial.serviceobjects.com/ad/api.svc/FindAddress?"+"Address1=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "BusinessName=" + businessname + "&PhoneNumber=" + phonenumber + "&FullName=" + fullname + "&FirstName=" + firstname + "&LastName=" + lastname + "&LicenseKey=" + licensekey)
        
        
      #These are set to access the hash that is returned
      @adresult ="FixedAddressResponse"
      @adaddresses = "Addresses"
      @adfixed = "FixedAddress"
      @aderror = "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" => "An Error Occured"}
            end
      end
        
  end
    private
    #processes HTTParty response a
    def processresults(response)   
          
    end
      
end

Address Detective Python Code Snippet

mAddress1 = Address1.get()
if mAddress1 is None or mAddress1 == "":
    mAddress1 = " "
mAddress2 = Address2.get()
if mAddress2 is None or mAddress2 == "":
    mAddress2 = " "
mCity = City.get()
if mCity is None or mCity == "":
    mCity = " "
mState = State.get()
if mState is None or mState == "":
    mState = " "
mPostalCode = PostalCode.get()
if mPostalCode is None or mPostalCode == "":
    mPostalCode = " "
mBusinessName = BusinessName.get()
if mBusinessName is None or mBusinessName == "":
    mBusinessName = " "
mPhoneNumber = PhoneNumber.get()
if mPhoneNumber is None or mPhoneNumber == "":
    mPhoneNumber = " "
mFullName = FullName.get()
if mFullName is None or mFullName == "":
    mFullName = " "
mFirstName = FirstName.get()
if mFirstName is None or mFirstName == "":
    mFirstName = " "
mLastName = LastName.get()
if mLastName is None or mLastName == "":
    mLastName = " "
mLicenseKey = LicenseKey.get()
if mLicenseKey is None or mLicenseKey == "":
    mLicenseKey = " "
#Set the primary and backup URLs as necessary
primaryURL = 'https://trial.serviceobjects.com/ad/api.svc/FindAddress?'
backupURL = 'https://trial.serviceobjects.com/ad/api.svc/FindAddress?'
#The
 Requests package allows the user to format the path parameters like so
instead of having to manually insert them into the URL
inputs = {'Address1': mAddress1, 'Address2': mAddress2, 'City': mCity, 'State': mState, "PostalCode": mPostalCode, 'BusinessName': mBusinessName, 'PhoneNumber': mPhoneNumber, 'FullName': mFullName, 'FirstName':mFirstName, 'LastName':mLastName, '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)
  
    #handle response and displays the info accordingly
  
#This tries the backup URL 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)
  
        #handle response and displays the info accordingly
         
    #Prints an error message to screen if the primary and backup url failed
    except:
        Label(swin.window, text='Error').pack()
        
        print (result)

Address Detective ColdFusion Code Snippet

<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
    <cftry>
        <cfset primaryURL =  "https://trial.serviceobjects.com/ad/api.svc/FindAddress?Address1=#Address1#&Address2=#Address2#&City=#City#&State=#State#&PostalCode=#PostalCode#&BusinessName=#BusinessName#&PhoneNumber=#PhoneNumber#&FullName=#FullName#&FirstName=#FirstName#&LastName=#LastName#&LicenseKey=#LicenseKey#">
        <cfhttp url="#primaryURL#" method="get" result="response">
        <cfset outputs = XmlParse(response.FileContent)>
        <cfcatch>
            <cftry>
                <cfset backupURL =  "https://trial.serviceobjects.com/ad/api.svc/FindAddress?Address1=#Address1#&Address2=#Address2#&City=#City#&State=#State#&PostalCode=#PostalCode#&BusinessName=#BusinessName#&PhoneNumber=#PhoneNumber#&FullName=#FullName#&FirstName=#FirstName#&LastName=#LastName#&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 Detective 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/ad/api.svc/FindAddress?" + "Address1=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "BusinessName=" + businessname + "&PhoneNumber=" + phonenumber + "&FullName=" + fullname + "&FirstName=" + firstname + "&LastName=" + lastname + "&LicenseKey=" + licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/ad/api.svc/FindAddress?" + "Address1=" + address1 + "&Address2=" + address2 + "&City=" + city + "&State=" + state + "&PostalCode=" + postalcode + "BusinessName=" + businessname + "&PhoneNumber=" + phonenumber + "&FullName=" + fullname + "&FirstName=" + firstname + "&LastName=" + lastname + "&LicenseKey=" + licensekey
  
Dim wsresponse As ADResponse.FixedAddressResponse = 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 Detective TSQL Code Snippet

BEGIN
    SET @sUrl = 'https://trial.serviceobjects.com/ad/api.svc/FindAddress?Address1=' + @address1 + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&PostalCode=' + @postalcode + '&BusinessName=' + @businessname + '&PhoneNumber=' + @phonenumber + '&FullName=' + @fullname + '&FirstName=' + @firstname + '&LastName=' + @lastname + '&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/ad/api.svc/FindAddress?Address1=' + @address1 + '&Address2=' + @address2 + '&City=' + @city + '&State=' + @state + '&PostalCode=' + @postalcode + '&BusinessName=' + @businessname + '&PhoneNumber=' + @phonenumber + '&FullName=' + @fullname + '&FirstName=' + @firstname + '&LastName=' + @lastname + '&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 Detective NodeJS Code Snippet

//Set backup and primary URL as necessary
var primaryUrl = 'https://trial.serviceobjects.com/ad/api.svc/FindAddress?Address1='+ Address1+'&Address2='+ Address2 + '&City=' + City +'&State=' + State +'&PostalCode=' + PostalCode + '&BusinessName=' + BusinessName + '&PhoneNumber=' + PhoneNumber + '&FullName=' + FullName + '&FirstName=' + FirstName + '&LastName=' + LastName +'&LicenseKey=' + LicenseKey;
var backupUrl = 'https://trial.serviceobjects.com/ad/api.svc/FindAddress?Address1='+ Address1+'&Address2='+ Address2 + '&City=' + City +'&State=' + State +'&PostalCode=' + PostalCode + '&BusinessName=' + BusinessName + '&PhoneNumber=' + PhoneNumber + '&FullName=' + FullName + '&FirstName=' + FirstName + '&LastName=' + LastName +'&LicenseKey=' + LicenseKey;
  
  
var req = http.get(primaryUrl, function(res) {
  
res.setEncoding('utf8');
res.on('data', function (results) {
  
    var parser = require('xml2js').Parser({explicitArray: false,ignoreAttrs: true});
    parser.parseString(results, function (err, outputs) {
        if (outputs.FixedAddressResponse.Error !=  null)
        {
            //Indicates a Fatal error has occured. If this happens, the logic will then failover to the backup url
            if (outputs.FixedAddressResponse.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;
        }
    });
});