#!/usr/bin/perl ################################################################################## ## BeVocal Sample Code # ## (C) Copyright BeVocal, Inc. 2003, All rights reserved. # ## # ## This Sample Code is provided for your reference purposes, and carries no # ## warranty whatsoever. Use of this code is restricted to use in connection # ## with the BeVocal Cafe developer's program. # ## # ## BeVocal disclaims and excludes any and all warranties of merchantability, # ## title and fitness for a particular purpose. BeVocal does not warrant that the # ## software will satisfy your requirements, or that the software is without # ## defect or error. You are using the software at your own risk. # ## # ## This sample uses the Location Service to get a ZIP code from a phone number. # ## # ## Example usage (when the requestID of the call is "12345": # ## phoneToZIP.pl 6506411465 -c production # ## # ## This script uses a store for security keys. See its documentation in # ## http://cafe.bevocal.com/resources/voicexml_samples/keyRing.pl # ################################################################################## #use SOAP::Lite +trace => 'debug'; use SOAP::Lite; use strict; require "../keyRing.pl"; # access keys are found here. # Define global variables my $soapLocationURL = 'LocationInfoService_v1/services/LocationInfoService_v1'; my $soapURL = ''; my $accessSystem = ''; my $orgId = ''; my $appId = ''; my $soapServer = ''; my $myAccessKey = ''; my $customer = "production"; # default to using Production my $phone = ''; #-------------------------------------------------------------------# # getUSZipCodeFromPhone(phone) # # # # input: phone number (string) # # output: the ZIP code associated with that phone number (string) # # errors: if there is a SOAP fault, or a transport error, # # the perl process will die with an error message. # #-------------------------------------------------------------------# sub getUSZipCodeFromPhone { my ($phone)= @_; # construct URI of the SOAP Location Service $soapURL = "http://$soapServer/$soapLocationURL"; # Setup a pointer to the Location Service my $locationService = SOAP::Lite ->proxy($soapURL) ->uri('http://www.bevocal.com/soap/services/') ->on_fault( sub { my($locationService, $res) = @_; die ref $res ? $res->faultstring : $locationService->transport->status, "\n"; }); # To call this service, we need an Access Key, # passed in via the SOAP header, as per the W3C. my $head = SOAP::Header->name( platformServicesSessionID => $myAccessKey); # Call the Location Service. # If there's a problem, print out fault or transport info and die. my $res1 = $locationService->getUSZipCodeFromPhone( $head, SOAP::Data->type('string')->name(phone => $phone)); return $res1->result(); } # ------------------------------------------------------------------------- sub usage { print "ERROR: $_[0]\n\n"; print "USAGE: phoneToZIP.pl [-c ]\n"; print "\n"; print " Converts a phone number to a ZIP code, and prints it out on the console.\n"; print " If is not specified, 'production' will be used.\n"; exit(1); } # ---------------------------------------------------------------------- sub processArgs { shift(@_); # phone number while ($#_ >= 0) { if ($_[0] eq '-c') { shift(@_); $customer = $_[0]; } else { usage("Incorrect parameter given: '" . $_[0] . "'"); } shift(@_); } # get the AccessKey, based on the customer specified on the command line ($accessSystem, $orgId, $appId, $soapServer, $myAccessKey) = getProviderData($customer); if ($accessSystem eq "NoProviderFound") { usage("No valid SOAP Provider given"); } $phone = $ARGV[0]; if ($phone eq "") { usage("You must provide a phone number to lookup."); } } #-------------------------------------------------------------# # main -- pass in Phone, get back ZIP and print it out # #-------------------------------------------------------------# processArgs(@ARGV); print "The ZIP code for ", $phone, " is ", getUSZipCodeFromPhone($phone), "."; exit(0);