| File: | C4/SMS.pm |
| Coverage: | 41.9% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | package C4::SMS; | |||||
| 2 | ||||||
| 3 | # This file is part of Koha. | |||||
| 4 | # | |||||
| 5 | # Koha is free software; you can redistribute it and/or modify it under the | |||||
| 6 | # terms of the GNU General Public License as published by the Free Software | |||||
| 7 | # Foundation; either version 2 of the License, or (at your option) any later | |||||
| 8 | # version. | |||||
| 9 | # | |||||
| 10 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | |||||
| 11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | |||||
| 12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |||||
| 13 | # | |||||
| 14 | # You should have received a copy of the GNU General Public License along with | |||||
| 15 | # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | |||||
| 16 | # Suite 330, Boston, MA 02111-1307 USA | |||||
| 17 | ||||||
| 18 - 31 | =head1 NAME
C4::SMS - send SMS messages
=head1 SYNOPSIS
my $success = C4::SMS->send_sms( message => 'This is my text message',
destination => '212-555-1212' );
=head1 DESCRIPTION
=cut | |||||
| 32 | ||||||
| 33 | 15 15 15 | 544 136 673 | use strict; | |||
| 34 | 15 15 15 | 206 104 807 | use warnings; | |||
| 35 | ||||||
| 36 | 15 15 15 | 326 72 255 | use C4::Context; | |||
| 37 | ||||||
| 38 | 15 15 15 | 111 98 957 | use vars qw( $VERSION ); | |||
| 39 | ||||||
| 40 | BEGIN { | |||||
| 41 | 15 | 4106 | $VERSION = 0.03; | |||
| 42 | } | |||||
| 43 | ||||||
| 44 - 46 | =head1 METHODS =cut | |||||
| 47 | ||||||
| 48 | # The previous implmentation used username and password. | |||||
| 49 | # our $user = C4::Context->config('smsuser'); | |||||
| 50 | # our $pwd = C4::Context->config('smspass'); | |||||
| 51 | ||||||
| 52 - 54 | =head2 send_sms =cut | |||||
| 55 | ||||||
| 56 | sub send_sms { | |||||
| 57 | 0 | my $self = shift; | ||||
| 58 | 0 | my $params= shift; | ||||
| 59 | ||||||
| 60 | 0 | foreach my $required_parameter ( qw( message destination ) ) { | ||||
| 61 | # Should I warn in some way? | |||||
| 62 | 0 | return unless defined $params->{ $required_parameter }; | ||||
| 63 | } | |||||
| 64 | ||||||
| 65 | 0 0 | eval { require SMS::Send; }; | ||||
| 66 | 0 | if ( $@ ) { | ||||
| 67 | # we apparently don't have SMS::Send. Return a failure. | |||||
| 68 | 0 | return; | ||||
| 69 | } | |||||
| 70 | ||||||
| 71 | # This allows the user to override the driver. See SMS::Send::Test | |||||
| 72 | 0 | my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); | ||||
| 73 | 0 | return unless $driver; | ||||
| 74 | ||||||
| 75 | # warn "using driver: $driver to send message to $params->{'destination'}"; | |||||
| 76 | ||||||
| 77 | # Create a sender | |||||
| 78 | 0 | my $sender = SMS::Send->new( $driver, | ||||
| 79 | _login => C4::Context->preference('SMSSendUsername'), | |||||
| 80 | _password => C4::Context->preference('SMSSendPassword'), | |||||
| 81 | ); | |||||
| 82 | ||||||
| 83 | # Send a message | |||||
| 84 | 0 | my $sent = $sender->send_sms( to => $params->{'destination'}, | ||||
| 85 | text => $params->{'message'}, | |||||
| 86 | ); | |||||
| 87 | # warn 'failure' unless $sent; | |||||
| 88 | 0 | return $sent; | ||||
| 89 | } | |||||
| 90 | ||||||
| 91 - 93 | =head2 driver =cut | |||||
| 94 | ||||||
| 95 | sub driver { | |||||
| 96 | 0 | my $self = shift; | ||||
| 97 | ||||||
| 98 | # return 'US::SprintPCS'; | |||||
| 99 | 0 | return C4::Context->preference('SMSSendDriver'); | ||||
| 100 | ||||||
| 101 | } | |||||
| 102 | ||||||
| 103 | 1; | |||||
| 104 | ||||||