Phone Exchange C# Rest Code Snippet

string mainURL = "https://trial.serviceobjects.com/GPPL2/api.svc/PhoneInfo/" + 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}).",
        response.StatusCode,
        response.StatusDescription));
    //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
}
else
{
    //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
else{
}
    //DOTS GeoPhone Plus 2 Errors
      
}

Phone Exchange PHP Rest Code Snippet

$URL = "https://trial.serviceobjects.com/GPPL2/api.svc/PhoneInfo/".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)
{
    if(is_array($val))
    {
        echo "GeoPhone Plus 2 Results";
    }
    else
    {
        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 = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=" + phonenumber + "&TestType=" + testtype + "&LicenseKey=" + licensekey
     backupURL = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=" + phonenumber + "&TestType=" + testtype + "&LicenseKey=" + licensekey
      
       #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 HTTParty::Error => 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 HTTParty::Error => e
           end
     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

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 = 'https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?'
backupURL = 'https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?'
#The
 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
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 use the backupURL if the call to 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 message if the primary and backup urls failed
    except:
        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 ""  >
    <cftry>
        <cfset primaryURL = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=#PhoneNumber#&TestType=#TestType#&LicenseKey=#LicenseKey#">
        <cfhttp url="#primaryURL#" method="get" result="response">
        <cfset outputs = XmlParse(response.FileContent)>
    <cfcatch >
        <cftry>
            <cfset backupURL = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=#PhoneNumber#&TestType=#TestType#&LicenseKey=#LicenseKey#">
            <cfhttp url="#backupURL#" method="get" result="response">
            <cfset outputs = XmlParse(outputs.FileContent)>              
            <cfcatch >
                <cfoutput >
                    The Following Error Occured: #response.StatusCode#
                </cfoutput>
            </cfcatch>
        </cftry>
    </cfcatch>
    </cftry>
</cfif>

Phone Exchange 2 VB Rest Code Snippet

Try
    'encodes the URLs for the get Call. Set the primary and back urls as necessary
    Dim primaryurl As String = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=" & phonenumber + "&TestType=" + testtype + "&LicenseKey=" & licensekey
    Dim backupurl As String = "https://trial.serviceobjects.com/GPPL2/api.svc/GetPhoneInfo?PhoneNumber=" & 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
        ProcessErrorResponse(wsresponse.[Error])
    Else
        ProcessSuccessfulResponse(wsresponse)
    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

BEGIN
    SET @sUrl = 'https://sws.serviceobjects.com/gppl2/api.svc/GetPhoneInfo?PhoneNumber=' + @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
    BEGIN
        SET @sBackupUrl = 'https://swsbackup.serviceobjects.com/gppl2/api.svc/GetPhoneInfo?PhoneNumber=' + @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
    END
END