WWW::SMS - sends SMS using service provided by free websites
use WWW::SMS; my $sms = WWW::SMS->new( '39', #international prefix '333', #operator prefix '1234567', #phone number 'This is a test.', #message text username => 'abcde', #optional parameters passwd => 'edcba' #in hash fashion );
#or now even just my $sms = WWW::SMS->new($whole_number, $smstext);
for ( $sms->gateways() ) { #for every compatible gateway if ($sms->send( $_ ) { #try to send sms last; #until it succeds } else { print $WWW::SMS:Error; #here the error } }
WWW::SMS a Perl framework for sending free SMSs over the web.
A new WWW::SMS object must be created with the new method. Once created you can send it through one of the available submodules.
INTPREFIX
is the international prefix:
some gateways just don't use the international prefix,
but put something in here anyway.
OPPREFIX
is the operator prefix
PHONE_NUMBER
not much to say
WHOLE_NUMBER
the alternative constructor use the
the whole number of your cellphone: it includes international prefix
and operator prefix. It relies on the database in Telephone::Number
to split your number in its 3 basic parts.
So if unsure just use the ``three-part-phone-number'' constructor.
MESSAGETEXT
even here not much to say. Submodules are going to cut
the SMS to the maximum allowed length by the operator. You can check
anyway the maximum length directly looking for the MAXLENGTH constant
in submodules.
OPTIONS
are passed in a hash fashion. The useful ones to set include
proxy
your HTTP proxy
cookie_jar
The file where to store cookies. If not set, every cookie goes
in the file ``lwpcookies.txt'' in your working directory.
username
and passwd
Used by registration based gateways
Other parameters may be required by specific submodules.
GATEWAY
)$sms
using GATEWAY
: returns 1 if succesfull, 0 if
there are errors. The last error is in the $WWW::SMS::Error
variable.
GATEWAY
the gateway you wish to use for sending the SMS: must be a scalar.
gateways([OPTIONS])
WWW::SMS->gateways(); #returns every available gateway
$sms->gateways(); #returns just the gateways that can send $sms
#compatible gateways sorted by reliability $sms->gateways(sorted => 'reliability');
So, now you got WWW::SMS but what's next? Well, all that's cool about it resides in submodules. A submodule got to do the dirty work of GETting and POSTing webpages. How to write a submodule then? There a few points to observe:
MAXLENGTH
to what is the maximum length
of SMS the gateway you are scripting for allow.
@PREFIXES
got to be an array of Telephone::Number
objects.
Telephone::Number
->new takes 3 parameters: each one can be a scalar
or an array reference.
Each scalar or element of referenced arrays is a regular expression.
Code will check for the phone number to match at least one of the regexp
for each of intpref, prefix and phone_number. If you don't have regexp
for one of these fields just give undef to Telephone::Number
->new.
Take a look at other submodules to better make up your mind.
$WWW::SMS::Error
to something useful and include the step number in it, so debugging will
be easier. Then return 0.
If everything goes alright just return 1.
Copyright 2001 Giulio Motta.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.