- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- TSQL
GeoPhone C# Rest Code Snippet
string mainURL = WEB_SERVICE_PRIMARY_URL + phonenumber + "/" + licenseKey + "?format=json";
string backupURL = WEB_SERVICE_BACKUP_URL + phonenumber + "/" + licenseKey + "?format=json";
GPResponse result = null;
try
{
result = HttpGet(mainURL);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if (result == null || (result.PhoneInfo.Error != null && result.PhoneInfo.Error.Number == "3"))
{
return HttpGet(backupURL);
}
else
{
return result;
}
}
catch (Exception)
{ //ERROR IN MAIN URL - USING BACKUP
return HttpGet(backupURL);
}
}
GeoPhone Java Rest Code Snippet
String MainURL = this.MainUrl + phoneNumber + "/" + licensekey + "?format=json";
String BackupURL = this.BackupUrl + phoneNumber + "/" + licensekey + "?format=json";
PhoneInfo_V2Response result = GetPhoneInfo_V2Response(MainURL);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if (ErrorMessages != null || (result.PhoneInfo.Error != null && result.PhoneInfo.Error.Number == "3")) {
// BACKUP
result = GetPhoneInfo_V2Response(BackupURL);
}
return result;
GeoPhone PHP Rest Code Snippet
$URL = "https://trial.serviceobjects.com/rest/GP/api.svc/PhoneInfo/V2/".rawurlencode($PhoneNumber)."/".rawurlencode($LicenseKey)."?format=json";
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/rest/GP/api.svc/PhoneInfo/V2/".rawurlencode($PhoneNumber)."/".rawurlencode($LicenseKey)."?format=json";
echo($URL);
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Lead Validation'));
//Https peer certification validation turned off
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT ); //timeout in seconds
// Send the request & save response to $resp
$resp = curl_exec($curl);
$status = curl_getinfo($curl);
if(isset($status) && $status['http_code'] != 200){
//var_dump($status);
}
$decoded = json_decode($resp, TRUE);
// Close request to clear up some resources
if($resp == false || (isset ($decoded['Error']) != NULL && $decoded['Error']['TypeCode'] == 3))
{
$curl2 = curl_init();
curl_setopt_array($curl2, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Email Validation 3'));
//Https peer certification validation turned off
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl2, CURLOPT_CONNECTTIMEOUT_MS, $TIMEOUT ); //timeout in seconds
// Send the request & save response to $resp
$resp = curl_exec($curl2);
echo($resp);
$decoded = json_decode($resp, TRUE);
if($resp == false)
{
echo "<b> Both rest calls failed </b>";
curl_close($curl2);
return;
}
}
curl_close($curl);
GeoPhone RoR Rest Code Snippet
phonenumber = @request.phonenumber
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/gp/GeoPhone.asmx/GetExchangeInfo?PhoneNumber=" + phonenumber + "&LicenseKey=" + licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/gp/GeoPhone.asmx/GetExchangeInfo?PhoneNumber=" + phonenumber + "&LicenseKey=" + licensekey)
#These are set to access the hash that is returned
@gpresult ="PhoneInfo"
@gpproviders = "Providers"
@gpprovider = "Provider"
@gperror = "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" => "A Big Error Occured"}
end
end
GeoPhone Python Rest Code Snippet
primaryURL = 'https://trial.serviceobjects.com/gp/GeoPhone.asmx/GetExchangeInfo?'
backupURL = 'https://trial.serviceobjects.com/gp/GeoPhone.asmx/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['PhoneInfo']:
#loops through the response from the service and prints the values to the screen.
for key, value in outputs['PhoneInfo']['Error'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
else:
#Loops through the results printed from the service and displays them to the screen
for key, value in outputs['PhoneInfo']['Providers']['Provider'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
#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)
#checks the output for Errors and displays the info accordingly
if 'Error' in outputs['PhoneInfo']:
#loops through the response from the service and prints the values to the screen.
for key, value in outputs['PhoneInfo']['Error'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
else:
if 'Providers' in outputs['PhoneInfo']:
#Loops through the results printed from the service and displays them to the screen
for key, value in outputs['PhoneInfo']['Providers']['Provider'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
GeoPhone ColdFusion Rest Code Snippet
<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
<cftry>
<cfset primaryURL = "https://trial.serviceobjects.com/gp/GeoPhone.asmx/GetPhoneInfo_V2?PhoneNumber=#PhoneNumber#&LicenseKey=#LicenseKey#">
<cfhttp url="#primaryURL#" method="get" result="response">
<cfset outputs = XmlParse(response.FileContent)>
<cfcatch >
<cftry>
<cfset backupURL = "https://trial.serviceobjects.com/ev3/api.svc/ValidateEmailFull?EmailAddress=#EmailAddress#&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>
GeoPhone 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/gp/GeoPhone.asmx/GetPhoneInfo_V2?PhoneNumber=" & phonenumber + "&LicenseKey=" & licensekey
Dim backupurl As String = "https://trial.serviceobjects.com/gp/GeoPhone.asmx/GetPhoneInfo_V2?PhoneNumber=" & phonenumber + "&LicenseKey=" & licensekey
Dim wsresponse As GPResponse.PhoneInfo_V2 = 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].Number = "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
GeoPhone TSQL Rest Code Snippet
BEGIN
SET @sUrl = 'https://sws.serviceobjects.com/gp/GeoPhone.asmx/GetPhoneInfo_V2?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/gp/GeoPhone.asmx/GetPhoneInfo_V2?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