SMS::Send::US::Ipipi - An SMS::Send driver for the ipipi.com website


SMS-Send-US-Ipipi documentation Contained in the SMS-Send-US-Ipipi distribution.

Index


Code Index:

NAME

Top

SMS::Send::US::Ipipi - An SMS::Send driver for the ipipi.com website

VERSION

Top

Version 0.03

SYNOPSIS

Top

  # Get the sender and login
  my $sender = SMS::Send->new('US::Ipipi',
  	_login    => 'username',
  	_password => 'password',
  	);

  my $sent = $sender->send_sms(
  	text => 'Messages have a limit of 160 chars',
  	to   => '212-555-1212',
  	);

  # Did it send?
  if ( $sent ) {
  	print "Sent test message\n";
  } else {
  	print "Test message failed\n";
  }

DESCRIPTION

Top

SMS::Send::US::Ipipi is a SMS::Send driver that delivers messages via the http://ipipi.com website.

Preparing to Use This Driver

You need to sign up for an account at http://ipipi.com to be able to use this driver.

Disclaimer

Using this driver may cost you money. YOU HAVE BEEN WARNED

METHODS

Top

new

  # Create a new sender using this driver
  my $sender = SMS::Send->new(
  	_login    => 'username',
  	_password => 'password',
  	);

The new constructor takes two parameters, which should be passed through from the SMS::Send constructor.

The params are driver-specific for now, until SMS::Send adds a standard set of params for specifying the login and password.

_login

The _login param should be your ipipi.com login.

_password

The _password param should be your ipipi.com password.

Returns a new SMS::Send::US::Ipipi object, or dies on error.

send_sms

  This method is actually called by SMS::Send when you call send_sms on it.

  my $sent = $sender->send_sms(
  	text => 'Messages have a limit of 160 chars',
  	to   => '212-555-1212',
  	);

AUTHOR

Top

Andrew Moore, <andrew.moore at liblime.com>

BUGS

Top

Please report any bugs or feature requests to bug-sms-send-ipipi at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-Send-US-Ipipi. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc SMS::Send::US::Ipipi

You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=SMS-Send-US-Ipipi

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/SMS-Send-US-Ipipi

* CPAN Ratings

http://cpanratings.perl.org/d/SMS-Send-US-Ipipi

* Search CPAN

http://search.cpan.org/dist/SMS-Send-US-Ipipi

ACKNOWLEDGEMENTS

Top

Thanks to Adam Kennedy <adamk@cpan.org>, http://ali.as/ for writing SMS::Send and for SMS::Send::AU::MyVodafone which I copied for this module.

COPYRIGHT & LICENSE

Top


SMS-Send-US-Ipipi documentation Contained in the SMS-Send-US-Ipipi distribution.
package SMS::Send::US::Ipipi;
use warnings;
use strict;

our $VERSION = '0.03';

use base 'SMS::Send::Driver';
use LWP::UserAgent ();


sub new {
	my $class  = shift;
	my %params = @_;

	# Get the login
	my $login    = $class->_LOGIN   ( delete $params{_login}    );
	my $password = $class->_PASSWORD( delete $params{_password} );

        # Create our LWP::UserAgent object
        my $ua = LWP::UserAgent->new;

	# Create the object, saving any private params for later
	my $self = bless {
                          ua       => $ua,
                          login    => $login,
                          password => $password,
                          private  => \%params,
                          
                          # State variables
                          logged_in => '',
                      }, $class;

	$self;
}

sub send_sms {
    my $self   = shift;
    my %params = @_;
    
    # Get the message and destination
    my $message   = $self->_MESSAGE( delete $params{text} );
    my $recipient = $self->_TO     ( delete $params{to}   );

    my $response = $self->{'ua'}->post( 'http://service.ipipi.com/wsrv/api.asmx/xmlSendSMS',
                                       { Username => $self->{'login'},
                                         Password => $self->{'password'},
                                         SendTo   => $recipient,
                                         Text     => $message,
                                         Encoding => 7, }, );
    
    
    if ( not $response->is_success() ) {
        Carp::croak( 'HTTP request returned failure when sending SMS request: ' . $response->status_line() );
    }

    # warn $response->content();
    
    # Fire-and-forget, we don't know for sure.
    return 1;
}


#####################################################################
# Support Functions

sub _LOGIN {
	my $class  = ref $_[0] ? ref shift : shift;
	my $login = shift;
	unless ( defined $login and ! ref $login and length $login ) {
		Carp::croak('Did not provide a login');
	}
	return $login;
}

sub _PASSWORD {
	my $class    = ref $_[0] ? ref shift : shift;
	my $password = shift;
	unless ( defined $password and ! ref $password and length $password ) {
		Carp::croak("Did not provide a password");
	}
	return $password;
}

sub _MESSAGE {
	my $class   = ref $_[0] ? ref shift : shift;
	my $message = shift;
	unless ( length($message) <= 160 ) {
		Carp::croak("Message length limit is 160 characters");
	}
	return $message;
}

sub _TO {
	my $class = ref $_[0] ? ref shift : shift;
	my $to    = shift;

        # strip out non-numerals
        $to =~ s/[^\d]//g;

	# International numbers need their + removed
	if ( $to =~ s/^\+// ) {
		return $to;
	}
        
        if ( $to !~ /^1/ ) {
            $to = '1' . $to;
        }
        
 	# US numbers should be 11 digits, starting with "1"
 	unless ( $to =~ /^1\d{10}$/ ) {
 		Carp::croak("Regional number is not a valid US mobile phone number");
 	}

	return $to;
}

1;

1; # End of SMS::Send::US::Ipipi