Phone Exchange C# Rest Code Snippet

string mainURL = "" + email + "/" + testtype + "/" + licenseKey + "?format=json";
GPPL2Response result = null;
HttpWebRequest request = WebRequest.Create(mainURL ) as HttpWebRequest;
request.Timeout = 5000;//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}).",
    //parse response
    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GPPL2Response));
    object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
    result = objResponse as GPPL2Response;
//processing result
if (result.error == null)
    //process result
    //process error

Phone Exchange Java Rest Code Snippet

GPPL2Response.Error error = null;
GPPL2Response.PhoneInfo info = null;
GPPL2RestClient GPPL2Client = new GPPL2RestClient();
GPPL2Response result = GPPL2Client.ValidateLead(phoneNumber, testType,  licensekey);
if (result != null) {
    error = result.error;
    info = result.PhoneInfo;
//Process Results
if (error == null) {
    //DOTS GeoPhone Plus 2 Results
//Process Errors
    //DOTS GeoPhone Plus 2 Errors

Phone Exchange PHP Rest Code Snippet

$URL = "".rawurlencode($PhoneNumber)."/".rawurlencode($TestType)."/".rawurlencode($LicenseKey)."?format=json";
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects GeoPhone Plus 2'));
curl_setopt($curl, CURLOPT_TIMEOUT, 5); //timeout in seconds
// Send the request & save response to $resp
$resp = curl_exec($curl);
$jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($resp, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val)
        echo "GeoPhone Plus 2 Results";
        echo "$key";
        echo "$val";

Phone Exchange RoR Rest Code Snippet

#This sets the default timeout for HTTParty get operation. This must be set in order to use the gem
     default_timeout = 10
     phonenumber = @request.phonenumber
     testtype = @request.testtype
     licensekey = @request.licensekey
     #These are set to access the hash that is returned
     @gppl2result ="PhoneInfoResponse"
     @gppl2info = "PhoneInfo"
     @gppl2providers = "Providers"
     @gppl2provider = "Provider"
     @gppl2contacts = "Contacts"
     @gppl2contact = "Contact"
     @gppl2error = "Error"
     #Set Primary and Backup URLs as needed. This method encodes and standardizes the URI to pass to the REST service.
     primaryURL = "" + phonenumber + "&TestType=" + testtype + "&LicenseKey=" + licensekey
     backupURL = "" + phonenumber + "&TestType=" + testtype + "&LicenseKey=" + licensekey
       #Begins the call the RESTful web service
       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
      rescue HTTParty::Error => e
         #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
         #If the backup url railed this will raise an error and display the
         #error message returned from the HTTParty gem.
           rescue HTTParty::Error => e
     #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

Phone Exchange Python Rest Code Snippet

mPhoneNumber = PhoneNumber.get()
if mPhoneNumber is None or mPhoneNumber == "":
    mPhoneNumber = " "
mTestType = TestType.get()
if mTestType is None or mTestType == "":
    mTestType = " "
mLicenseKey = LicenseKey.get()
if mLicenseKey is None or mLicenseKey == "":
    mLicenseKey = " "
primaryURL = ''
backupURL = ''
 Requests package allows the user to format the path parameters like so
instead of having to manually insert them into the URL
inputs = {'PhoneNumber':mPhoneNumber, 'TestType':mTestType, 'LicenseKey': mLicenseKey}
label = 0
    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 use the backupURL if the call to the primary URL failed
        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 message if the primary and backup urls failed
        Label(swin.window, text='Error').pack()
        print (result.content)

Phone Exchange 2 ColdFusion Rest Code Snippet

<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq ""  >
        <cfset primaryURL = "">
        <cfhttp url="#primaryURL#" method="get" result="response">
        <cfset outputs = XmlParse(response.FileContent)>
    <cfcatch >
            <cfset backupURL = "">
            <cfhttp url="#backupURL#" method="get" result="response">
            <cfset outputs = XmlParse(outputs.FileContent)>              
            <cfcatch >
                <cfoutput >
                    The Following Error Occured: #response.StatusCode#

Phone Exchange 2 VB Rest Code Snippet

    'encodes the URLs for the get Call. Set the primary and back urls as necessary
    Dim primaryurl As String = "" & phonenumber + "&TestType=" + testtype + "&LicenseKey=" & licensekey
    Dim backupurl As String = "" & phonenumber + "&TestType=" + testtype + "&LicenseKey=" & licensekey
    Dim wsresponse As GPPL2Response.PhoneInfoResponse = 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
    End If
Catch ex As Exception
    'Displays the relevant error mesasge if both backup and primary urls failed.
    StatusLabel.Text = ex.Message
    StatusLabel.Visible = True
End Try

Phone Exchange 2 TSQL Rest Code Snippet

    SET @sUrl = '' + @phonenumber + '&TestType=' + @testtype + '&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
        SET @sBackupUrl = '' + @phonenumber + '&TestType=' + @testtype + '&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