#!/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);
# SendCharFax needs xmlns attribute set to the namespace
# (http://www.interfax.cc) to make the Interfax gateway happy.
my $method = SOAP::Data->name('SendCharFax') -> attr({xmlns =>
$NS});
# Interfax Authentication Parameters
$user = ""; # Your username goes here
$pass = ""; # Your password goes here
# Recipient's Fax Number
#
# Number is encoded as per details given at
# http://www.interfax.net/en/help/faxnumber_format.html
#
# and Appendix B:
# http://www.interfax.net/en/dev/webservice/reference.html#appendixb
$number = ""; # Destination fax number goes here
$data = ""; # Text to be faxed goes here
$type = "TXT";
# Set our SendCharFax parameters including our fax message (Data)
# and its file type of TXT for text.
my @params = ( SOAP::Data->name(Username => $user),
SOAP::Data->name(Password => $pass),
SOAP::Data->name(FaxNumber => $number),
SOAP::Data->name(Data => $data),
SOAP::Data->name(FileType => $type) );
# Dispatch and save result
# This actually does the transaction with the gateway server
my $result = $interfax->call($method => @params)->result;
# Hash of possible error messages
$error{'-112'} = "No valid recipients added";
$error{'-123'} = "No valid documents attached";
$error{'-150'} = "Internal system error";
$error{'-1002'} = "Number of types does not match " . "number of document sizes string";
$error{'-1003'} = "Authentication error";
$error{'-1005'} = "Transaction does not exist";
$error{'-1007'} = "Size value is not numeric or not greater than 0";
$error{'-1008'} = "Total size does not match filesdata length";
$error{'-1009'} = "Image not available";
# If the fax was submitted successfully, display its ID
# else, print out the error message for the result code
if($result > 0) {
print "Success. Fax submitted and given a transaction ID of $result.\n";
}
else {
if($error{$result}) {
$message = $error{"$result"};
}
else {
$message = "Unknown error returned from server.";
}
print "Error [$result] $message\n";
}
# end of file