3 # Sam Buca, indigo networks GmbH, 08/2007
5 # This script is a very basic perl-client to the SAMURAI service
6 # provided by sipgate (indigo networks GmbH) without any claim to
7 # completeness and without any warranty!
9 # The following code shows how to use the service to send fax-messages
10 # using a sipgate account.
11 # Note: This example does not check for the state / success of the
12 # sending process, so you will have to check that on the sipgate website.
13 # If you need such functionality in your code check the documentation for
14 # the provided XMLRPC-method "samurai.SessionStatusGet" !
18 use Frontier
::Client
; # needed for XMLRPC
19 use MIME
::Base64
; # we need to encode the PDF Base64
21 # declare some variables for later use:
23 my $NAME = "sipgateAPI-fax.pl";
24 my $VENDOR = "indigo networks GmbH";
33 # check the count of commandline parameters and show usage information
37 print "This script needs 4 parameters supplied on the commandline:\n";
39 print "parameter 1 -> the username (not SIPID) used to login to sipgate\n";
40 print "parameter 2 -> the password associated with the username\n";
41 print "parameter 3 -> the number to send the fax-message to\n";
42 print " (with national prefix, e.g. 4921xxxxxxxxx)\n";
43 print "parameter 4 -> the name of the PDF-file to send\n";
49 # define URL for XMLRPC:
51 $url = "https://$ARGV[0]:$ARGV[1]\@samurai.sipgate.net/RPC2";
53 # create an instance of the XMLRPC-Client:
55 $xmlrpc_client = Frontier
::Client
->new( 'url' => $url );
57 # identify the script to the server calling XMLRPC-method "samurai.ClientIdentify"
58 # providing client-name, -version and -vendor:
60 $args_identify = { ClientName
=> $NAME, ClientVersion
=> $VERSION, ClientVendor
=> $VENDOR };
62 $xmlrpc_result = $xmlrpc_client->call( "samurai.ClientIdentify", $args_identify );
64 # the check for success is not necessary in this case since the Frontier::Client module
65 # dies with an exception in case of a fault, but we do it for completeness:
67 if ($xmlrpc_result->{'StatusCode'} == 200) {
68 print "Successfully identified to the server!\n";
70 # we should never get here!
71 print "There was an error during identification to the server!\n";
74 # read the PDF file ...
76 open( PDF
, $ARGV[3] ) or die ("Cannot open PDF file!\n");
78 while ( my $line = <PDF
>) {
79 $content_binary .= $line;
83 # ... and encode it Base64:
85 $content_base64 = MIME
::Base64
::encode
($content_binary);
87 # create the input argument set for XMLRPC:
89 $args = { RemoteUri
=> "sip:$ARGV[2]\@sipgate.net", TOS
=> "fax", Content
=> $content_base64 };
91 # do the call and store the result / answer to $xmlrpc_result
93 $xmlrpc_result = $xmlrpc_client->call( "samurai.SessionInitiate", $args );
95 # again we do the check on success for completeness:
97 if ($xmlrpc_result->{'StatusCode'} == 200) {
98 print "Your request was successfully send to the server!\n";
99 print "The request was assigned the ID '".$xmlrpc_result->{'SessionID'}."'.\n";
100 print "You may use this ID to reference the request in other XMLRPC methods, e.g. 'samurai.SessionStatusGet' to obtain the status of the sending process.\n";
102 # we should never get here!
103 print "There was an error!\n";