#!/usr/bin/perl -w
#
# Testing script for LJ::TextMessage.pm.
# 
# Usage: run the script.  ;)  Make sure that LJ::TextMessage
# is either installed on your system or exists as LJ/TextMessage.pm
# from your current working directory.
# 
# Written by ntang@livejournal.com - send all comments/flames/etc. 
# there.  ;)

use LJ::TextMessage;
use Term::ReadKey;
use strict;

print "\n============================================\n";
print " Using LJ::TextMessage version $LJ::TextMessage::VERSION\n";
print "============================================\n";

my @providers = LJ::TextMessage::providers();

foreach my $p (@providers) {
    my $info = LJ::TextMessage::provider_info($p);
    print "Name: $info->{'name'} [ $p ]\n";
}

print "\nProvider to use:\n> ";
my $prov_name = ReadLine(0);
chomp($prov_name);
$prov_name = lc($prov_name);
print "\n";

my $foo = LJ::TextMessage::provider_info($prov_name);
print "Name: $foo->{'name'} [ $prov_name ]\n";
print "Notes: $foo->{'notes'}\n";
print "Limits: \n";
foreach my $limit (qw(from msg tot)) {
   print "  $limit: ", $foo->{"${limit}limit"}, "\n";
}
print "\n";

print "Number/name to send to:\n> ";
my $number = ReadLine(0);
chomp($number);
$number = lc($number);
print "\n";

print "Provider: $prov_name\nNumber: $number\n\n";

my $test_message = new LJ::TextMessage {
    'provider'		=> "$prov_name",
    'number'		=> "$number",
    'mailcommand'	=> '/usr/sbin/sendmail -t',
};

my @errors;

$test_message->send({
    'from'	=> 'lj_textmessage (a really long name)',
#    'from'	=> 'lj_textmessage',
    'message'	=> "Final Test: please reply to lj_textmessage\@livejournal.com.  If anything gets cut off please let me know.  This is a test of the LJ::TextMessage broadcast system, this is only a test.  Dum dum de dum dum dum..."
#    'message'	=> "Testing: please reply to lj_textmessage\@livejournal.com."
    }, \@errors);

if (@errors) {
  foreach my $error (@errors) {
    print "Error: $error \n"; 
  }
} else {
    print "Message sent!\n";
}
