- C#
- Java
- Php
- RoR
- Python
- ColdFusion
- VB
- TSQL
Telephone Verification C# 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/tv /TelephoneVerification.asmx/SendSMS?CountryCode=" & countrycode + "&PhoneNumber=" & phonenumber + "&Message=" & message + "&LicenseKey=" & licensekey Dim backupurl As String = "https://trial.serviceobjects.com/tv /TelephoneVerification.asmx/SendSMS?CountryCode=" & countrycode + "&PhoneNumber=" & phonenumber + "&Message=" & message + "&LicenseKey=" & licensekey Dim wsresponse As New TVResponse.TelephoneInfo() wsresponse = 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 End If If True Then wsresponse = httpGet(backupurl) End If If wsresponse.[Error] IsNot Nothing Then ProcessErrorResponse(wsresponse.[Error]) Else ProcessSuccessfulResponse(wsresponse) End If
Telephone Verification Java Rest Code Snippet
JSONObject results = RestClient(mainURL);
try {
if (ErrorMessages != null || (results.getJSONObject
("TelephoneInfo").has("Error") && results.getJSONObject("TelephoneInfo").
getJSONObject("Error").get("DescCode") == "3")) {
// BACKUP
results = RestClient(backupURL);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return results;
Telephone Verification PHP Rest Code Snippets
$URL = "https://trial.serviceobjects.com/tv/TelephoneVerification.asmx
/SendSMS?CountryCode=".urlencode($CountryCode)."&PhoneNumber=".urlencode
($PhoneNumber)."&Message=".urlencode($Message)."&LicenseKey=".urlencode
($LicenseKey);
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/tv/TelephoneVerification.asmx
/SendSMS?CountryCode=".urlencode($CountryCode)."&PhoneNumber=".urlencode
($PhoneNumber)."&Message=".urlencode($Message)."&LicenseKey=".urlencode
($LicenseKey);
// Get cURL resource
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL =>
$URL, CURLOPT_USERAGENT => 'Service Objects Telephone Verification'));
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)
{
echo "IN back up block";
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Telephone
Verification'));
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;
}
Telephone Verification RoR Rest Code Snippets
#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/tv
/TelephoneVerification.asmx/SendSMS?CountryCode=" + countrycode +
"&PhoneNumber=" + phonenumber + "&Message=" + message + "&LicenseKey=" +
licensekey)
backupURL = URI.encode("https://trial.serviceobjects.com/tv
/TelephoneVerification.asmx/SendSMS?CountryCode=" + countrycode +
"&PhoneNumber=" + phonenumber + "&Message=" + message + "&LicenseKey=" +
licensekey)
#These are set to access the hash that is returned
@tvresponse ="TelephoneInfo"
@tverror = "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
Telephone Verification Python Code Snippet
#Set the primary and backup URL as needed.
primaryURL = 'https://trial.serviceobjects.com/tv/TelephoneVerification.asmx
/SendSMS?'
backupURL = 'https://trial.serviceobjects.com/tv/TelephoneVerification.asmx
/SendSMS?'
#The Requests package allows the user to format the path parameters like
so instead of having to manually insert them into the URL
inputs = {'CountryCode':mCountryCode, 'PhoneNumber': mPhoneNumber,
'Message':mMessage, '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['TelephoneInfo']:
#loops through the response from the service and prints the values
to the screen.
for key, value in outputs['TelephoneInfo']['Error'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).pack()
else:
#Removes unnecessary text that was parsed in the xml response from
the service.
outputs['TelephoneInfo'].pop("@xmlns:xsi", None)
outputs['TelephoneInfo'].pop("@xmlns:xsd", None)
outputs['TelephoneInfo'].pop("@xmlns", None)
#Loops through and displays the results from with service. Does
not display ported info.
for key, value in outputs['TelephoneInfo'].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['TelephoneInfo']:
#loops through the response from the service and prints the
values to the screen.
for key, value in outputs['TelephoneInfo']['Error'].
iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).
pack()
else:
#Removes unnecessary text that was parsed in the xml response
from the service.
outputs['TelephoneInfo'].pop("@xmlns:xsi", None)
outputs['TelephoneInfo'].pop("@xmlns:xsd", None)
outputs['TelephoneInfo'].pop("@xmlns", None)
#Loops through and displays the results from with service.
Does not display ported info.
for key, value in outputs['TelephoneInfo'].iteritems():
Label(swin.window, text=str(key) + " : " + str(value)).
pack()
Telephone Verification ColdFusion Rest Snippet
<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq "" >
<cftry>
<cfset primaryURL = "https://trial.serviceobjects.com/tv
/TelephoneVerification.asmx/SendSMS?
CountryCode=#CountryCode#&PhoneNumber=#PhoneNumber#&Message=#Message#&Licen
seKey=#LicenseKey#">
<cfhttp url="#primaryURL#" method="get" result="response">
<cfset outputs = XmlParse(response.FileContent)>
<cfcatch >
<cftry>
<cfset backupURL = "https://trial.serviceobjects.com
/tv/TelephoneVerification.asmx/SendSMS?
CountryCode=#CountryCode#&PhoneNumber=#PhoneNumber#&Message=#Message#&Licen
seKey=#LicenseKey#">
<cfhttp url="#backupURL#" method="get" result="
response">
<cfset outputs = XmlParse(outputs.FileContent)
>
<cfcatch >
<cfoutput >
The Following Error Occured:
#cfcatch.message#
</cfoutput>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
</cfif>
Telephone Verification 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/tv /TelephoneVerification.asmx/SendSMS?CountryCode=" & countrycode + "&PhoneNumber=" & phonenumber + "&Message=" & message + "&LicenseKey=" & licensekey Dim backupurl As String = "https://trial.serviceobjects.com/tv /TelephoneVerification.asmx/SendSMS?CountryCode=" & countrycode + "&PhoneNumber=" & phonenumber + "&Message=" & message + "&LicenseKey=" & licensekey Dim wsresponse As New TVResponse.TelephoneInfo() wsresponse = 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 End If If True Then wsresponse = httpGet(backupurl) End If If wsresponse.[Error] IsNot Nothing Then ProcessErrorResponse(wsresponse.[Error]) Else ProcessSuccessfulResponse(wsresponse) End If
Telephone Verification TSQL Rest Code Snippet
BEGIN SET @sUrl = 'https://sws.serviceobjects.com/tv/TelephoneVerification. asmx/SendSMS?CountryCode=' + @countrycode + '&PhoneNumber=' + @phonenumber + '&Message=' + @message + '&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/tv /TelephoneVerification.asmx/SendSMS?CountryCode=' + @countrycode + '&PhoneNumber=' + @phonenumber + '&Message=' + @message + '&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