[Bio] / FigKernelPackages / Tracer.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.58, Thu Jun 29 19:02:48 2006 UTC revision 1.59, Sat Jul 1 03:14:09 2006 UTC
# Line 31  Line 31 
31      use File::Basename;      use File::Basename;
32      use File::Path;      use File::Path;
33      use File::stat;      use File::stat;
34        use LWP::UserAgent;
35    
36  =head1 Tracing and Debugging Helpers  =head1 Tracing and Debugging Helpers
37    
# Line 2048  Line 2049 
2049      }      }
2050  }  }
2051    
2052    =head3 SendSMS
2053    
2054    C<< my $msgID = Tracer::SendSMS($phoneNumber, $msg); >>
2055    
2056    Send a text message to a phone number using Clickatell. The FIG_Config file must contain the
2057    user name, password, and API ID for the relevant account in the hash reference variable
2058    I<$FIG_Config::phone>, using the keys C<user>, C<password>, and C<api_id>. For
2059    example, if the user name is C<BruceTheHumanPet>, the password is C<silly>, and the API ID
2060    is C<2561022>, then the FIG_Config file must contain
2061    
2062        $phone =  { user => 'BruceTheHumanPet',
2063                    password => 'silly',
2064                    api_id => '2561022' };
2065    
2066    The original purpose of this method was to insure Bruce would be notified immediately when the
2067    Sprout Load terminates. Care should be taken if you do not wish Bruce to be notified immediately
2068    when you call this method.
2069    
2070    The message ID will be returned if successful, and C<undef> if an error occurs.
2071    
2072    =over 4
2073    
2074    =item phoneNumber
2075    
2076    Phone number to receive the message, in international format. A United States phone number
2077    would be prefixed by "1". A British phone number would be prefixed by "44".
2078    
2079    =item msg
2080    
2081    Message to send to the specified phone.
2082    
2083    =item RETURN
2084    
2085    Returns the message ID if successful, and C<undef> if the message could not be sent.
2086    
2087    =back
2088    
2089    =cut
2090    
2091    sub SendSMS {
2092        # Get the parameters.
2093        my ($phoneNumber, $msg) = @_;
2094        # Declare the return variable. If we do not change it, C<undef> will be returned.
2095        my $retVal;
2096        # Only proceed if we have phone support.
2097        if (! defined $FIG_Config::phone) {
2098            Trace("Phone support not present in FIG_Config.") if T(1);
2099        } else {
2100            # Get the phone data.
2101            my $parms = $FIG_Config::phone;
2102            # Get the Clickatell URL.
2103            my $url = "http://api.clickatell.com/http/";
2104            # Create the user agent.
2105            my $ua = LWP::UserAgent->new;
2106            # Request a Clickatell session.
2107            my $resp = $ua->post("$url/sendmsg", { user => $parms->{user},
2108                                         password => $parms->{password},
2109                                         api_id => $parms->{api_id},
2110                                         to => $phoneNumber,
2111                                         text => $msg});
2112            # Check for an error.
2113            if (! $resp->is_success) {
2114                Trace("Alert failed.") if T(1);
2115            } else {
2116                # Get the message ID.
2117                my $rstring = $resp->content;
2118                if ($rstring =~ /^ID:\s+(.*)$/) {
2119                    $retVal = $1;
2120                } else {
2121                    Trace("Phone attempt failed with $rstring") if T(1);
2122                }
2123            }
2124        }
2125        # Return the result.
2126        return $retVal;
2127    }
2128    
2129  =head3 CommaFormat  =head3 CommaFormat
2130    
2131  C<< my $formatted = Tracer::CommaFormat($number); >>  C<< my $formatted = Tracer::CommaFormat($number); >>

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.59

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3