Phone Exchange C# Rest Code Snippet

PE2Response result = null;
string mainURL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber="+ phoneNumber + "&LicenseKey=" + licenseKey;
string backupURL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber=" + phoneNumber + "&LicenseKey=" + licenseKey;;
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;
    }
}

Phone Exchange Java Rest Code Snippet

String MainURL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber="+ phoneNumber + "&LicenseKey=" + licenseKey;
String BackupURL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber="+ phoneNumber + "&LicenseKey=" + licenseKey;
ExchangeInfoResponse result = GetExchangeInfoResponse(MainURL);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if(ErrorMessages!=null || (result.Error != null && result.Error.TypeCode == "3" ))
{   //BACKUP URL
    result = GetExchangeInfoResponse(BackupURL);
}
return result;

Phone Exchange PHP Rest Code Snippet

$URL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber=".urlencode($PhoneNumber)."&LicenseKey=".urlencode($LicenseKey);
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber=".urlencode($PhoneNumber)."&LicenseKey=".urlencode($LicenseKey);
  
    // Get cURL resource
    $curl = curl_init();
    curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Phone Exchange 2'));
    curl_setopt($curl, CURLOPT_TIMEOUT, 5); //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 Phone Exchange 2'));
        curl_setopt($curl, CURLOPT_TIMEOUT, 5); //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;
        }
      
      
    }
curl_close($curl);

Phone Exchange RoR Rest Code Snippet

#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/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=" + phonenumber + "&LicenseKey=" + licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=" + phonenumber + "&LicenseKey=" + licensekey)
#These are set to access the hash that is returned
@pe2response ="ExchangeInfoResponse"
@pe2results = "ExchangeInfoResults"
@pe2info = "ExchangeInfo"
@pe2portedinfo = "PortedInfo"
@pe2error = "Error"
  #Begins the call the RESTful web service
begin
  response = HTTParty.get(primaryURL, timeout: default_timeout)
    
  #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 = response
            @displaydata = {"Error" => "A Big Error Occured"}
        end
end

Phone Exchange Python Rest Code Snippet

primaryURL = 'https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?'
backupURL = 'https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?'
#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, '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['ExchangeInfoResponse']:
        #loops through the response from the service and prints the values to the screen.
        for key, value in outputs['ExchangeInfoResponse']['Error'].iteritems():
            Label(swin.window, text=str(key) + " : " + str(value)).pack()
    #Loops through and prints Valid results from the service
    else:
        for key, value in outputs['ExchangeInfoResponse']['ExchangeInfoResults']['ExchangeInfo'].iteritems():
            if key != 'PortedInfo':
                Label(swin.window, text=str(key) + " : " + str(value)).pack()
        #If Ported info is available this will print the results under a heading.
        if 'PortedInfo' in outputs['ExchangeInfoResponse']['ExchangeInfoResults']['ExchangeInfo']:
            Label(swin.window, font="bold", text="Ported Info").pack()
            for key, value in outputs['ExchangeInfoResponse']['ExchangeInfoResults']['ExchangeInfo']['PortedInfo'].iteritems():
                Label(swin.window, text=str(key) + " : " + str(value)).pack()
#Attempts to use the backup URL 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)
        #checks the output for Errors and displays the info accordingly
        if 'Error' in outputs['ValidateEmailResponse']:
            #loops through the response from the service and prints the values to the screen.
            for key, value in outputs['ValidateEmailResponse']['Error'].iteritems():
                Label(swin.window, text=str(key) + " : " + str(value)).pack()
        else:
            for key, value in outputs['ValidateEmailResponse']['ValidateEmailInfo'].iteritems():
                Label(swin.window, text=str(key) + " : " + str(value)).pack()

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/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=#PhoneNumber#&LicenseKey=#LicenseKey#">
        <cfhttp url="#primaryURL#" method="get" result="response">
        <cfset outputs = XmlParse(response.FileContent)>
    <cfcatch >
        <cftry>
            <cfset backupURL = "https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=#PhoneNumber#&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>

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 = "https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=" & phonenumber + "&LicenseKey=" & licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/PE2/web.svc/xml/GetExchangeInfo?PhoneNumber=" & phonenumber + "&LicenseKey=" & licensekey
Dim wsresponse As PE2Response.ExchangeInfoResponse = 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

Phone Exchange 2 TSQL Rest Code Snippet

BEGIN
    SET @sUrl = 'https://sws.serviceobjects.com/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber=' + @phonenumber + '&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/pe2/web.svc/xml/GetExchangeInfo?PhoneNumber=' + @phonenumber + '&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