Sales
Click for numbers
Welcome User Tools Developer Tools Prices Help Sign up Login
You are here: Home > Developer Tools > Fax Web Service > Samples > Perl - Retrieve fax status from Perl

Perl - Retrieve fax status from Perl using the FaxStatus method

Download the Perl file.

#!/usr/bin/perl -w
# Interfax Namespace
$NS = "http://www.interfax.cc";

# Interfax Gateway
$HOST = "http://ws.interfax.net/dfs.asmx";

# We require SOAP, obviously.
use SOAP::Lite;

# Instantiate a new SOAP instance,
#
# on_action is overloaded to fixup differences between SOAP::Lite
# (our Perl client) and Microsoft .NET namespace (the Interfax server)
# differences in SOAPAction header.
#
# SOAP::Lite (our client) defaults to http://www.interfax.cc#SendCharFax
# .NET (server) requires http://www.interfax.cc/SendCharFax (without the #)

my $interfax = SOAP::Lite -> uri($NS)
-> on_action( sub { join "/", @_ } )
-> proxy($HOST);

# FaxStatus needs the xmlns attribute set to the namespace
# ("http://www.interfax.cc") to make the Interfax gateway happy.

my $method = SOAP::Data->name('FaxStatus') -> attr({xmlns => $NS});

# FaxStatus web service paramaters as per the Interfax documentation at
# http://www.interfax.net/en/dev/webservice/reference.html#faxstatus

# Parameters

$user = ""; # Username goes here
$pass = ""; # Password goes here
$lastID = ""; # select which transactions to return, 9999999 for all
$maxItems = ""; # number of items to return, 99999999 for all

# Create an array of our web service parameters, properly casting
# the data into the correct types to keep everybody happy.

my @params = (
SOAP::Data->name("Username")->type(string => $user),
SOAP::Data->name("Password")->type(string => $pass),
SOAP::Data->name("LastTransactionID")->type(integer => $lastID),
SOAP::Data->name("MaxItems")->type(string => $maxItems)
);

# Subroutine to print error codes as per the Interfax Web Service documentation
# located at http://www.interfax.net/en/dev/webservice/reference.html#appendixa

sub errorMessage($) {
my %message;
my $code = shift;

$message{'-112'} = "No valid recipients added";
$message{'-123'} = "No valid documents attached";
$message{'-150'} = "Internal system error";
$message{'-1002'} = "Number of types does not match "
. "number of document sizes string";
$message{'-1003'} = "Authentication error";
$message{'-1005'} = "Transaction does not exist";
$message{'-1007'} = "Size value is not numeric or not greater than 0";
$message{'-1008'} = "Total size does not match filesdata length";
$message{'-1009'} = "Image not available";

if(exists $message{$code}) {
print "There was a problem retrieving FaxStatus results.\n";
print "Error code: $code, " . $message{$code} . "\n";
}
else {
print "Unknown error code: $code\n";
}
}

sub printFaxItems($) {
my $faxStatus = shift;

# As per the documentation, FaxStatus returns array of FaxItems, see
# http://www.interfax.net/en/dev/webservice/reference.html#faxstatus

my @faxItemFields = (
"TransactionID",
"SubmitTime",
"PostponeTime",
"CompletionTime",
"DestinationFax",
"RemoteCSID",
"PagesSent",
"Status",
"Duration",
"Subject",
"PagesSubmitted"
);

$responsePath = '//FaxStatusResponse';
$resultPath = '/FaxStatusResult';
$match = $faxStatus->match($responsePath . $resultPath . "/FaxItem");
@faxItems = $match->dataof;

print "The following FaxItems were returned:\n";
$count = 1;
foreach $faxItem (@faxItems) {
print "$count:\n";
foreach $element (@faxItemFields) {
printf "\t%-20s", $element . ":";
if(exists $faxItem->value->{$element}) {
print $faxItem->value->{$element} . "\n";
}
else {
print "No value returned.\n";
}
}
$count++;
print "\n";
}
}

# Perform the FaxStatus query and save the result

print "Interfax FaxStatus SOAP::Lite/Perl Example Program \n";
my $faxStatus = $interfax->call($method => @params);

# Did we have a SOAP fault?
unless ($faxStatus->fault()) {
# No, therefore we should have some return data
# See WSDL schema for more information about FaxStatusResponse elements

# Check if we received a FaxStatusResponse
$responsePath = '//FaxStatusResponse';
if($faxStatus->match($responsePath)) {

# Okay, we received a FaxStatusResponse
# Things are looking good.

# Did we get a ResultCode?
if($faxStatus->match($responsePath . "/ResultCode")) {
# Yes, we received a ResultCode
# Things are looking even better.

$resultCode = $faxStatus->valueof($responsePath . "/ResultCode");
unless($resultCode ne "0") {
# ResultCode is 0, success.
printFaxItems($faxStatus);
}
else {
# ResultCode is not 0, error.
errorMessage($resultCode);
}
}
else {
print "Server did not return a ResultCode, aborted\n";
print "Maybe there is a problem with the server?\n";
}
}
else {
print "Server did not return a FaxStatusResponse, aborted.\n";
print "Maybe there is a problem with the server?\n";
}
}
else {
print "There was a SOAP communications fault, aborted.\n";
print "Fault code: " . $faxStatus->faultcode() . "\n";
print "Fault string: " . $faxStatus->faultstring() . "\n";
}

# end of file




About | Contact | Privacy | Terms | Partners | Login | System Status

© Interfax Inc